diff --git a/src/Markdig.Tests/Specs/EmphasisExtraSpecs.md b/src/Markdig.Tests/Specs/EmphasisExtraSpecs.md index e1dada02b..50f6e14eb 100644 --- a/src/Markdig.Tests/Specs/EmphasisExtraSpecs.md +++ b/src/Markdig.Tests/Specs/EmphasisExtraSpecs.md @@ -52,3 +52,16 @@ Marked text can be used to specify that a text has been marked in a document. T .

Marked text

```````````````````````````````` +## Emphasis on Html Entities + + +```````````````````````````````` example +This is text MyBrand ^®^ and MyTrademark ^™^ +This is text MyBrand^®^ and MyTrademark^™^ +This is text MyBrand~®~ and MyCopyright^©^ +. +

This is text MyBrand ® and MyTrademark TM +This is text MyBrand® and MyTrademarkTM +This is text MyBrand® and MyCopyright©

+```````````````````````````````` + diff --git a/src/Markdig.Tests/Specs/Specs.cs b/src/Markdig.Tests/Specs/Specs.cs index 2377721f4..250bac53c 100644 --- a/src/Markdig.Tests/Specs/Specs.cs +++ b/src/Markdig.Tests/Specs/Specs.cs @@ -17616,6 +17616,30 @@ public void Example005() Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 5, "Extensions Marked"); TestParser.TestSpec("==Marked text==", "

Marked text

", "emphasisextras|advanced"); } + } + // ## Emphasis on Html Entities + [TestFixture] + public partial class TestExtensionsEmphasisonHtmlEntities + { + [Test] + public void Example006() + { + // Example 6 + // Section: Extensions Emphasis on Html Entities + // + // The following CommonMark: + // This is text MyBrand ^®^ and MyTrademark ^™^ + // This is text MyBrand^®^ and MyTrademark^™^ + // This is text MyBrand~®~ and MyCopyright^©^ + // + // Should be rendered as: + //

This is text MyBrand ® and MyTrademark TM + // This is text MyBrand® and MyTrademarkTM + // This is text MyBrand® and MyCopyright©

+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 6, "Extensions Emphasis on Html Entities"); + TestParser.TestSpec("This is text MyBrand ^®^ and MyTrademark ^™^\nThis is text MyBrand^®^ and MyTrademark^™^\nThis is text MyBrand~®~ and MyCopyright^©^", "

This is text MyBrand ® and MyTrademark TM\nThis is text MyBrand® and MyTrademarkTM\nThis is text MyBrand® and MyCopyright©

", "emphasisextras|advanced"); + } } // # Extensions // diff --git a/src/Markdig/Helpers/CharHelper.cs b/src/Markdig/Helpers/CharHelper.cs index b6cb38c0f..9217bd2e1 100644 --- a/src/Markdig/Helpers/CharHelper.cs +++ b/src/Markdig/Helpers/CharHelper.cs @@ -162,6 +162,9 @@ public static bool IsWhiteSpaceOrZero(this char c) return IsWhitespace(c) || IsZero(c); } + // Note that we are not considering the character & as a punctuation in HTML + // as it is used for HTML entities, print unicode, so we assume that when we have a `&` + // it is more likely followed by a valid HTML Entity that represents a non punctuation public static void CheckUnicodeCategory(this char c, out bool space, out bool punctuation) { // Credits: code from CommonMark.NET @@ -170,7 +173,7 @@ public static void CheckUnicodeCategory(this char c, out bool space, out bool pu if (c <= 'ÿ') { space = c == '\0' || c == ' ' || (c >= '\t' && c <= '\r') || c == '\u00a0' || c == '\u0085'; - punctuation = c == '\0' || (c >= 33 && c <= 47) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126); + punctuation = c == '\0' || (c >= 33 && c <= 47 && c != 38) || (c >= 58 && c <= 64) || (c >= 91 && c <= 96) || (c >= 123 && c <= 126); } else {