Open limingchina opened 1 year ago
This diff seem to be working. However, I feel it might not be the correct fix. The problem is that the function isStraddling tries to find out a delimiter inside the brackets. However, it's unclear to me why if the delimiter is not matching, the LinkRef detection would be skipped later. It's actually quite possible that the link section contains some underscores.
diff --git a/flexmark/src/main/java/com/vladsch/flexmark/parser/core/delimiter/Bracket.java b/flexmark/src/main/java/com/vladsch/flexmark/parser/core/delimiter/Bracket.java
index 89e5050c4..e172d8cb6 100644
--- a/flexmark/src/main/java/com/vladsch/flexmark/parser/core/delimiter/Bracket.java
+++ b/flexmark/src/main/java/com/vladsch/flexmark/parser/core/delimiter/Bracket.java
@@ -92,7 +92,15 @@ public class Bracket {
// first see if we have any closers in our span
int startOffset = nodeChars.getStartOffset();
int endOffset = nodeChars.getEndOffset();
- Delimiter inner = previousDelimiter == null ? null : previousDelimiter.getNext();
+
+ Delimiter inner = null;
+ if (previousDelimiter != null) {
+ inner = previousDelimiter.getNext();
+ if (inner != null && inner.getDelimiterChar() != previousDelimiter.getDelimiterChar()) {
+ // If the delimiter chars are not matching then we are not straddling
+ inner = null;
+ }
+ }
while (inner != null) {
int innerOffset = inner.getEndIndex();
if (innerOffset >= endOffset) break;
Parser
To Reproduce Create a java project adding flexmark dependency and run the following code.
Resulting Output :
Additional context The bug was initially reported in the heremaps/gluecodium project: https://github.com/heremaps/gluecodium/issues/1542. After debugging, it's found that the issue is actually in the flexmark library.