diff --git a/commonmark-ext-autolink/pom.xml b/commonmark-ext-autolink/pom.xml
index af2b99363..297b78306 100644
--- a/commonmark-ext-autolink/pom.xml
+++ b/commonmark-ext-autolink/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-autolink
diff --git a/commonmark-ext-footnotes/pom.xml b/commonmark-ext-footnotes/pom.xml
index 7300078b2..efa0aae5c 100644
--- a/commonmark-ext-footnotes/pom.xml
+++ b/commonmark-ext-footnotes/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-footnotes
diff --git a/commonmark-ext-gfm-alerts/pom.xml b/commonmark-ext-gfm-alerts/pom.xml
index ec7467f85..b65273b4b 100644
--- a/commonmark-ext-gfm-alerts/pom.xml
+++ b/commonmark-ext-gfm-alerts/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-gfm-alerts
diff --git a/commonmark-ext-gfm-strikethrough/pom.xml b/commonmark-ext-gfm-strikethrough/pom.xml
index a3bdf38ee..fef5bc592 100644
--- a/commonmark-ext-gfm-strikethrough/pom.xml
+++ b/commonmark-ext-gfm-strikethrough/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-gfm-strikethrough
diff --git a/commonmark-ext-gfm-tables/pom.xml b/commonmark-ext-gfm-tables/pom.xml
index ea35aaf14..f2f12926b 100644
--- a/commonmark-ext-gfm-tables/pom.xml
+++ b/commonmark-ext-gfm-tables/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-gfm-tables
diff --git a/commonmark-ext-heading-anchor/pom.xml b/commonmark-ext-heading-anchor/pom.xml
index 330356418..e1a6026bd 100644
--- a/commonmark-ext-heading-anchor/pom.xml
+++ b/commonmark-ext-heading-anchor/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-heading-anchor
diff --git a/commonmark-ext-image-attributes/pom.xml b/commonmark-ext-image-attributes/pom.xml
index f48904c57..07ddb1218 100644
--- a/commonmark-ext-image-attributes/pom.xml
+++ b/commonmark-ext-image-attributes/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-image-attributes
diff --git a/commonmark-ext-ins/pom.xml b/commonmark-ext-ins/pom.xml
index b275a4e93..c6a5c4e4d 100644
--- a/commonmark-ext-ins/pom.xml
+++ b/commonmark-ext-ins/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-ins
diff --git a/commonmark-ext-task-list-items/pom.xml b/commonmark-ext-task-list-items/pom.xml
index b8d708a26..1e4125393 100644
--- a/commonmark-ext-task-list-items/pom.xml
+++ b/commonmark-ext-task-list-items/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-task-list-items
diff --git a/commonmark-ext-yaml-front-matter/pom.xml b/commonmark-ext-yaml-front-matter/pom.xml
index d3156892b..0185f55c3 100644
--- a/commonmark-ext-yaml-front-matter/pom.xml
+++ b/commonmark-ext-yaml-front-matter/pom.xml
@@ -4,7 +4,7 @@
commonmark-parent
org.commonmark
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-ext-yaml-front-matter
diff --git a/commonmark-integration-test/pom.xml b/commonmark-integration-test/pom.xml
index d16b7ea05..de27cc2dd 100644
--- a/commonmark-integration-test/pom.xml
+++ b/commonmark-integration-test/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-integration-test
diff --git a/commonmark-test-util/pom.xml b/commonmark-test-util/pom.xml
index 3eb723f4e..8fad7d0cd 100644
--- a/commonmark-test-util/pom.xml
+++ b/commonmark-test-util/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-test-util
diff --git a/commonmark/pom.xml b/commonmark/pom.xml
index 30125aa0b..af0c5cd71 100644
--- a/commonmark/pom.xml
+++ b/commonmark/pom.xml
@@ -4,7 +4,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark
diff --git a/commonmark/src/main/java/org/commonmark/internal/LinkReferenceDefinitionParser.java b/commonmark/src/main/java/org/commonmark/internal/LinkReferenceDefinitionParser.java
index 8725a0612..8a10d212d 100644
--- a/commonmark/src/main/java/org/commonmark/internal/LinkReferenceDefinitionParser.java
+++ b/commonmark/src/main/java/org/commonmark/internal/LinkReferenceDefinitionParser.java
@@ -30,6 +30,7 @@ public class LinkReferenceDefinitionParser {
private String destination;
private char titleDelimiter;
private StringBuilder title;
+ private int titleSourceSpanStart = -1;
private boolean referenceValid = false;
public void parse(SourceLine line) {
@@ -226,6 +227,7 @@ private boolean startTitle(Scanner scanner) {
if (titleDelimiter != '\0') {
state = State.TITLE;
+ titleSourceSpanStart = sourceSpans.size();
title = new StringBuilder();
scanner.next();
if (!scanner.hasNext()) {
@@ -277,17 +279,28 @@ private void finishReference() {
return;
}
+ boolean incompleteTitle = state == State.TITLE;
String d = Escaping.unescapeString(destination);
- String t = title != null ? Escaping.unescapeString(title.toString()) : null;
+ String t =
+ !incompleteTitle && title != null
+ ? Escaping.unescapeString(title.toString())
+ : null;
LinkReferenceDefinition definition = new LinkReferenceDefinition(label.toString(), d, t);
- definition.setSourceSpans(sourceSpans);
- sourceSpans.clear();
+ if (incompleteTitle) {
+ definition.setSourceSpans(
+ new ArrayList<>(sourceSpans.subList(0, titleSourceSpanStart)));
+ sourceSpans.subList(0, titleSourceSpanStart).clear();
+ } else {
+ definition.setSourceSpans(sourceSpans);
+ sourceSpans.clear();
+ }
definitions.add(definition);
label = null;
referenceValid = false;
destination = null;
title = null;
+ titleSourceSpanStart = -1;
}
private static void removeLast(int n, List list) {
diff --git a/commonmark/src/test/java/org/commonmark/internal/LinkReferenceDefinitionParserTest.java b/commonmark/src/test/java/org/commonmark/internal/LinkReferenceDefinitionParserTest.java
index d9ee3a990..a2a781513 100644
--- a/commonmark/src/test/java/org/commonmark/internal/LinkReferenceDefinitionParserTest.java
+++ b/commonmark/src/test/java/org/commonmark/internal/LinkReferenceDefinitionParserTest.java
@@ -4,6 +4,7 @@
import org.commonmark.internal.LinkReferenceDefinitionParser.State;
import org.commonmark.node.LinkReferenceDefinition;
+import org.commonmark.node.SourceSpan;
import org.commonmark.parser.SourceLine;
import org.junit.jupiter.api.Test;
@@ -169,6 +170,25 @@ void testTitleMultiline4() {
assertDef(parser.getDefinitions().get(0), "foo", "/url", null);
}
+ @Test
+ void testUnclosedMultilineTitleKeepsParagraphSourceSpans() {
+ SourceSpan definitionSpan = SourceSpan.of(0, 0, 0, 11);
+ SourceSpan paragraphSpan = SourceSpan.of(1, 0, 12, 14);
+
+ parse("[foo]: /url");
+ parser.addSourceSpan(definitionSpan);
+ parse("(partial title");
+ parser.addSourceSpan(paragraphSpan);
+
+ var definitions = parser.getDefinitions();
+
+ assertThat(definitions).hasSize(1);
+ assertDef(definitions.get(0), "foo", "/url", null);
+ assertThat(definitions.get(0).getSourceSpans()).containsExactly(definitionSpan);
+ assertThat(parser.getParagraphLines().getContent()).isEqualTo("(partial title");
+ assertThat(parser.getParagraphSourceSpans()).containsExactly(paragraphSpan);
+ }
+
@Test
void testTitleInvalid() {
assertParagraph("[foo]: /url (invalid(");
diff --git a/pom.xml b/pom.xml
index 1556a92ae..93947a9d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
org.commonmark
commonmark-parent
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
commonmark-java parent
Java implementation of CommonMark, a specification of the Markdown format for turning plain text into formatted
@@ -146,62 +146,62 @@
org.commonmark
commonmark
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-autolink
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-footnotes
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-image-attributes
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-ins
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-gfm-alerts
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-gfm-strikethrough
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-gfm-tables
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-heading-anchor
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-task-list-items
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-ext-yaml-front-matter
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT
org.commonmark
commonmark-test-util
- 0.30.1-SNAPSHOT
+ 0.30.2-SNAPSHOT