Skip to content

Commit eee271d

Browse files
committed
unify link ref derived link rendering elements in link text
1 parent cb24403 commit eee271d

File tree

13 files changed

+398
-46
lines changed

13 files changed

+398
-46
lines changed

Diff for: .idea/codeStyles/Project.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: VERSION-TODO.md

+9
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ Please give feedback on the upcoming changes if you have concerns about breaking
234234
taking options flags.
235235
* Fix: `MarkdownParagraph` wrapping with preserving tracked offsets with spaces to preserve
236236
spaces right before last non-blank character.
237+
* Fix: unify handling of link generating inline element handling in link text elements.
238+
* Add: `LinkRendered` interface to identify link rendering elements derived from link/image
239+
ref syntax identified by implementation of `LinkRefDerived` interface
240+
* Fix: `WikiNode` to implement `LinkRefDerived`
241+
* Fix: `WikiLink` to implement `LinkRendered`
242+
* Fix: `Footnote` to implement `LinkRendered`
243+
244+
:information_source: nested link ref derived elements in link ref text have priority and
245+
cannot be used to embed into link ref text using `[link ref text][ref id]` syntax.
237246

238247
## 0.61.24
239248

Diff for: flexmark-ext-footnotes/src/main/java/com/vladsch/flexmark/ext/footnotes/Footnote.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.vladsch.flexmark.ext.footnotes;
22

