Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add strikethrough support #280

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/MudBlazor.Markdown.Core/sample.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
##### Heading 5
###### Heading 6

Some regular text. *Text in italics* and **text in bold**.
Some regular text. *Text in italics*, **text in bold** and ~~text in strikethrough~~.
**Bold and *italics within***.
*Italics and **bold within***.
It is possible to `highlight some code`.
Expand Down
7 changes: 6 additions & 1 deletion src/MudBlazor.Markdown/Extensions/EmphasisInlineEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal static class EmphasisInlineEx
{
public static bool TryGetEmphasisElement(this EmphasisInline emphasis, out string value)
{
const string italics = "i", bold = "b";
const string italics = "i", bold = "b", strikethrough = "del";

value = emphasis.DelimiterChar switch
{
Expand All @@ -17,6 +17,11 @@ public static bool TryGetEmphasisElement(this EmphasisInline emphasis, out strin
_ => string.Empty
},
'_' => italics,
'~' => emphasis.DelimiterCount switch
{
2 => strikethrough,
_ => string.Empty
},
_ => string.Empty
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public void RenderNothingIfNullOrWhitespace(string? value)
}

[Fact]
public void RenderCodeItalicAndBold()
public void RenderEmphasisElements()
{
const string value = "Some text `code` again text - *italics* text and **bold** text.";
const string value = "Some text `code` again text - *italics* text and also **bold** and ~~strikethrough~~ text.";
const string expected =
"""
<article class='mud-markdown-body'>
<p class='mud-typography mud-typography-body1'>
Some text <code>code</code> again text - <i>italics</i> text and <b>bold</b> text.
Some text <code>code</code> again text - <i>italics</i> text and also <b>bold</b> and <del>strikethrough</del> text.
</p>
</article>
""";
Expand All @@ -35,13 +35,13 @@ Some text <code>code</code> again text - <i>italics</i> text and <b>bold</b> tex
[Fact]
public void RenderBlockQuotes()
{
const string value = ">Some text `code` again text - *italics* text and **bold** text.";
const string value = ">Some text `code` again text - *italics* text and also **bold** and ~~strikethrough~~ text.";
const string expected =
"""
<article class='mud-markdown-body'>
<blockquote>
<p class='mud-typography mud-typography-body1'>
Some text <code>code</code> again text - <i>italics</i> text and <b>bold</b> text.
Some text <code>code</code> again text - <i>italics</i> text and also <b>bold</b> and <del>strikethrough</del> text.
</p>
</blockquote>
</article>
Expand Down
Loading