Skip to content

Commit

Permalink
Fix emphasis with HTML entities (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Feb 24, 2017
1 parent a926e1a commit b47ae8d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Markdig.Tests/Specs/EmphasisExtraSpecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ Marked text can be used to specify that a text has been marked in a document. T
.
<p><mark>Marked text</mark></p>
````````````````````````````````
## Emphasis on Html Entities


```````````````````````````````` example
This is text MyBrand ^&reg;^ and MyTrademark ^&trade;^
This is text MyBrand^&reg;^ and MyTrademark^&trade;^
This is text MyBrand~&reg;~ and MyCopyright^&copy;^
.
<p>This is text MyBrand <sup>®</sup> and MyTrademark <sup>TM</sup>
This is text MyBrand<sup>®</sup> and MyTrademark<sup>TM</sup>
This is text MyBrand<sub>®</sub> and MyCopyright<sup>©</sup></p>
````````````````````````````````

24 changes: 24 additions & 0 deletions src/Markdig.Tests/Specs/Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17616,6 +17616,30 @@ public void Example005()
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 5, "Extensions Marked");
TestParser.TestSpec("==Marked text==", "<p><mark>Marked text</mark></p>", "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 ^&reg;^ and MyTrademark ^&trade;^
// This is text MyBrand^&reg;^ and MyTrademark^&trade;^
// This is text MyBrand~&reg;~ and MyCopyright^&copy;^
//
// Should be rendered as:
// <p>This is text MyBrand <sup>®</sup> and MyTrademark <sup>TM</sup>
// This is text MyBrand<sup>®</sup> and MyTrademark<sup>TM</sup>
// This is text MyBrand<sub>®</sub> and MyCopyright<sup>©</sup></p>

Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 6, "Extensions Emphasis on Html Entities");
TestParser.TestSpec("This is text MyBrand ^&reg;^ and MyTrademark ^&trade;^\nThis is text MyBrand^&reg;^ and MyTrademark^&trade;^\nThis is text MyBrand~&reg;~ and MyCopyright^&copy;^", "<p>This is text MyBrand <sup>®</sup> and MyTrademark <sup>TM</sup>\nThis is text MyBrand<sup>®</sup> and MyTrademark<sup>TM</sup>\nThis is text MyBrand<sub>®</sub> and MyCopyright<sup>©</sup></p>", "emphasisextras|advanced");
}
}
// # Extensions
//
Expand Down
5 changes: 4 additions & 1 deletion src/Markdig/Helpers/CharHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand Down

0 comments on commit b47ae8d

Please sign in to comment.