3+
import com.vladsch.flexmark.ast.LinkRendered;
34
import com.vladsch.flexmark.ext.footnotes.internal.FootnoteRepository;
45
import com.vladsch.flexmark.util.ast.*;
56
import com.vladsch.flexmark.util.sequence.BasedSequence;
@@ -8,7 +9,7 @@
89
/**
910
* A Footnote referencing node
1011
*/
11-
public class Footnote extends Node implements DelimitedNode, DoNotDecorate, ReferencingNode<FootnoteRepository, FootnoteBlock> {
12+
public class Footnote extends Node implements DelimitedNode, DoNotDecorate, LinkRendered, ReferencingNode<FootnoteRepository, FootnoteBlock> {
1213
protected BasedSequence openingMarker = BasedSequence.NULL;
1314
protected BasedSequence text = BasedSequence.NULL;
1415
protected BasedSequence closingMarker = BasedSequence.NULL;
@@ -48,6 +49,14 @@ public boolean isDefined() {
4849
return footnoteBlock != null;
4950
}
5051

52+
/**
53+
* @return true if this node will be rendered as text because it depends on a reference which is not defined.
54+
*/
55+
@Override
56+
public boolean isTentative() {
57+
return footnoteBlock == null;
58+
}
59+
5160
public FootnoteBlock getFootnoteBlock(FootnoteRepository footnoteRepository) {
5261
return text.isEmpty() ? null : footnoteRepository.get(text.toString());
5362
}

Diff for: flexmark-ext-footnotes/src/test/java/com/vladsch/flexmark/ext/footnotes/ComboFootnotesSpecTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class ComboFootnotesSpecTest extends RendererSpecTest {
3131
optionsMap.put("back-link-class-none", new MutableDataSet().set(FootnoteExtension.FOOTNOTE_BACK_LINK_REF_CLASS, ""));
3232
optionsMap.put("back-link-class-text", new MutableDataSet().set(FootnoteExtension.FOOTNOTE_BACK_LINK_REF_CLASS, "text"));
3333
optionsMap.put("item-indent-8", new MutableDataSet().set(Parser.LISTS_ITEM_INDENT, 8));
34+
optionsMap.put("link-text-priority", new MutableDataSet().set(Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF, true));
3435
}
3536
public ComboFootnotesSpecTest(@NotNull SpecExample example) {
3637
super(example, optionsMap, OPTIONS);

Diff for: flexmark-ext-footnotes/src/test/resources/ext_footnotes_ast_spec.md

+179
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,185 @@ Document[0, 85]
10061006
````````````````````````````````
10071007

10081008

1009+
### In Links
1010+
1011+
1012+
```````````````````````````````` example Footnotes - In Links: 1
1013+
[[^footnote]](/url)
1014+
.
1015+
<p><a href="/url">[^footnote]</a></p>
1016+
.
1017+
Document[0, 19]
1018+
Paragraph[0, 19]
1019+
Link[0, 19] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] linkOpen:[13, 14, "("] url:[14, 18, "/url"] pageRef:[14, 18, "/url"] linkClose:[18, 19, ")"]
1020+
Text[1, 12] chars:[1, 12, "[^foo … note]"]
1021+
````````````````````````````````
1022+
1023+
1024+
```````````````````````````````` example Footnotes - In Links: 2
1025+
[[^footnote]](/url)
1026+
1027+
[^footnote]: test footnote
1028+
.
1029+
<p>[<sup id="fnref-1"><a class="footnote-ref" href="#fn-1">1</a></sup>](/url)</p>
1030+
<div class="footnotes">
1031+
<hr />
1032+
<ol>
1033+
<li id="fn-1">
1034+
<p>test footnote</p>
1035+
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
1036+
</li>
1037+
</ol>
1038+
</div>
1039+
.
1040+
Document[0, 51]
1041+
Paragraph[0, 20] isTrailingBlankLine
1042+
Text[0, 1] chars:[0, 1, "["]
1043+
Footnote[1, 12] ordinal: 1 textOpen:[1, 3, "[^"] text:[3, 11, "footnote"] textClose:[11, 12, "]"]
1044+
Text[3, 11] chars:[3, 11, "footnote"]
1045+
Text[12, 19] chars:[12, 19, "](/url)"]
1046+
FootnoteBlock[25, 51] ordinal: 1 open:[25, 27] text:[27, 35] close:[35, 37] footnote:[38, 51]
1047+
Paragraph[38, 51]
1048+
Text[38, 51] chars:[38, 51, "test … tnote"]
1049+
````````````````````````````````
1050+
1051+
1052+
```````````````````````````````` example(Footnotes - In Links: 3) options(link-text-priority)
1053+
[[^footnote]](/url)
1054+
.
1055+
<p><a href="/url">[^footnote]</a></p>
1056+
.
1057+
Document[0, 19]
1058+
Paragraph[0, 19]
1059+
Link[0, 19] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] linkOpen:[13, 14, "("] url:[14, 18, "/url"] pageRef:[14, 18, "/url"] linkClose:[18, 19, ")"]
1060+
Text[1, 12] chars:[1, 12, "[^foo … note]"]
1061+
````````````````````````````````
1062+
1063+
1064+
```````````````````````````````` example(Footnotes - In Links: 4) options(link-text-priority)
1065+
[[^footnote]](/url)
1066+
1067+
[^footnote]: test footnote
1068+
.
1069+
<p><a href="/url">[^footnote]</a></p>
1070+
<div class="footnotes">
1071+
<hr />
1072+
<ol>
1073+
<li id="fn-1">
1074+
<p>test footnote</p>
1075+
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
1076+
</li>
1077+
</ol>
1078+
</div>
1079+
.
1080+
Document[0, 51]
1081+
Paragraph[0, 20] isTrailingBlankLine
1082+
Link[0, 19] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] linkOpen:[13, 14, "("] url:[14, 18, "/url"] pageRef:[14, 18, "/url"] linkClose:[18, 19, ")"]
1083+
Text[1, 12] chars:[1, 12, "[^foo … note]"]
1084+
FootnoteBlock[25, 51] ordinal: 1 open:[25, 27] text:[27, 35] close:[35, 37] footnote:[38, 51]
1085+
Paragraph[38, 51]
1086+
Text[38, 51] chars:[38, 51, "test … tnote"]
1087+
````````````````````````````````
1088+
1089+
1090+
defined footnote in link refs have priority
1091+
1092+
```````````````````````````````` example Footnotes - In Links: 5
1093+
[[^footnote]][ref]
1094+
1095+
[ref]: /url
1096+
.
1097+
<p><a href="/url">[^footnote]</a></p>
1098+
.
1099+
Document[0, 35]
1100+
Paragraph[0, 19] isTrailingBlankLine
1101+
LinkRef[0, 18] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
1102+
Text[1, 12] chars:[1, 12, "[^foo … note]"]
1103+
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
1104+
````````````````````````````````
1105+
1106+
1107+
```````````````````````````````` example Footnotes - In Links: 6
1108+
[[^footnote]][ref]
1109+
1110+
[ref]: /url
1111+
1112+
[^footnote]: test footnote
1113+
.
1114+
<p>[<sup id="fnref-1"><a class="footnote-ref" href="#fn-1">1</a></sup>]<a href="/url">ref</a></p>
1115+
<div class="footnotes">
1116+
<hr />
1117+
<ol>
1118+
<li id="fn-1">
1119+
<p>test footnote</p>
1120+
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
1121+
</li>
1122+
</ol>
1123+
</div>
1124+
.
1125+
Document[0, 67]
1126+
Paragraph[0, 19] isTrailingBlankLine
1127+
Text[0, 1] chars:[0, 1, "["]
1128+
Footnote[1, 12] ordinal: 1 textOpen:[1, 3, "[^"] text:[3, 11, "footnote"] textClose:[11, 12, "]"]
1129+
Text[3, 11] chars:[3, 11, "footnote"]
1130+
Text[12, 13] chars:[12, 13, "]"]
1131+
LinkRef[13, 18] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
1132+
Text[14, 17] chars:[14, 17, "ref"]
1133+
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
1134+
FootnoteBlock[41, 67] ordinal: 1 open:[41, 43] text:[43, 51] close:[51, 53] footnote:[54, 67]
1135+
Paragraph[54, 67]
1136+
Text[54, 67] chars:[54, 67, "test … tnote"]
1137+
````````````````````````````````
1138+
1139+
1140+
```````````````````````````````` example(Footnotes - In Links: 7) options(link-text-priority)
1141+
[[^footnote]][ref]
1142+
1143+
[ref]: /url
1144+
.
1145+
<p><a href="/url">[^footnote]</a></p>
1146+
.
1147+
Document[0, 35]
1148+
Paragraph[0, 19] isTrailingBlankLine
1149+
LinkRef[0, 18] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
1150+
Text[1, 12] chars:[1, 12, "[^foo … note]"]
1151+
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
1152+
````````````````````````````````
1153+
1154+
1155+
```````````````````````````````` example(Footnotes - In Links: 8) options(link-text-priority)
1156+
[[^footnote]][ref]
1157+
1158+
[ref]: /url
1159+
1160+
[^footnote]: test footnote
1161+
.
1162+
<p>[<sup id="fnref-1"><a class="footnote-ref" href="#fn-1">1</a></sup>]<a href="/url">ref</a></p>
1163+
<div class="footnotes">
1164+
<hr />
1165+
<ol>
1166+
<li id="fn-1">
1167+
<p>test footnote</p>
1168+
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
1169+
</li>
1170+
</ol>
1171+
</div>
1172+
.
1173+
Document[0, 67]
1174+
Paragraph[0, 19] isTrailingBlankLine
1175+
Text[0, 1] chars:[0, 1, "["]
1176+
Footnote[1, 12] ordinal: 1 textOpen:[1, 3, "[^"] text:[3, 11, "footnote"] textClose:[11, 12, "]"]
1177+
Text[3, 11] chars:[3, 11, "footnote"]
1178+
Text[12, 13] chars:[12, 13, "]"]
1179+
LinkRef[13, 18] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
1180+
Text[14, 17] chars:[14, 17, "ref"]
1181+
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
1182+
FootnoteBlock[41, 67] ordinal: 1 open:[41, 43] text:[43, 51] close:[51, 53] footnote:[54, 67]
1183+
Paragraph[54, 67]
1184+
Text[54, 67] chars:[54, 67, "test … tnote"]
1185+
````````````````````````````````
1186+
1187+
10091188
## Source Position Attribute
10101189

