Skip to content

Commit

Permalink
fix to not wrap multiline URL images
Browse files Browse the repository at this point in the history
  • Loading branch information
vsch committed Apr 11, 2020
1 parent c36ff2b commit d8a76e5
Show file tree
Hide file tree
Showing 17 changed files with 659 additions and 126 deletions.
11 changes: 11 additions & 0 deletions VERSION-TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ Please give feedback on the upcoming changes if you have concerns about breaking

* Fix: add more information to `MarkdownParagraph.resolveTrackedOffsetsEdit` assert failures to
allow better diagnostics in reported stack traces.
* Fix: disable wrapping of multiline URL image links
* Fix: `Paragraph` content node to preserve leading spaces on lines. Otherwise, multiline URL
image content would loose indents since these were stripped from paragraph content during
parsing.
* Fix: `TablesExtension` to accept non-indenting leading spaces on all table rows. This
results in previously non-table text as valid table texts:

```markdown
Abc|Def
|---|---
```

## 0.61.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public abstract class FormatterTranslationSpecTestBase extends ComboSpecTestCase
optionsMap.put("delete-space", new MutableDataSet().set(EDIT_OP, -1).set(EDIT_OP_CHAR, ' '));
// optionsMap.put("indent-edit", new MutableDataSet().set(EDIT_INDENT, true));
optionsMap.put("restore-tracked-spaces", new MutableDataSet().set(Formatter.RESTORE_TRACKED_SPACES, true));
optionsMap.put("multi-line-image-url", new MutableDataSet().set(Parser.PARSE_MULTI_LINE_IMAGE_URLS, true));

optionsMap.put("format-fixed-indent", new MutableDataSet().set(Formatter.FORMATTER_EMULATION_PROFILE, ParserEmulationProfile.FIXED_INDENT));
optionsMap.put("format-content-after-prefix", new MutableDataSet().set(Formatter.LISTS_ITEM_CONTENT_AFTER_SUFFIX, true));
Expand Down
2 changes: 1 addition & 1 deletion flexmark-core-test/src/test/resources/ast_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -12815,7 +12815,7 @@ Document[0, 14]
Paragraph[0, 14]
Text[0, 3] chars:[0, 3, "foo"]
HardLineBreak[3, 5]
Text[10, 13] chars:[10, 13, "bar"]
Text[10, 13] chars:[10, 13, " bar"]
````````````````````````````````


Expand Down
77 changes: 67 additions & 10 deletions flexmark-core-test/src/test/resources/core_extra_ast_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -4159,7 +4159,64 @@ Document[0, 59]
````````````````````````````````


```````````````````````````````` example(Multi-Line Image URL: 11) options(unmatched-fence)
encoding of embedded EOL

```````````````````````````````` example(Multi-Line Image URL: 11) options(multi-line-image-url)
![ref](/url1?
one = 1 & line
line two
) trailing text
.
<p><img src="/url1?one%20=%201%20&amp;%20line%0Aline%20two%0A" alt="ref" /> trailing text</p>
.
Document[0, 53]
Paragraph[0, 53]
Image[0, 39] textOpen:[0, 2, "!["] text:[2, 5, "ref"] textClose:[5, 6, "]"] linkOpen:[6, 7, "("] url:[7, 13, "/url1?"] pageRef:[7, 13, "/url1?"] urlContent:[14, 38, "one = 1 & line\nline two\n"] linkClose:[38, 39, ")"]
Text[2, 5] chars:[2, 5, "ref"]
Text[39, 53] chars:[39, 53, " trai … text"]
````````````````````````````````


preserve content indent

```````````````````````````````` example(Multi-Line Image URL: 12) options(multi-line-image-url)
![ref](/url1?
one = 1 & line
line two
) trailing text
.
<p><img src="/url1?%20%20%20%20one%20=%201%20&amp;%20line%0A%20%20%20%20line%20two%0A" alt="ref" /> trailing text</p>
.
Document[0, 61]
Paragraph[0, 61]
Image[0, 47] textOpen:[0, 2, "!["] text:[2, 5, "ref"] textClose:[5, 6, "]"] linkOpen:[6, 7, "("] url:[7, 13, "/url1?"] pageRef:[7, 13, "/url1?"] urlContent:[18, 46, " one = 1 & line\n line two\n"] linkClose:[46, 47, ")"]
Text[2, 5] chars:[2, 5, "ref"]
Text[47, 61] chars:[47, 61, " trai … text"]
````````````````````````````````


