Upstream xoofx/markdig state of the touched files before 27b8c9eb56

This commit is contained in:
upstream committed 2026-09-19 11:52:40 +02:00
1 parent 9006f0b4a2
commit 49e145437f
3 files changed
+93 -81

No files matched your search

+93
View File
@@ -0,0 +1,93 @@
---
title: Emphasis extras
---
# Emphasis extras
Enable with `.UseEmphasisExtras()` (included in `UseAdvancedExtensions()`).
This extension adds several emphasis styles beyond standard bold and italic.
If you need improved emphasis parsing for Chinese/Japanese/Korean (CJK) text, see [CJK friendly emphasis](cjk-friendly-emphasis.md).
## Strikethrough
Wrap text with `~~` for strikethrough:
```markdown
This is ~~deleted~~ text.
```
This is ~~deleted~~ text.
## Subscript
Wrap text with `~` for subscript:
```markdown
H~2~O is water.
```
H~2~O is water.
## Superscript
Wrap text with `^` for superscript:
```markdown
2^10^ is 1024.
```
2^10^ is 1024.
## Inserted text
Wrap text with `++` for inserted/underlined text:
```markdown
This text has been ++inserted++.
```
This text has been ++inserted++.
## Marked/highlighted text
Wrap text with `==` for marked/highlighted text:
```markdown
This is ==highlighted== text.
```
This is ==highlighted== text.
## HTML output
{.table}
| Syntax | HTML output |
|---|---|
| `~~text~~` | `<del>text</del>` |
| `~text~` | `<sub>text</sub>` |
| `^text^` | `<sup>text</sup>` |
| `++text++` | `<ins>text</ins>` |
| `==text==` | `<mark>text</mark>` |
## Selective activation
By default, all emphasis extras are enabled. Use `EmphasisExtraOptions` to enable only specific ones:
```csharp
using Markdig.Extensions.EmphasisExtras;
var pipeline = new MarkdownPipelineBuilder()
.UseEmphasisExtras(EmphasisExtraOptions.Strikethrough | EmphasisExtraOptions.Superscript)
.Build();
```
Available options:
- `EmphasisExtraOptions.Strikethrough`
- `EmphasisExtraOptions.Subscript`
- `EmphasisExtraOptions.Superscript`
- `EmphasisExtraOptions.Inserted`
- `EmphasisExtraOptions.Marked`
- `EmphasisExtraOptions.Default` (all of the above)
@@ -1,68 +0,0 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
using Markdig.Renderers.Roundtrip;
using Markdig.Syntax;
namespace Markdig.Tests;
[TestFixture]
public class TestEmphasisRoundtrip
{
private static string RoundTrip(string markdown, MarkdownPipeline pipeline)
{
MarkdownDocument document = Markdown.Parse(markdown, pipeline);
var writer = new StringWriter();
var renderer = new RoundtripRenderer(writer);
pipeline.Setup(renderer);
renderer.Write(document);
return writer.ToString();
}
// Leftover delimiter characters below the minimum count used to stay nested
// inside the emphasis they closed, moving the following text to the end of
// the block. https://github.com/xoofx/markdig/issues/743
[Test]
public void GridTableSeparatorRoundtripsWithTrackTrivia()
{
string markdown =
"+---------------+---------------+--------------------+\n" +
"| Fruit | Price | Advantages |\n" +
"+===============+===============+====================+\n" +
"| Bananas | first line | first line |\n" +
"| | next line | next line |\n" +
"+---------------+---------------+--------------------+\n";
var pipeline = new MarkdownPipelineBuilder()
.UseAutoLinks()
.UseEmphasisExtras()
.UseListExtras()
.EnableTrackTrivia()
.Build();
Assert.That(RoundTrip(markdown, pipeline), Is.EqualTo(markdown));
}
// Same defect, minimal: leftovers (15 = 7 * 2 + 1) below the "==" minimum.
[Test]
public void UnbalancedMarkedRunsRoundtrip()
{
string markdown = "+===============+===============+\n";
var pipeline = new MarkdownPipelineBuilder()
.UseEmphasisExtras()
.EnableTrackTrivia()
.Build();
Assert.That(RoundTrip(markdown, pipeline), Is.EqualTo(markdown));
}
// The fix must not prevent balanced "marked" emphasis from being detected.
[Test]
public void BalancedMarkedEmphasisStillParses()
{
var pipeline = new MarkdownPipelineBuilder().UseEmphasisExtras().Build();
Assert.That(Markdown.ToHtml("==bold==", pipeline).Trim(), Is.EqualTo("<p><mark>bold</mark></p>"));
}
}
@@ -419,19 +419,6 @@ public class EmphasisInlineParser : InlineParser, IPostInlineProcessor
break;
}
}
// Leftover delimiter characters keep the following inlines nested inside
// the emphasis; move them out so they keep their original position.
if (closeDelimiter.DelimiterCount > 0 && closeDelimiter.Parent is EmphasisInline closerParentEmphasis)
{
var outermostEmphasis = closerParentEmphasis;
while (outermostEmphasis.Parent is EmphasisInline ancestorEmphasis)
{
outermostEmphasis = ancestorEmphasis;
}
closeDelimiter.MoveChildrenAfter(outermostEmphasis);
}
}
}