Skip to content

Commit

Permalink
unify link ref derived link rendering elements in link text
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Apr 30, 2020
1 parent cb24403 commit eee271d
Show file tree
Hide file tree
Showing 13 changed files with 398 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions VERSION-TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,15 @@ Please give feedback on the upcoming changes if you have concerns about breaking
taking options flags.
* Fix: `MarkdownParagraph` wrapping with preserving tracked offsets with spaces to preserve
spaces right before last non-blank character.
* Fix: unify handling of link generating inline element handling in link text elements.
* Add: `LinkRendered` interface to identify link rendering elements derived from link/image
ref syntax identified by implementation of `LinkRefDerived` interface
* Fix: `WikiNode` to implement `LinkRefDerived`
* Fix: `WikiLink` to implement `LinkRendered`
* Fix: `Footnote` to implement `LinkRendered`

:information_source: nested link ref derived elements in link ref text have priority and
cannot be used to embed into link ref text using `[link ref text][ref id]` syntax.

## 0.61.24

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vladsch.flexmark.ext.footnotes;

import com.vladsch.flexmark.ast.LinkRendered;
import com.vladsch.flexmark.ext.footnotes.internal.FootnoteRepository;
import com.vladsch.flexmark.util.ast.*;
import com.vladsch.flexmark.util.sequence.BasedSequence;
Expand All @@ -8,7 +9,7 @@
/**
* A Footnote referencing node
*/
public class Footnote extends Node implements DelimitedNode, DoNotDecorate, ReferencingNode<FootnoteRepository, FootnoteBlock> {
public class Footnote extends Node implements DelimitedNode, DoNotDecorate, LinkRendered, ReferencingNode<FootnoteRepository, FootnoteBlock> {
protected BasedSequence openingMarker = BasedSequence.NULL;
protected BasedSequence text = BasedSequence.NULL;
protected BasedSequence closingMarker = BasedSequence.NULL;
Expand Down Expand Up @@ -48,6 +49,14 @@ public boolean isDefined() {
return footnoteBlock != null;
}

/**
* @return true if this node will be rendered as text because it depends on a reference which is not defined.
*/
@Override
public boolean isTentative() {
return footnoteBlock == null;
}

public FootnoteBlock getFootnoteBlock(FootnoteRepository footnoteRepository) {
return text.isEmpty() ? null : footnoteRepository.get(text.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ComboFootnotesSpecTest extends RendererSpecTest {
optionsMap.put("back-link-class-none", new MutableDataSet().set(FootnoteExtension.FOOTNOTE_BACK_LINK_REF_CLASS, ""));
optionsMap.put("back-link-class-text", new MutableDataSet().set(FootnoteExtension.FOOTNOTE_BACK_LINK_REF_CLASS, "text"));
optionsMap.put("item-indent-8", new MutableDataSet().set(Parser.LISTS_ITEM_INDENT, 8));
optionsMap.put("link-text-priority", new MutableDataSet().set(Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF, true));
}
public ComboFootnotesSpecTest(@NotNull SpecExample example) {
super(example, optionsMap, OPTIONS);
Expand Down
179 changes: 179 additions & 0 deletions flexmark-ext-footnotes/src/test/resources/ext_footnotes_ast_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,185 @@ Document[0, 85]
````````````````````````````````


### In Links


```````````````````````````````` example Footnotes - In Links: 1
[[^footnote]](/url)
.
<p><a href="/url">[^footnote]</a></p>
.
Document[0, 19]
Paragraph[0, 19]
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, ")"]
Text[1, 12] chars:[1, 12, "[^foo … note]"]
````````````````````````````````


```````````````````````````````` example Footnotes - In Links: 2
[[^footnote]](/url)
[^footnote]: test footnote
.
<p>[<sup id="fnref-1"><a class="footnote-ref" href="#fn-1">1</a></sup>](/url)</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn-1">
<p>test footnote</p>
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
</li>
</ol>
</div>
.
Document[0, 51]
Paragraph[0, 20] isTrailingBlankLine
Text[0, 1] chars:[0, 1, "["]
Footnote[1, 12] ordinal: 1 textOpen:[1, 3, "[^"] text:[3, 11, "footnote"] textClose:[11, 12, "]"]
Text[3, 11] chars:[3, 11, "footnote"]
Text[12, 19] chars:[12, 19, "](/url)"]
FootnoteBlock[25, 51] ordinal: 1 open:[25, 27] text:[27, 35] close:[35, 37] footnote:[38, 51]
Paragraph[38, 51]
Text[38, 51] chars:[38, 51, "test … tnote"]
````````````````````````````````


```````````````````````````````` example(Footnotes - In Links: 3) options(link-text-priority)
[[^footnote]](/url)
.
<p><a href="/url">[^footnote]</a></p>
.
Document[0, 19]
Paragraph[0, 19]
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, ")"]
Text[1, 12] chars:[1, 12, "[^foo … note]"]
````````````````````````````````


```````````````````````````````` example(Footnotes - In Links: 4) options(link-text-priority)
[[^footnote]](/url)
[^footnote]: test footnote
.
<p><a href="/url">[^footnote]</a></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn-1">
<p>test footnote</p>
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
</li>
</ol>
</div>
.
Document[0, 51]
Paragraph[0, 20] isTrailingBlankLine
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, ")"]
Text[1, 12] chars:[1, 12, "[^foo … note]"]
FootnoteBlock[25, 51] ordinal: 1 open:[25, 27] text:[27, 35] close:[35, 37] footnote:[38, 51]
Paragraph[38, 51]
Text[38, 51] chars:[38, 51, "test … tnote"]
````````````````````````````````


defined footnote in link refs have priority

```````````````````````````````` example Footnotes - In Links: 5
[[^footnote]][ref]
[ref]: /url
.
<p><a href="/url">[^footnote]</a></p>
.
Document[0, 35]
Paragraph[0, 19] isTrailingBlankLine
LinkRef[0, 18] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
Text[1, 12] chars:[1, 12, "[^foo … note]"]
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
````````````````````````````````


```````````````````````````````` example Footnotes - In Links: 6
[[^footnote]][ref]
[ref]: /url
[^footnote]: test footnote
.
<p>[<sup id="fnref-1"><a class="footnote-ref" href="#fn-1">1</a></sup>]<a href="/url">ref</a></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn-1">
<p>test footnote</p>
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
</li>
</ol>
</div>
.
Document[0, 67]
Paragraph[0, 19] isTrailingBlankLine
Text[0, 1] chars:[0, 1, "["]
Footnote[1, 12] ordinal: 1 textOpen:[1, 3, "[^"] text:[3, 11, "footnote"] textClose:[11, 12, "]"]
Text[3, 11] chars:[3, 11, "footnote"]
Text[12, 13] chars:[12, 13, "]"]
LinkRef[13, 18] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
Text[14, 17] chars:[14, 17, "ref"]
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
FootnoteBlock[41, 67] ordinal: 1 open:[41, 43] text:[43, 51] close:[51, 53] footnote:[54, 67]
Paragraph[54, 67]
Text[54, 67] chars:[54, 67, "test … tnote"]
````````````````````````````````


```````````````````````````````` example(Footnotes - In Links: 7) options(link-text-priority)
[[^footnote]][ref]
[ref]: /url
.
<p><a href="/url">[^footnote]</a></p>
.
Document[0, 35]
Paragraph[0, 19] isTrailingBlankLine
LinkRef[0, 18] textOpen:[0, 1, "["] text:[1, 12, "[^footnote]"] textClose:[12, 13, "]"] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
Text[1, 12] chars:[1, 12, "[^foo … note]"]
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
````````````````````````````````


```````````````````````````````` example(Footnotes - In Links: 8) options(link-text-priority)
[[^footnote]][ref]
[ref]: /url
[^footnote]: test footnote
.
<p>[<sup id="fnref-1"><a class="footnote-ref" href="#fn-1">1</a></sup>]<a href="/url">ref</a></p>
<div class="footnotes">
<hr />
<ol>
<li id="fn-1">
<p>test footnote</p>
<a href="#fnref-1" class="footnote-backref">&#8617;</a>
</li>
</ol>
</div>
.
Document[0, 67]
Paragraph[0, 19] isTrailingBlankLine
Text[0, 1] chars:[0, 1, "["]
Footnote[1, 12] ordinal: 1 textOpen:[1, 3, "[^"] text:[3, 11, "footnote"] textClose:[11, 12, "]"]
Text[3, 11] chars:[3, 11, "footnote"]
Text[12, 13] chars:[12, 13, "]"]
LinkRef[13, 18] referenceOpen:[13, 14, "["] reference:[14, 17, "ref"] referenceClose:[17, 18, "]"]
Text[14, 17] chars:[14, 17, "ref"]
Reference[24, 35] refOpen:[24, 25, "["] ref:[25, 28, "ref"] refClose:[28, 30, "]:"] url:[31, 35, "/url"]
FootnoteBlock[41, 67] ordinal: 1 open:[41, 43] text:[43, 51] close:[51, 53] footnote:[54, 67]
Paragraph[54, 67]
Text[54, 67] chars:[54, 67, "test … tnote"]
````````````````````````````````


## Source Position Attribute

```````````````````````````````` example(Source Position Attribute: 1) options(src-pos)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.vladsch.flexmark.ext.wikilink;

import com.vladsch.flexmark.ast.LinkRendered;
import com.vladsch.flexmark.util.sequence.BasedSequence;

public class WikiLink extends WikiNode {
public class WikiLink extends WikiNode implements LinkRendered {
public WikiLink(boolean linkIsFirst) {
super(linkIsFirst);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.vladsch.flexmark.ext.wikilink;

import com.vladsch.flexmark.ast.LinkRefDerived;
import com.vladsch.flexmark.util.ast.DoNotDecorate;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.ast.NodeVisitor;
Expand All @@ -11,7 +12,7 @@
import com.vladsch.flexmark.util.sequence.builder.ISequenceBuilder;
import org.jetbrains.annotations.NotNull;

public class WikiNode extends Node implements DoNotDecorate, TextContainer {
public class WikiNode extends Node implements DoNotDecorate, TextContainer, LinkRefDerived {
final public static char SEPARATOR_CHAR = '|';

protected BasedSequence openingMarker = BasedSequence.NULL;
Expand Down Expand Up @@ -83,6 +84,14 @@ public WikiNode(boolean linkIsFirst) {
this.linkIsFirst = linkIsFirst;
}

/**
* @return true if this node will be rendered as text because it depends on a reference which is not defined.
*/
@Override
public boolean isTentative() {
return false;
}

public WikiNode(BasedSequence chars, boolean linkIsFirst, boolean allowAnchors, boolean canEscapePipe, boolean canEscapeAnchor) {
super(chars);
this.linkIsFirst = linkIsFirst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ComboWikiLinkSpecTest extends RendererSpecTest {
optionsMap.put("allow-pipe-escape", new MutableDataSet().set(WikiLinkExtension.ALLOW_PIPE_ESCAPE, true));
optionsMap.put("allow-anchor-escape", new MutableDataSet().set(WikiLinkExtension.ALLOW_ANCHOR_ESCAPE, true));
optionsMap.put("custom-link-escape", new MutableDataSet().set(WikiLinkExtension.LINK_ESCAPE_CHARS, " +<>").set(WikiLinkExtension.LINK_REPLACE_CHARS, "____"));
optionsMap.put("link-text-priority", new MutableDataSet().set(Parser.LINK_TEXT_PRIORITY_OVER_LINK_REF, true));
}
public ComboWikiLinkSpecTest(@NotNull SpecExample example) {
super(example, optionsMap, OPTIONS);
Expand Down
Loading

0 comments on commit eee271d

Please sign in to comment.