Adds exceptions to allow certain punctuation characters to behave as inline delimiters

This commit is contained in:
Chris Rodgers
2016-09-14 12:00:31 +01:00
parent 1c187f2d81
commit e7df7fabeb
3 changed files with 47 additions and 8 deletions

View File

@@ -21,6 +21,17 @@ H~2~O is a liquid. 2^10^ is 1024
.
<p>H<sub>2</sub>O is a liquid. 2<sup>10</sup> is 1024</p>
````````````````````````````````
Certain punctuation characters are exempted from the rule forbidding them within inline delimiters
```````````````````````````````` example
One quintillionth can be expressed as 10^-18^
Daggers^†^ and double-daggers^‡^ can be used to denote notes.
.
<p>One quintillionth can be expressed as 10<sup>-18</sup></p>
<p>Daggers<sup>†</sup> and double-daggers<sup>‡</sup> can be used to denote notes.</p>
````````````````````````````````
## Inserted

View File

@@ -17357,6 +17357,29 @@ namespace Markdig.Tests
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 2, "Extensions Superscript and Subscript");
TestParser.TestSpec("H~2~O is a liquid. 2^10^ is 1024", "<p>H<sub>2</sub>O is a liquid. 2<sup>10</sup> is 1024</p>", "emphasisextras|advanced");
}
}
// Certain punctuation characters are exempted from the rule forbidding them within inline delimiters
[TestFixture]
public partial class TestExtensionsSuperscriptandSubscript
{
[Test]
public void Example003()
{
// Example 3
// Section: Extensions Superscript and Subscript
//
// The following CommonMark:
// One quintillionth can be expressed as 10^-18^
//
// Daggers^†^ and double-daggers^‡^ can be used to denote notes.
//
// Should be rendered as:
// <p>One quintillionth can be expressed as 10<sup>-18</sup></p>
// <p>Daggers<sup>†</sup> and double-daggers<sup>‡</sup> can be used to denote notes.</p>
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 3, "Extensions Superscript and Subscript");
TestParser.TestSpec("One quintillionth can be expressed as 10^-18^\n\nDaggers^†^ and double-daggers^‡^ can be used to denote notes.", "<p>One quintillionth can be expressed as 10<sup>-18</sup></p>\n<p>Daggers<sup>†</sup> and double-daggers<sup>‡</sup> can be used to denote notes.</p>", "emphasisextras|advanced");
}
}
// ## Inserted
//
@@ -17365,9 +17388,9 @@ namespace Markdig.Tests
public partial class TestExtensionsInserted
{
[Test]
public void Example003()
public void Example004()
{
// Example 3
// Example 4
// Section: Extensions Inserted
//
// The following CommonMark:
@@ -17376,7 +17399,7 @@ namespace Markdig.Tests
// Should be rendered as:
// <p><ins>Inserted text</ins></p>
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 3, "Extensions Inserted");
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 4, "Extensions Inserted");
TestParser.TestSpec("++Inserted text++", "<p><ins>Inserted text</ins></p>", "emphasisextras|advanced");
}
}
@@ -17387,9 +17410,9 @@ namespace Markdig.Tests
public partial class TestExtensionsMarked
{
[Test]
public void Example004()
public void Example005()
{
// Example 4
// Example 5
// Section: Extensions Marked
//
// The following CommonMark:
@@ -17398,7 +17421,7 @@ namespace Markdig.Tests
// Should be rendered as:
// <p><mark>Marked text</mark></p>
Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 4, "Extensions Marked");
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");
}
}

View File

@@ -23,6 +23,8 @@ namespace Markdig.Helpers
// We don't support LCDM
private static IDictionary<char, int> romanMap = new Dictionary<char, int> { { 'I', 1 }, { 'V', 5 }, { 'X', 10 } };
private static readonly char[] punctuationExceptions = { '−', '-', '†', '‡' };
public static void CheckOpenCloseDelimiter(char pc, char c, bool enableWithinWord, out bool canOpen, out bool canClose)
{
// A left-flanking delimiter run is a delimiter run that is
@@ -37,8 +39,11 @@ namespace Markdig.Helpers
pc.CheckUnicodeCategory(out prevIsWhiteSpace, out prevIsPunctuation);
c.CheckUnicodeCategory(out nextIsWhiteSpace, out nextIsPunctuation);
var prevIsExcepted = prevIsPunctuation && punctuationExceptions.Contains(pc);
var nextIsExcepted = nextIsPunctuation && punctuationExceptions.Contains(c);
canOpen = !nextIsWhiteSpace &&
(!nextIsPunctuation || prevIsWhiteSpace || prevIsPunctuation);
((!nextIsPunctuation || nextIsExcepted) || prevIsWhiteSpace || prevIsPunctuation);
// A right-flanking delimiter run is a delimiter run that is
@@ -47,7 +52,7 @@ namespace Markdig.Helpers
// or a punctuation character.
// For purposes of this definition, the beginning and the end of the line count as Unicode whitespace.
canClose = !prevIsWhiteSpace &&
(!prevIsPunctuation || nextIsWhiteSpace || nextIsPunctuation);
((!prevIsPunctuation || prevIsExcepted) || nextIsWhiteSpace || nextIsPunctuation);
if (!enableWithinWord)
{