1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
package org.apache.maven.doxia.module.markdown; |
20 |
|
|
21 |
|
import java.io.IOException; |
22 |
|
import java.util.Arrays; |
23 |
|
|
24 |
|
import org.devacfr.testing.jupiter.TestCase; |
25 |
|
import org.junit.jupiter.api.Test; |
26 |
|
|
27 |
|
import com.vladsch.flexmark.ext.abbreviation.AbbreviationExtension; |
28 |
|
import com.vladsch.flexmark.ext.autolink.AutolinkExtension; |
29 |
|
import com.vladsch.flexmark.ext.definition.DefinitionExtension; |
30 |
|
import com.vladsch.flexmark.ext.escaped.character.EscapedCharacterExtension; |
31 |
|
import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension; |
32 |
|
import com.vladsch.flexmark.ext.tables.TablesExtension; |
33 |
|
import com.vladsch.flexmark.ext.typographic.TypographicExtension; |
34 |
|
import com.vladsch.flexmark.ext.wikilink.WikiLinkExtension; |
35 |
|
import com.vladsch.flexmark.ext.yaml.front.matter.YamlFrontMatterExtension; |
36 |
|
import com.vladsch.flexmark.html.HtmlRenderer; |
37 |
|
import com.vladsch.flexmark.util.ast.Node; |
38 |
|
import com.vladsch.flexmark.util.data.MutableDataSet; |
39 |
|
|
|
|
| 95,2% |
Uncovered Elements: 1 (21) |
Complexity: 4 |
Complexity Density: 0,22 |
|
40 |
|
public class FlexmarkParserTest extends TestCase { |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static final com.vladsch.flexmark.parser.Parser FLEXMARK_PARSER; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
private static final HtmlRenderer FLEXMARK_HTML_RENDERER; |
52 |
|
|
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
|
54 |
1 |
static {... |
55 |
1 |
MutableDataSet flexmarkOptions = new MutableDataSet(); |
56 |
|
|
57 |
|
|
58 |
1 |
flexmarkOptions.set( |
59 |
|
com.vladsch.flexmark.parser.Parser.EXTENSIONS, |
60 |
|
Arrays.asList( |
61 |
|
EscapedCharacterExtension.create(), |
62 |
|
AbbreviationExtension.create(), |
63 |
|
AutolinkExtension.create(), |
64 |
|
DefinitionExtension.create(), |
65 |
|
TypographicExtension.create(), |
66 |
|
TablesExtension.create(), |
67 |
|
WikiLinkExtension.create(), |
68 |
|
StrikethroughExtension.create())); |
69 |
|
|
70 |
|
|
71 |
1 |
flexmarkOptions.set(TypographicExtension.SINGLE_QUOTE_UNMATCHED, "'"); |
72 |
|
|
73 |
|
|
74 |
1 |
flexmarkOptions.set(HtmlRenderer.HTML_BLOCK_OPEN_TAG_EOL, false); |
75 |
1 |
flexmarkOptions.set(HtmlRenderer.HTML_BLOCK_CLOSE_TAG_EOL, false); |
76 |
1 |
flexmarkOptions.set(HtmlRenderer.MAX_TRAILING_BLANK_LINES, -1); |
77 |
|
|
78 |
|
|
79 |
1 |
FLEXMARK_PARSER = com.vladsch.flexmark.parser.Parser.builder(flexmarkOptions).build(); |
80 |
|
|
81 |
1 |
MutableDataSet flexmarkMetadataOptions = new MutableDataSet(); |
82 |
1 |
flexmarkMetadataOptions.set( |
83 |
|
com.vladsch.flexmark.parser.Parser.EXTENSIONS, Arrays.asList(YamlFrontMatterExtension.create())); |
84 |
|
|
85 |
|
|
86 |
1 |
FLEXMARK_HTML_RENDERER = HtmlRenderer.builder(flexmarkOptions) |
87 |
|
.linkResolverFactory(new FlexmarkDoxiaLinkResolver.Factory()) |
88 |
|
.build(); |
89 |
|
} |
90 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0,4 |
1PASS
|
|
91 |
1 |
@Test... |
92 |
|
public void shouldConvertMarkdown() { |
93 |
1 |
verify((content) -> { |
94 |
1 |
StringBuilder html = new StringBuilder(); |
95 |
1 |
try { |
96 |
1 |
return render(content, html); |
97 |
|
} catch (IOException e) { |
98 |
0 |
throw new RuntimeException(e); |
99 |
|
} |
100 |
|
}, "md"); |
101 |
|
} |
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
|
103 |
1 |
private String render(String content, Appendable html) throws IOException {... |
104 |
1 |
Node documentRoot = FLEXMARK_PARSER.parse(content); |
105 |
1 |
FLEXMARK_HTML_RENDERER.render(documentRoot, html); |
106 |
1 |
return html.toString(); |
107 |
|
|
108 |
|
} |
109 |
|
} |