```````````````````````````````` example(Multi-Line Image URL: 13) options(multi-line-image-url)
> ![ref](/url1?
> one = 1 & line
> line two
> ) trailing text
.
<blockquote>
<p><img src="/url1?%20%20%20%20one%20=%201%20&amp;%20line%0A%20%20%20%20line%20two%0A" alt="ref" /> trailing text</p>
</blockquote>
.
Document[0, 69]
BlockQuote[0, 69] marker:[0, 1, ">"]
Paragraph[2, 69]
Image[2, 55] textOpen:[2, 4, "!["] text:[4, 7, "ref"] textClose:[7, 8, "]"] linkOpen:[8, 9, "("] url:[9, 15, "/url1?"] pageRef:[9, 15, "/url1?"] urlContent:[22, 52, " one = 1 & line\n line two\n"] linkClose:[54, 55, ")"]
Text[4, 7] chars:[4, 7, "ref"]
Text[55, 69] chars:[55, 69, " trai … text"]
````````````````````````````````


## Fenced Code

```````````````````````````````` example(Fenced Code: 1) options(unmatched-fence)
~~~
proper unmatched fenced code
```
Expand All @@ -4175,7 +4232,7 @@ Document[0, 36]

non empty, info, blank line follows, unmatched

```````````````````````````````` example(Multi-Line Image URL: 12) options(unmatched-fence)
```````````````````````````````` example(Fenced Code: 2) options(unmatched-fence)
```info
some text
~~~
Expand Down Expand Up @@ -5399,10 +5456,10 @@ lines*
Document[0, 131]
Paragraph[0, 131]
Text[0, 10] chars:[0, 10, "paragraph "]
Code[10, 23] textOpen:[10, 11, "`"] text:[11, 22, "test \nwith"] textClose:[22, 23, "`"]
Code[10, 23] textOpen:[10, 11, "`"] text:[11, 22, "test … \n with"] textClose:[22, 23, "`"]
Text[11, 16] chars:[11, 16, "test "]
SoftLineBreak[16, 17]
Text[18, 22] chars:[18, 22, "with"]
Text[18, 22] chars:[18, 22, " with"]
Text[23, 45] chars:[23, 45, " mult … lines"]
SoftLineBreak[45, 46]
Text[46, 56] chars:[46, 56, "paragraph "]
Expand All @@ -5411,7 +5468,7 @@ Document[0, 131]
SoftLineBreak[61, 62]
Text[62, 66] chars:[62, 66, "with"]
Text[67, 82] chars:[67, 82, " mult … lazy "]
StrongEmphasis[82, 97] textOpen:[82, 84, "**"] text:[84, 95, "lines\nall"] textClose:[95, 97, "**"]
StrongEmphasis[82, 97] textOpen:[82, 84, "**"] text:[84, 95, "lines\n all"] textClose:[95, 97, "**"]
Text[84, 89] chars:[84, 89, "lines"]
SoftLineBreak[89, 90]
Text[92, 95] chars:[92, 95, "all"]
Expand Down Expand Up @@ -5439,10 +5496,10 @@ lines*
Document[0, 131]
Paragraph[0, 131]
Text[0, 10] chars:[0, 10, "paragraph "]
Code[10, 23] textOpen:[10, 11, "`"] text:[11, 22, "test \nwith"] textClose:[22, 23, "`"]
Code[10, 23] textOpen:[10, 11, "`"] text:[11, 22, "test … \n with"] textClose:[22, 23, "`"]
Text[11, 16] chars:[11, 16, "test "]
SoftLineBreak[16, 17]
Text[18, 22] chars:[18, 22, "with"]
Text[18, 22] chars:[18, 22, " with"]
Text[23, 45] chars:[23, 45, " mult … lines"]
SoftLineBreak[45, 46]
Text[46, 56] chars:[46, 56, "paragraph "]
Expand All @@ -5451,7 +5508,7 @@ Document[0, 131]
SoftLineBreak[61, 62]
Text[62, 66] chars:[62, 66, "with"]
Text[67, 82] chars:[67, 82, " mult … lazy "]
StrongEmphasis[82, 97] textOpen:[82, 84, "**"] text:[84, 95, "lines\nall"] textClose:[95, 97, "**"]
StrongEmphasis[82, 97] textOpen:[82, 84, "**"] text:[84, 95, "lines\n all"] textClose:[95, 97, "**"]
Text[84, 89] chars:[84, 89, "lines"]
SoftLineBreak[89, 90]
Text[92, 95] chars:[92, 95, "all"]
Expand Down Expand Up @@ -6830,9 +6887,9 @@ Document[0, 20]
.
Document[0, 31]
Paragraph[0, 31]
Link[0, 31] textOpen:[0, 1, "["] text:[1, 23, "hello **bold\nworld**"] textClose:[23, 24, "]"] linkOpen:[24, 25, "("] url:[25, 30, "#test"] pageRef:[25, 25] anchorMarker:[25, 26, "#"] anchorRef:[26, 30, "test"] linkClose:[30, 31, ")"]
Link[0, 31] textOpen:[0, 1, "["] text:[1, 23, "hello **bold\n world**"] textClose:[23, 24, "]"] linkOpen:[24, 25, "("] url:[25, 30, "#test"] pageRef:[25, 25] anchorMarker:[25, 26, "#"] anchorRef:[26, 30, "test"] linkClose:[30, 31, ")"]
Text[1, 7] chars:[1, 7, "hello "]
StrongEmphasis[7, 23] textOpen:[7, 9, "**"] text:[9, 21, "bold\nworld"] textClose:[21, 23, "**"]
StrongEmphasis[7, 23] textOpen:[7, 9, "**"] text:[9, 21, "bold\n world"] textClose:[21, 23, "**"]
Text[9, 13] chars:[9, 13, "bold"]
SoftLineBreak[13, 14]
Text[16, 21] chars:[16, 21, "world"]
Expand Down
118 changes: 118 additions & 0 deletions flexmark-core-test/src/test/resources/core_wrapping_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,124 @@ BasedSegmentBuilder{[0, 133), s=4:6, u=9:11, t=9:11, l=138, sz=22, na=17: [0, 27
````````````````````````````````


### Images


```````````````````````````````` example(Wrap - Images: 1) options(margin[72], multi-line-image-url, show-ranges)
![alt](http://g.gravizo.com/g?
digraph G {
aize ="4,4";
main [shape=box];
main -> parse [weight=8];
parse -> execute;
main -> init [style=dotted];
main -> testing [style=dashed];
testing -> make_string;
main -> cleanupMore;
execute -> { make_string; printf }
init -> make_string;
edge [color=red];
main -> printf [style=bold,label="100 times"];
make_string [label="make a string"];
node [shape=box,style=fill≤ed,color=".7 .3 1.0"];
execute -> compares;
}
"title works three!!!")
.
![alt](http://g.gravizo.com/g?
digraph G {
aize ="4,4";
main [shape=box];
main -> parse [weight=8];
parse -> execute;
main -> init [style=dotted];
main -> testing [style=dashed];
testing -> make_string;
main -> cleanupMore;
execute -> { make_string; printf }
init -> make_string;
edge [color=red];
main -> printf [style=bold,label="100 times"];
make_string [label="make a string"];
node [shape=box,style=fill≤ed,color=".7 .3 1.0"];
execute -> compares;
}
"title works three!!!")
---- Ranges ------------------------------------------------------------
⟦![alt](http://g.gravizo.com/g?
digraph G {
aize ="4,4";
main [shape=box];
main -> parse [weight=8];
parse -> execute;
main -> init [style=dotted];
main -> testing [style=dashed];
testing -> make_string;
main -> cleanupMore;
execute -> { make_string; printf }
init -> make_string;
edge [color=red];
main -> printf [style=bold,label="100 times"];
make_string [label="make a string"];
node [shape=box,style=fill≤ed,color=".7 .3 1.0"];
execute -> compares;
}
"title works three!!!")⟧
⟦⟧
---- Segments ----------------------------------------------------------
BasedSegmentBuilder{[0, 538), s=0:0, u=1:1, t=1:1, l=539, sz=3, na=2: [0, 538), a:'\n', [538) }
.
Document[0, 538]
Paragraph[0, 538]
Image[0, 538] textOpen:[0, 2, "!["] text:[2, 5, "alt"] textClose:[5, 6, "]"] linkOpen:[6, 7, "("] url:[7, 30, "http://g.gravizo.com/g?"] pageRef:[7, 30, "http://g.gravizo.com/g?"] urlContent:[31, 515, "digraph G {\n aize =\"4,4\";\n main [shape=box];\n main -> parse [weight=8];\n parse -> execute;\n main -> init [style=dotted];\n main -> testing [style=dashed];\n testing -> make_string;\n main -> cleanupMore;\n execute -> { make_string; printf }\n init -> make_string;\n edge [color=red];\n main -> printf [style=bold,label=\"100 times\"];\n make_string [label=\"make a string\"];\n node [shape=box,style=fill≤ed,color=\".7 .3 1.0\"];\n execute -> compares;\n}\n"] titleOpen:[515, 516, "\""] title:[516, 536, "title works three!!!"] titleClose:[536, 537, "\""] linkClose:[537, 538, ")"]
Text[2, 5] chars:[2, 5, "alt"]
````````````````````````````````


```````````````````````````````` example(Wrap - Images: 2) options(margin[72], multi-line-image-url)
> ![alt](http://g.gravizo.com/g?
> digraph G {
> aize ="4,4";
> main [shape=box];
> main -> parse [weight=8];
> parse -> execute;
> main -> init [style=dotted];
> main -> testing [style=dashed];
> testing -> make_string;
> main -> cleanupMore;
> execute -> { make_string; printf }
> init -> make_string;
> edge [color=red];
> main -> printf [style=bold,label="100 times"];
> make_string [label="make a string"];
> node [shape=box,style=fill≤ed,color=".7 .3 1.0"];
> execute -> compares;
> }
> "title works three!!!")
.
> ![alt](http://g.gravizo.com/g?
> digraph G {
> aize ="4,4";
> main [shape=box];
> main -> parse [weight=8];
> parse -> execute;
> main -> init [style=dotted];
> main -> testing [style=dashed];
> testing -> make_string;
> main -> cleanupMore;
> execute -> { make_string; printf }
> init -> make_string;
> edge [color=red];
> main -> printf [style=bold,label="100 times"];
> make_string [label="make a string"];
> node [shape=box,style=fill≤ed,color=".7 .3 1.0"];
> execute -> compares;
> }
> "title works three!!!")
````````````````````````````````


### Delete Indent

delete space to previous non-blank
Expand Down
3 changes: 2 additions & 1 deletion flexmark-ext-footnotes/flexmark-ext-footnotes.iml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="module" module-name="flexmark-core-test" scope="TEST" />
<orderEntry type="library" name="org.jetbrains:annotations" level="project" />
<orderEntry type="module" module-name="flexmark-ext-tables" scope="TEST" />
</component>
</module>
</module>
5 changes: 5 additions & 0 deletions flexmark-ext-footnotes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
<artifactId>flexmark-test-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-ext-tables</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vladsch.flexmark</groupId>
<artifactId>flexmark-core-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vladsch.flexmark.ext.footnotes;

import com.vladsch.flexmark.core.test.util.RendererSpecTest;
import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.parser.Parser;
import com.vladsch.flexmark.test.util.spec.ResourceLocation;
import com.vladsch.flexmark.test.util.spec.SpecExample;
Expand All @@ -9,16 +10,13 @@
import org.jetbrains.annotations.NotNull;
import org.junit.runners.Parameterized;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

public class ComboFootnotesSpecTest extends RendererSpecTest {
static final String SPEC_RESOURCE = "/ext_footnotes_ast_spec.md";
final public static @NotNull ResourceLocation RESOURCE_LOCATION = ResourceLocation.of(SPEC_RESOURCE);
final private static DataHolder OPTIONS = new MutableDataSet()
.set(Parser.EXTENSIONS, Collections.singleton(FootnoteExtension.create()))
.set(Parser.EXTENSIONS, Arrays.asList(FootnoteExtension.create(), TablesExtension.create()))
.toImmutable();

final private static Map<String, DataHolder> optionsMap = new HashMap<>();
Expand Down
Loading

0 comments on commit d8a76e5

Please sign in to comment.