10111190
```````````````````````````````` example(Source Position Attribute: 1) options(src-pos)

Diff for: flexmark-ext-wikilink/src/main/java/com/vladsch/flexmark/ext/wikilink/WikiLink.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.vladsch.flexmark.ext.wikilink;
22

3+
import com.vladsch.flexmark.ast.LinkRendered;
34
import com.vladsch.flexmark.util.sequence.BasedSequence;
45

5-
public class WikiLink extends WikiNode {
6+
public class WikiLink extends WikiNode implements LinkRendered {
67
public WikiLink(boolean linkIsFirst) {
78
super(linkIsFirst);
89
}

Diff for: flexmark-ext-wikilink/src/main/java/com/vladsch/flexmark/ext/wikilink/WikiNode.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.vladsch.flexmark.ext.wikilink;
22

3+
import com.vladsch.flexmark.ast.LinkRefDerived;
34
import com.vladsch.flexmark.util.ast.DoNotDecorate;
45
import com.vladsch.flexmark.util.ast.Node;
56
import com.vladsch.flexmark.util.ast.NodeVisitor;
@@ -11,7 +12,7 @@
1112
import com.vladsch.flexmark.util.sequence.builder.ISequenceBuilder;
1213
import org.jetbrains.annotations.NotNull;
1314

14-
public class WikiNode extends Node implements DoNotDecorate, TextContainer {
15+
public class WikiNode extends Node implements DoNotDecorate, TextContainer, LinkRefDerived {
1516
final public static char SEPARATOR_CHAR = '|';
1617

1718
protected BasedSequence openingMarker = BasedSequence.NULL;
@@ -83,6 +84,14 @@ public WikiNode(boolean linkIsFirst) {
8384
this.linkIsFirst = linkIsFirst;
8485
}
8586

87+
/**
88+
* @return true if this node will be rendered as text because it depends on a reference which is not defined.
89+
*/
90+
@Override
91+
public boolean isTentative() {
92+
return false;
93+
}
94+
8695
public WikiNode(BasedSequence chars, boolean linkIsFirst, boolean allowAnchors, boolean canEscapePipe, boolean canEscapeAnchor) {
8796
super(chars);
8897
this.linkIsFirst = linkIsFirst;

Diff for: flexmark-ext-wikilink/src/test/java/com/vladsch/flexmark/ext/wikilink/ComboWikiLinkSpecTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class ComboWikiLinkSpecTest extends RendererSpecTest {
3737
optionsMap.put("allow-pipe-escape", new MutableDataSet().set(WikiLinkExtension.ALLOW_PIPE_ESCAPE, true));
3838
optionsMap.put("allow-anchor-escape", new MutableDataSet().set(WikiLinkExtension.ALLOW_ANCHOR_ESCAPE, true));
3939
optionsMap.put("custom-link-escape", new MutableDataSet().set(WikiLinkExtension.LINK_ESCAPE_CHARS, " +<>").set(WikiLinkExtension.LINK_REPLACE_CHARS, "____"));
40+
optionsMap.put("link-text-priority", new MutableDataSet().set(Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF, true));
4041
}
4142
public ComboWikiLinkSpecTest(@NotNull SpecExample example) {
4243
super(example, optionsMap, OPTIONS);

0 commit comments

Comments
 (0)