Skip to content

Commit b0a23ee

Browse files
committed
add src position by paragraph line
1 parent 461f516 commit b0a23ee

63 files changed

Lines changed: 1787 additions & 186 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

VERSION.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ flexmark-java
44
[TOC]: # "## Version History"
55

66
## Version History
7+
- [0.4.14](#0414)
78
- [0.4.13](#0413)
89
- [0.4.12](#0412)
910
- [0.4.11](#0411)
@@ -42,6 +43,20 @@ flexmark-java
4243
- [0.1.1](#011)
4344
- [0.1.0](#010)
4445

46+
0.4.14
47+
------
48+
49+
- Add `HtmlWriter.srcPos()` methods to add source position information to the next `.withAttr()`
50+
tag.
51+
52+
- Add `HtmlRenderer.SOURCE_POSITION_ATTRIBUTE` the name of the source position HTML attribute so
53+
set to the source position given in `.srcPos()` methods.
54+
55+
- Add `HtmlRenderer.SOURCE_POSITION_PARAGRAPH_LINES` if true then paragraph source lines will be
56+
wrapped in `<span></span>` with source position information for the line. Works even for tight
57+
list items that do not generate a `<p>` wrapper for their text. :warning: Only works if source
58+
position attribute is set to non-empty value.
59+
4560
0.4.13
4661
------
4762

flexmark-ext-abbreviation/src/main/java/com/vladsch/flexmark/ext/abbreviation/internal/AbbreviationNodeRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private void render(Abbreviation node, NodeRendererContext context, HtmlWriter h
4545
}
4646

4747
html.attr("title", abbreviation);
48-
html.withAttr().tag(tag);
48+
html.srcPos(node.getChars()).withAttr().tag(tag);
4949
html.text(text);
5050
html.tag("/" + tag);
5151
}

flexmark-ext-abbreviation/src/test/java/com/vladsch/flexmark/ext/abbreviation/ComboAbbreviationSpecTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ public class ComboAbbreviationSpecTest extends ComboSpecTestCase {
2020

2121
private static final Map<String, DataHolder> optionsMap = new HashMap<>();
2222
static {
23-
optionsMap.put("links", new MutableDataSet()
24-
.set(AbbreviationExtension.USE_LINKS, true)
25-
);
23+
optionsMap.put("src-pos", new MutableDataSet().set(HtmlRenderer.SOURCE_POSITION_ATTRIBUTE, "md-pos"));
24+
optionsMap.put("links", new MutableDataSet().set(AbbreviationExtension.USE_LINKS, true));
2625
}
2726

2827
static final Parser PARSER = Parser.builder(OPTIONS).build();

flexmark-ext-abbreviation/src/test/resources/ext_abbreviation_ast_spec.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ license: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)'
1010

1111
## Abbreviation
1212

13-
flexmark-java extension for defining abbreviations and turning
14-
appearance of these abbreviations in text into abbr tags with titles
15-
consisting of the expansion of the abbreviation.
13+
flexmark-java extension for defining abbreviations and turning appearance of these abbreviations
14+
in text into abbr tags with titles consisting of the expansion of the abbreviation.
1615

1716
```````````````````````````````` example Abbreviation: 1
1817
*[Abbr]:Abbreviation
@@ -221,3 +220,23 @@ Document[0, 48]
221220
````````````````````````````````
222221

223222

223+
## Source Position Attribute
224+
225+
```````````````````````````````` example(Source Position Attribute: 1) options(src-pos)
226+
text with abbr embedded
227+
228+
*[abbr]: abbreviation
229+
230+
.
231+
<p md-pos="0-23">text with <abbr title="abbreviation" md-pos="10-14">abbr</abbr> embedded</p>
232+
.
233+
Document[0, 48]
234+
Paragraph[0, 24]
235+
TextBase[0, 23] chars:[0, 23, "text … edded"]
236+
Text[0, 10] chars:[0, 10, "text with "]
237+
Abbreviation[10, 14] chars:[10, 14, "abbr"]
238+
Text[14, 23] chars:[14, 23, " embedded"]
239+
AbbreviationBlock[25, 46] open:[25, 27] text:[27, 31] close:[31, 33] abbreviation:[34, 46]
240+
````````````````````````````````
241+
242+

flexmark-ext-anchorlink/src/test/java/com/vladsch/flexmark/ext/anchorlink/ComboAnchorLinkSpecTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class ComboAnchorLinkSpecTest extends ComboSpecTestCase {
2424

2525
private static final Map<String, DataHolder> optionsMap = new HashMap<>();
2626
static {
27+
optionsMap.put("src-pos", new MutableDataSet().set(HtmlRenderer.SOURCE_POSITION_ATTRIBUTE, "md-pos"));
2728
optionsMap.put("no-wrap", new MutableDataSet().set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, false));
2829
optionsMap.put("set-name", new MutableDataSet().set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true));
2930
optionsMap.put("no-id", new MutableDataSet().set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false));

flexmark-ext-anchorlink/src/test/resources/ext_anchorlink_ast_spec.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,17 @@ Document[0, 21]
170170
````````````````````````````````
171171

172172

173+
## Source Position Attribute
174+
175+
```````````````````````````````` example(Source Position Attribute: 1) options(src-pos)
176+
# Header
177+
.
178+
<h1 md-pos="2-8"><a href="#header" id="header" class="anchor">Header</a></h1>
179+
.
180+
Document[0, 9]
181+
Heading[0, 8] textOpen:[0, 1, "#"] text:[2, 8, "Header"]
182+
AnchorLink[2, 8]
183+
Text[2, 8] chars:[2, 8, "Header"]
184+
````````````````````````````````
185+
186+

flexmark-ext-autolink/src/test/java/com/vladsch/flexmark/ext/autolink/ComboAutolinkSpecTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ComboAutolinkSpecTest extends ComboSpecTestCase {
2222

2323
private static final Map<String, DataHolder> optionsMap = new HashMap<>();
2424
static {
25+
optionsMap.put("src-pos", new MutableDataSet().set(HtmlRenderer.SOURCE_POSITION_ATTRIBUTE, "md-pos"));
2526
optionsMap.put("no-autolink", new MutableDataSet().set(Parser.EXTENSIONS, Collections.EMPTY_LIST));
2627
// optionsMap.put("custom", new MutableDataSet()
2728
// .set(AutolinkExtension.AUTOLINK, value)

flexmark-ext-autolink/src/test/resources/ext_autolink_ast_spec.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,24 @@ Document[0, 21]
112112
````````````````````````````````
113113

114114

115+
## Source Position Attribute
116+
117+
```````````````````````````````` example(Source Position Attribute: 1) options(src-pos)
118+
119+
http://example.com
120+
.
121+
<p md-pos="0-34"><a md-pos="0-15" href="mailto:[email protected]">[email protected]</a>
122+
<a md-pos="16-34" href="http://example.com">http://example.com</a></p>
123+
.
124+
Document[0, 35]
125+
Paragraph[0, 35]
126+
TextBase[0, 15] chars:[0, 15, "foo@e … e.com"]
127+
MailLink[0, 15] text:[0, 15, "[email protected]"]
128+
Text[0, 15] chars:[0, 15, "foo@e … e.com"]
129+
SoftLineBreak[15, 16]
130+
TextBase[16, 34] chars:[16, 34, "http: … e.com"]
131+
AutoLink[16, 34] text:[16, 34, "http://example.com"]
132+
Text[16, 34] chars:[16, 34, "http: … e.com"]
133+
````````````````````````````````
134+
135+

flexmark-ext-definition/src/test/java/com/vladsch/flexmark/ext/definition/ComboDefinitionSpecTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class ComboDefinitionSpecTest extends ComboSpecTestCase {
2020

2121
private static final Map<String, DataHolder> optionsMap = new HashMap<>();
2222
static {
23+
optionsMap.put("src-pos", new MutableDataSet().set(HtmlRenderer.SOURCE_POSITION_ATTRIBUTE, "md-pos"));
2324
optionsMap.put("option1", new MutableDataSet().set(DefinitionExtension.NO_TERM_TRAILING_COLON, true));
2425
}
2526

flexmark-ext-definition/src/test/resources/ext_definition_ast_spec.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,17 @@ Term 4
243243
````````````````````````````````
244244

245245

246+
## Source Position Attribute
247+
248+
```````````````````````````````` example(Source Position Attribute: 1) options(src-pos, IGNORE)
249+
Definition Term
250+
: definition item
251+
.
252+
<dl>
253+
<dt>Definition Term</dt>
254+
<dd>definition item</dd>
255+
</dl>
256+
.
257+
````````````````````````````````
258+
259+

0 commit comments

Comments
 (0)