Skip to content

Commit 5d0bb93

Browse files
committed
fix link text vs link ref priority to match commonmark ref impl
1 parent daad074 commit 5d0bb93

File tree

14 files changed

+222
-39
lines changed

14 files changed

+222
-39
lines changed

VERSION-TODO.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Release 0.60.0](#release-0600)
88
- [API Refactoring](#api-refactoring)
99
- [Next 0.61.xx](#next-061xx)
10+
- [0.61.24](#06124)
1011
- [0.61.22](#06122)
1112
- [0.61.20](#06120)
1213
- [0.61.18](#06118)
@@ -207,7 +208,7 @@ Please give feedback on the upcoming changes if you have concerns about breaking
207208
extension add order
208209
* [ ] Fix: Change spec example to variable number of sections
209210
* [ ] Add: yaml front matter configurator for modules. See: [Yaml Front Matter
210-
Configuration](../../wiki/Yaml-Front-Matter-Configuration)
211+
Configuration](../../wiki/Yaml-Front-Matter-Configuration)
211212
* [ ] Fix: table formatting caret position tracking affects alignment even when not inserting,
212213
just formatting. Need to keep track of whether format after typing or just format. Then
213214
caret position should only track but not force spaces behind it to be preserved. See
@@ -223,6 +224,26 @@ Please give feedback on the upcoming changes if you have concerns about breaking
223224
* [ ] Fix: Html converter to not add spaces between end of inline marker and next punctuation:
224225
`.,:;`
225226

227+
## 0.61.24
228+
229+
* Fix: link refs in link text should be collapsed.
230+
* Add: `Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF`, default `false`, commonmark spec does not
231+
specify how to parse:
232+
233+
[[moon]](/uri)
234+
235+
[moon]: moon.jpg
236+
237+
with default implementation priority given to contained ref, renders as:
238+
239+
<p>[<a href="moon.jpg">moon</a>](/uri)</p>
240+
241+
when set to `true`, priority given to outer link and will render as:
242+
243+
<p><a href="/uri">[][moon]</a></p>
244+
245+
:information_source: Undefined reference links are always treated as text when in a link text element.
246+
226247
## 0.61.22
227248

228249
* Fix: [#407, Link text inline content fails to parse image references], link and image refs in
@@ -2446,6 +2467,7 @@ Please give feedback on the upcoming changes if you have concerns about breaking
24462467
[#396, DocumentParser stops reading too early resulting in the document being cut off]: https://github.com/vsch/flexmark-java/issues/396
24472468
[#397, PR: Add base64 image support with docx rendering]: https://github.com/vsch/flexmark-java/pull/397
24482469
[#398, Autolinks get cut off if they contain \`&amp;\` (escaped query params)]: https://github.com/vsch/flexmark-java/issues/398
2470+
[#407, Link text inline content fails to parse image references]: https://github.com/vsch/flexmark-java/issues/407
24492471
[@Xaelis]: https://github.com/Xaelis
24502472
[Awesome Console]: https://plugins.jetbrains.com/plugin/7677-awesome-console "Awesome Console"
24512473
[HtmlToMarkdownCustomizedSample.java]: https://github.com/vsch/flexmark-java/blob/master/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/HtmlToMarkdownCustomizedSample.java
@@ -2458,6 +2480,4 @@ Please give feedback on the upcoming changes if you have concerns about breaking
24582480
[migrate flexmark-java 0_40_x to 0_42_0]: https://github.com/vsch/flexmark-java/blob/master/assets/migrations/migrate%20flexmark-java%200_40_x%20to%200_42_0.xml
24592481
<!-- @IGNORE PREVIOUS: link -->
24602482
[migrate flexmark-java 0_42_x to 0_50_0.xml]: https://github.com/vsch/flexmark-java/blob/master/assets/migrations/migrate%20flexmark-java%200_42_x%20to%200_50_0.xml
2461-
[#407, Link text inline content fails to parse image references]: https://github.com/vsch/flexmark-java/issues/407
2462-
24632483

VERSION.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- [Release 0.60.0](#release-0600)
88
- [API Refactoring](#api-refactoring)
9+
- [0.61.24](#06124)
910
- [0.61.22](#06122)
1011
- [0.61.20](#06120)
1112
- [0.61.18](#06118)
@@ -167,6 +168,26 @@ Please give feedback on the upcoming changes if you have concerns about breaking
167168
* `com.vladsch.flexmark.util.ast.NodeAdaptingVisitHandler`
168169
* `com.vladsch.flexmark.util.ast.NodeAdaptingVisitor`
169170

171+
## 0.61.24
172+
173+
* Fix: link refs in link text should be collapsed.
174+
* Add: `Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF`, default `false`, commonmark spec does not
175+
specify how to parse:
176+
177+
[[moon]](/uri)
178+
179+
[moon]: moon.jpg
180+
181+
with default implementation priority given to contained ref, renders as:
182+
183+
<p>[<a href="moon.jpg">moon</a>](/uri)</p>
184+
185+
when set to `true`, priority given to outer link and will render as:
186+
187+
<p><a href="/uri">[][moon]</a></p>
188+
189+
:information_source: Undefined reference links are always treated as text when in a link text element.
190+
170191
## 0.61.22
171192

172193
* Fix: [#407, Link text inline content fails to parse image references], link and image refs in

flexmark-core-test/flexmark-core-test.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
2424
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
2525
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
26-
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
26+
<sourceFolder url="file://$MODULE_DIR$/target/generated-test-sources/test-annotations" isTestSource="true" generated="true" />
2727
<excludeFolder url="file://$MODULE_DIR$/target" />
2828
</content>
2929
<orderEntry type="inheritedJdk" />
@@ -50,4 +50,4 @@
5050
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.2" level="project" />
5151
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
5252
</component>
53-
</module>
53+
</module>

flexmark-core-test/src/test/java/com/vladsch/flexmark/core/test/util/renderer/ComboIssuesSpecTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final public class ComboIssuesSpecTest extends CoreRendererSpecTest {
3434
optionsMap.put("allow-javascript", new MutableDataSet().set(HtmlRenderer.SUPPRESSED_LINKS, ""));
3535
optionsMap.put("pass-through", new MutableDataSet().set(HtmlRenderer.FORMAT_FLAGS, LineAppendable.F_PASS_THROUGH));
3636
optionsMap.put("strip-indent", new MutableDataSet().set(TestUtils.SOURCE_INDENT, "> > "));
37+
optionsMap.put("link-over-linkref", new MutableDataSet().set(Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF, true));
3738
optionsMap.put("no-html-blocks", new MutableDataSet().set(Parser.HTML_BLOCK_PARSER, false));
3839
optionsMap.put("sub-parse", new MutableDataSet()
3940
.set(TestUtils.SOURCE_PREFIX, "" +

flexmark-core-test/src/test/resources/core_issues_ast_spec.md

Lines changed: 129 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ Document[0, 474]
13271327

13281328
Issue #487
13291329

1330-
Wrong syntax
1330+
Image refs
13311331

13321332
```````````````````````````````` example Core Issues Tests - 407: 1
13331333
[![][moon]](/uri)
@@ -1376,18 +1376,140 @@ Document[0, 35]
13761376
````````````````````````````````
13771377

13781378

1379+
Link refs should be treated as text
1380+
13791381
```````````````````````````````` example Core Issues Tests - 407: 4
1380-
![moon]
1382+
[[][moon]](/uri)
13811383

13821384
[moon]: moon.jpg
13831385
.
1384-
<p><img src="moon.jpg" alt="moon" /></p>
1386+
<p>[<a href="moon.jpg"></a>](/uri)</p>
13851387
.
1386-
Document[0, 25]
1387-
Paragraph[0, 8] isTrailingBlankLine
1388-
ImageRef[0, 7] referenceOpen:[0, 2, "!["] reference:[2, 6, "moon"] referenceClose:[6, 7, "]"]
1388+
Document[0, 34]
1389+
Paragraph[0, 17] isTrailingBlankLine
1390+
Text[0, 1] chars:[0, 1, "["]
1391+
LinkRef[1, 9] textOpen:[1, 2, "["] text:[2, 2] textClose:[2, 3, "]"] referenceOpen:[3, 4, "["] reference:[4, 8, "moon"] referenceClose:[8, 9, "]"]
1392+
Text[9, 16] chars:[9, 16, "](/uri)"]
1393+
Reference[18, 34] refOpen:[18, 19, "["] ref:[19, 23, "moon"] refClose:[23, 25, "]:"] url:[26, 34, "moon.jpg"]
1394+
````````````````````````````````
1395+
1396+
1397+
```````````````````````````````` example Core Issues Tests - 407: 5
1398+
[[moon]](/uri)
1399+
1400+
[moon]: moon.jpg
1401+
.
1402+
<p>[<a href="moon.jpg">moon</a>](/uri)</p>
1403+
.
1404+
Document[0, 32]
1405+
Paragraph[0, 15] isTrailingBlankLine
1406+
Text[0, 1] chars:[0, 1, "["]
1407+
LinkRef[1, 7] referenceOpen:[1, 2, "["] reference:[2, 6, "moon"] referenceClose:[6, 7, "]"]
13891408
Text[2, 6] chars:[2, 6, "moon"]
1390-
Reference[9, 25] refOpen:[9, 10, "["] ref:[10, 14, "moon"] refClose:[14, 16, "]:"] url:[17, 25, "moon.jpg"]
1409+
Text[7, 14] chars:[7, 14, "](/uri)"]
1410+
Reference[16, 32] refOpen:[16, 17, "["] ref:[17, 21, "moon"] refClose:[21, 23, "]:"] url:[24, 32, "moon.jpg"]
1411+
````````````````````````````````
1412+
1413+
1414+
```````````````````````````````` example Core Issues Tests - 407: 6
1415+
[[moon][]](/uri)
1416+
1417+
[moon]: moon.jpg
1418+
.
1419+
<p>[<a href="moon.jpg">moon</a>](/uri)</p>
1420+
.
1421+
Document[0, 34]
1422+
Paragraph[0, 17] isTrailingBlankLine
1423+
Text[0, 1] chars:[0, 1, "["]
1424+
LinkRef[1, 9] referenceOpen:[1, 2, "["] reference:[2, 6, "moon"] referenceClose:[6, 7, "]"] textOpen:[7, 8, "["] textClose:[8, 9, "]"]
1425+
Text[2, 6] chars:[2, 6, "moon"]
1426+
Text[9, 16] chars:[9, 16, "](/uri)"]
1427+
Reference[18, 34] refOpen:[18, 19, "["] ref:[19, 23, "moon"] refClose:[23, 25, "]:"] url:[26, 34, "moon.jpg"]
1428+
````````````````````````````````
1429+
1430+
1431+
undefined should render the same as if link text has priority
1432+
1433+
```````````````````````````````` example Core Issues Tests - 407: 7
1434+
[[][moon]](/uri)
1435+
.
1436+
<p><a href="/uri">[][moon]</a></p>
1437+
.
1438+
Document[0, 16]
1439+
Paragraph[0, 16]
1440+
Link[0, 16] textOpen:[0, 1, "["] text:[1, 9, "[][moon]"] textClose:[9, 10, "]"] linkOpen:[10, 11, "("] url:[11, 15, "/uri"] pageRef:[11, 15, "/uri"] linkClose:[15, 16, ")"]
1441+
Text[1, 9] chars:[1, 9, "[][moon]"]
1442+
````````````````````````````````
1443+
1444+
1445+
```````````````````````````````` example Core Issues Tests - 407: 8
1446+
[[moon]](/uri)
1447+
.
1448+
<p><a href="/uri">[moon]</a></p>
1449+
.
1450+
Document[0, 14]
1451+
Paragraph[0, 14]
1452+
Link[0, 14] textOpen:[0, 1, "["] text:[1, 7, "[moon]"] textClose:[7, 8, "]"] linkOpen:[8, 9, "("] url:[9, 13, "/uri"] pageRef:[9, 13, "/uri"] linkClose:[13, 14, ")"]
1453+
Text[1, 7] chars:[1, 7, "[moon]"]
1454+
````````````````````````````````
1455+
1456+
1457+
```````````````````````````````` example Core Issues Tests - 407: 9
1458+
[[moon][]](/uri)
1459+
.
1460+
<p><a href="/uri">[moon][]</a></p>
1461+
.
1462+
Document[0, 16]
1463+
Paragraph[0, 16]
1464+
Link[0, 16] textOpen:[0, 1, "["] text:[1, 9, "[moon][]"] textClose:[9, 10, "]"] linkOpen:[10, 11, "("] url:[11, 15, "/uri"] pageRef:[11, 15, "/uri"] linkClose:[15, 16, ")"]
1465+
Text[1, 9] chars:[1, 9, "[moon][]"]
1466+
````````````````````````````````
1467+
1468+
1469+
Link refs should be treated as text
1470+
1471+
```````````````````````````````` example(Core Issues Tests - 407: 10) options(link-over-linkref)
1472+
[[][moon]](/uri)
1473+
1474+
[moon]: moon.jpg
1475+
.
1476+
<p><a href="/uri">[][moon]</a></p>
1477+
.
1478+
Document[0, 34]
1479+
Paragraph[0, 17] isTrailingBlankLine
1480+
Link[0, 16] textOpen:[0, 1, "["] text:[1, 9, "[][moon]"] textClose:[9, 10, "]"] linkOpen:[10, 11, "("] url:[11, 15, "/uri"] pageRef:[11, 15, "/uri"] linkClose:[15, 16, ")"]
1481+
Text[1, 9] chars:[1, 9, "[][moon]"]
1482+
Reference[18, 34] refOpen:[18, 19, "["] ref:[19, 23, "moon"] refClose:[23, 25, "]:"] url:[26, 34, "moon.jpg"]
1483+
````````````````````````````````
1484+
1485+
1486+
```````````````````````````````` example(Core Issues Tests - 407: 11) options(link-over-linkref)
1487+
[[moon]](/uri)
1488+
1489+
[moon]: moon.jpg
1490+
.
1491+
<p><a href="/uri">[moon]</a></p>
1492+
.
1493+
Document[0, 32]
1494+
Paragraph[0, 15] isTrailingBlankLine
1495+
Link[0, 14] textOpen:[0, 1, "["] text:[1, 7, "[moon]"] textClose:[7, 8, "]"] linkOpen:[8, 9, "("] url:[9, 13, "/uri"] pageRef:[9, 13, "/uri"] linkClose:[13, 14, ")"]
1496+
Text[1, 7] chars:[1, 7, "[moon]"]
1497+
Reference[16, 32] refOpen:[16, 17, "["] ref:[17, 21, "moon"] refClose:[21, 23, "]:"] url:[24, 32, "moon.jpg"]
1498+
````````````````````````````````
1499+
1500+
1501+
```````````````````````````````` example(Core Issues Tests - 407: 12) options(link-over-linkref)
1502+
[[moon][]](/uri)
1503+
1504+
[moon]: moon.jpg
1505+
.
1506+
<p><a href="/uri">[moon][]</a></p>
1507+
.
1508+
Document[0, 34]
1509+
Paragraph[0, 17] isTrailingBlankLine
1510+
Link[0, 16] textOpen:[0, 1, "["] text:[1, 9, "[moon][]"] textClose:[9, 10, "]"] linkOpen:[10, 11, "("] url:[11, 15, "/uri"] pageRef:[11, 15, "/uri"] linkClose:[15, 16, ")"]
1511+
Text[1, 9] chars:[1, 9, "[moon][]"]
1512+
Reference[18, 34] refOpen:[18, 19, "["] ref:[19, 23, "moon"] refClose:[23, 25, "]:"] url:[26, 34, "moon.jpg"]
13911513
````````````````````````````````
13921514

13931515

flexmark-ext-gitlab/flexmark-ext-gitlab.iml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
2020
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
2121
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
22+
<excludeFolder url="file://$MODULE_DIR$/target" />
2223
</content>
2324
<orderEntry type="inheritedJdk" />
2425
<orderEntry type="sourceFolder" forTests="false" />
@@ -39,4 +40,4 @@
3940
<orderEntry type="module" module-name="flexmark-core-test" scope="TEST" />
4041
<orderEntry type="library" name="org.jetbrains:annotations" level="project" />
4142
</component>
42-
</module>
43+
</module>

flexmark-ext-macros/flexmark-ext-macros.iml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
2222
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
2323
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
24+
<excludeFolder url="file://$MODULE_DIR$/target" />
2425
</content>
2526
<orderEntry type="inheritedJdk" />
2627
<orderEntry type="sourceFolder" forTests="false" />
@@ -43,4 +44,4 @@
4344
<orderEntry type="module" module-name="flexmark-ext-tables" scope="TEST" />
4445
<orderEntry type="library" name="org.jetbrains:annotations" level="project" />
4546
</component>
46-
</module>
47+
</module>

flexmark-integration-test/flexmark-integration-test.iml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
<sourceFolder url="file://$MODULE_DIR$/target/generated-test-sources/test-annotations" isTestSource="true" generated="true" />
88
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
99
<excludeFolder url="file://$MODULE_DIR$/target" />
10-
<excludeFolder url="file://$MODULE_DIR$/target/javadoc-bundle-options" />
11-
<excludeFolder url="file://$MODULE_DIR$/target/maven-archiver" />
12-
<excludeFolder url="file://$MODULE_DIR$/target/maven-status" />
13-
<excludeFolder url="file://$MODULE_DIR$/target/surefire-reports" />
1410
</content>
1511
<orderEntry type="inheritedJdk" />
1612
<orderEntry type="sourceFolder" forTests="false" />
@@ -55,4 +51,4 @@
5551
<orderEntry type="module" module-name="flexmark-core-test" scope="TEST" />
5652
<orderEntry type="module" module-name="flexmark-test-specs" scope="TEST" />
5753
</component>
58-
</module>
54+
</module>

flexmark-pdf-converter/src/main/java/com/vladsch/flexmark/pdf/converter/PdfConverterExtension.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424
* Extension for converting Markdown to PDF
2525
* <p>
2626
* After document is rendered pass the HTML result to
27-
* {@link #exportToPdf(OutputStream, String, String, DataHolder)}
28-
* or {@link #exportToPdf(String, String, String, DataHolder)}
29-
* or {@link #exportToPdf(String, String, String, PdfRendererBuilder.TextDirection)}
30-
* or {@link #exportToPdf(String, String, String, PdfRendererBuilder.TextDirection, ProtectionPolicy protectionPolicy)}
31-
* or {@link #exportToPdf(OutputStream, String, String, PdfRendererBuilder.TextDirection)}
32-
* or {@link #exportToPdf(OutputStream, String, String, PdfRendererBuilder.TextDirection, ProtectionPolicy protectionPolicy)}
27+
* {@link PdfConverterExtension#exportToPdf(OutputStream, String, String, DataHolder)}
28+
* or {@link PdfConverterExtension#exportToPdf(String, String, String, DataHolder)}
29+
* or {@link PdfConverterExtension#exportToPdf(String, String, String, PdfRendererBuilder.TextDirection)}
30+
* or {@link PdfConverterExtension#exportToPdf(String, String, String, PdfRendererBuilder.TextDirection, ProtectionPolicy protectionPolicy)}
31+
* or {@link PdfConverterExtension#exportToPdf(OutputStream, String, String, PdfRendererBuilder.TextDirection)}
32+
* or {@link PdfConverterExtension#exportToPdf(OutputStream, String, String, PdfRendererBuilder.TextDirection, ProtectionPolicy protectionPolicy)}
3333
* <p>
3434
* The parsed Markdown text is rendered to HTML then converted to PDF
3535
* </p>

flexmark-tree-iteration/flexmark-tree-iteration.iml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
2424
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
2525
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
26+
<excludeFolder url="file://$MODULE_DIR$/target" />
2627
</content>
2728
<orderEntry type="inheritedJdk" />
2829
<orderEntry type="sourceFolder" forTests="false" />
@@ -35,4 +36,4 @@
3536
<orderEntry type="library" name="org.jetbrains:annotations" level="project" />
3637
<orderEntry type="library" name="slf4j-api-1.7.26" level="project" />
3738
</component>
38-
</module>
39+
</module>

0 commit comments

Comments
 (0)