From d70f14addbcb3ebe3b7f7f37ee5ebd1446c8d688 Mon Sep 17 00:00:00 2001 From: Chris Rodgers Date: Tue, 13 Sep 2016 16:53:25 +0100 Subject: [PATCH] Fixes problem with multiple, similar abbreviations not parsing correctly. --- src/Markdig.Tests/Specs/AbbreviationSpecs.md | 12 ++++++++++ src/Markdig.Tests/Specs/Specs.cs | 24 ++++++++++++++++++++ src/Markdig/Helpers/TextMatcher.cs | 12 +++++----- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Markdig.Tests/Specs/AbbreviationSpecs.md b/src/Markdig.Tests/Specs/AbbreviationSpecs.md index 97189108..e2576dce 100644 --- a/src/Markdig.Tests/Specs/AbbreviationSpecs.md +++ b/src/Markdig.Tests/Specs/AbbreviationSpecs.md @@ -45,3 +45,15 @@ This is a 😃 HTML document .

This is a 😃 HTML document

```````````````````````````````` + +Abbreviations may be similar: + +```````````````````````````````` example +*[1A]: First +*[1A1]: Second +*[1A2]: Third + +We can abbreviate 1A, 1A1 and 1A2! +. +

We can abbreviate 1A, 1A1 and 1A2!

+```````````````````````````````` diff --git a/src/Markdig.Tests/Specs/Specs.cs b/src/Markdig.Tests/Specs/Specs.cs index 6d2c4205..b9e65256 100644 --- a/src/Markdig.Tests/Specs/Specs.cs +++ b/src/Markdig.Tests/Specs/Specs.cs @@ -18226,6 +18226,30 @@ namespace Markdig.Tests Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 4, "Extensions Abbreviation"); TestParser.TestSpec("*[😃 HTML]: Hypertext Markup Language\n\nThis is a 😃 HTML document ", "

This is a 😃 HTML document

", "abbreviations|advanced"); } + } + // Abbreviations may be similar: + [TestFixture] + public partial class TestExtensionsAbbreviation + { + [Test] + public void Example005() + { + // Example 5 + // Section: Extensions Abbreviation + // + // The following CommonMark: + // *[1A]: First + // *[1A1]: Second + // *[1A2]: Third + // + // We can abbreviate 1A, 1A1 and 1A2! + // + // Should be rendered as: + //

We can abbreviate 1A, 1A1 and 1A2!

+ + Console.WriteLine("Example {0}" + Environment.NewLine + "Section: {0}" + Environment.NewLine, 5, "Extensions Abbreviation"); + TestParser.TestSpec("*[1A]: First\n*[1A1]: Second\n*[1A2]: Third\n\nWe can abbreviate 1A, 1A1 and 1A2!", "

We can abbreviate 1A, 1A1 and 1A2!

", "abbreviations|advanced"); + } } // # Extensions // diff --git a/src/Markdig/Helpers/TextMatcher.cs b/src/Markdig/Helpers/TextMatcher.cs index b66cb983..de095df6 100644 --- a/src/Markdig/Helpers/TextMatcher.cs +++ b/src/Markdig/Helpers/TextMatcher.cs @@ -53,17 +53,17 @@ namespace Markdig.Helpers CharNode nextNode; if (!node.TryGetValue(c, out nextNode)) { - return false; + break; } node = nextNode; - if (node.Content != null) - { - match = node.Content; - return true; - } offset++; length--; } + if (node.Content != null) + { + match = node.Content; + return true; + } return false; }