Skip to content
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
3 changes: 3 additions & 0 deletions src/Markdig.Tests/TestEmphasisExtended.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ class CustomEmphasisInline : EmphasisInline { }
[TestCase("1Foo1", "<one-only>Foo</one-only>")]
[TestCase("1121", "1<one-only>2</one-only>")]
[TestCase("22322", "<two-only>3</two-only>")]
[TestCase("2223222", "2<two-only>32</two-only>")]
[TestCase("22223222", "22<two-only>32</two-only>")]
[TestCase("22223223222", "22223<two-only>3</two-only>2")]
[TestCase("2232", "2232")]
[TestCase("333", "333")]
[TestCase("3334333", "<three-only>4</three-only>")]
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Helpers/UnicodeUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static bool IsValidUnicodeScalar(uint value)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void GetUtf16SurrogatesFromSupplementaryPlaneScalar(uint value, out char highSurrogateCodePoint, out char lowSurrogateCodePoint)
{
Debug.Assert(IsValidUnicodeScalar(value) && IsBmpCodePoint(value));
Debug.Assert(IsValidUnicodeScalar(value) && !IsBmpCodePoint(value));

highSurrogateCodePoint = (char)((value + ((0xD800u - 0x40u) << 10)) >> 10);
lowSurrogateCodePoint = (char)((value & 0x3FFu) + 0xDC00u);
Expand Down
2 changes: 2 additions & 0 deletions src/Markdig/Parsers/Inlines/EmphasisDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
// See the license.txt file in the project root for more information.

using Markdig.Helpers;
using System.Diagnostics;

namespace Markdig.Parsers.Inlines;

/// <summary>
/// Descriptor for an emphasis.
/// </summary>
[DebuggerDisplay("Emphasis Char={Character}, Min={MinimumCount}, Max={MaximumCount}, EnableWithinWord={EnableWithinWord}")]
public sealed class EmphasisDescriptor
{
/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/Markdig/Parsers/Inlines/EmphasisInlineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ private void ProcessEmphasis(InlineProcessor processor, List<EmphasisDelimiterIn
continue;
}

if ((closeDelimiter.Type & DelimiterType.Close) != 0 && closeDelimiter.DelimiterCount >= emphasisDesc.MinimumCount)
if ((closeDelimiter.Type & DelimiterType.Close) != 0)
{
while (true)
while (closeDelimiter.DelimiterCount >= emphasisDesc.MinimumCount)
{
// Now, look back in the stack (staying above stack_bottom and the openers_bottom for this delimiter type)
// for the first matching potential opener (“matching” means same delimiter).
Expand All @@ -245,8 +245,7 @@ private void ProcessEmphasis(InlineProcessor processor, List<EmphasisDelimiterIn
{
var previousOpenDelimiter = delimiters[j];

var isOddMatch = ((closeDelimiter.Type & DelimiterType.Open) != 0 ||
(previousOpenDelimiter.Type & DelimiterType.Close) != 0) &&
var isOddMatch = ((closeDelimiter.Type & DelimiterType.Open) != 0 || (previousOpenDelimiter.Type & DelimiterType.Close) != 0) &&
previousOpenDelimiter.DelimiterCount != closeDelimiter.DelimiterCount &&
(previousOpenDelimiter.DelimiterCount + closeDelimiter.DelimiterCount) % 3 == 0 &&
(previousOpenDelimiter.DelimiterCount % 3 != 0 || closeDelimiter.DelimiterCount % 3 != 0);
Expand Down Expand Up @@ -357,7 +356,8 @@ private void ProcessEmphasis(InlineProcessor processor, List<EmphasisDelimiterIn
}

// The current delimiters are matching
if (openDelimiter.DelimiterCount >= emphasisDesc.MinimumCount)
if (openDelimiter.DelimiterCount >= emphasisDesc.MinimumCount &&
closeDelimiter.DelimiterCount >= emphasisDesc.MinimumCount)
{
goto process_delims;
}
Expand Down