Revision | 88 (tree) |
---|---|
Time | 2020-05-22 12:14:09 |
Author | hirukawa_ryo |
* catalpa 0.8.1
flexmark 0.61.32 に変更しました。(flexmark 0.60以降でAPIの破壊的変更があります。)
@@ -4,9 +4,9 @@ | ||
4 | 4 | import com.vladsch.flexmark.html.HtmlRenderer.Builder; |
5 | 5 | import com.vladsch.flexmark.html.renderer.NodeRenderer; |
6 | 6 | import com.vladsch.flexmark.html.renderer.NodeRendererFactory; |
7 | -import com.vladsch.flexmark.util.builder.Extension; | |
8 | 7 | import com.vladsch.flexmark.util.data.DataHolder; |
9 | 8 | import com.vladsch.flexmark.util.data.MutableDataHolder; |
9 | +import com.vladsch.flexmark.util.misc.Extension; | |
10 | 10 | |
11 | 11 | public class BasicNodeExtension implements HtmlRenderer.HtmlRendererExtension { |
12 | 12 |
@@ -10,7 +10,6 @@ | ||
10 | 10 | import com.vladsch.flexmark.ast.Paragraph; |
11 | 11 | import com.vladsch.flexmark.ast.SoftLineBreak; |
12 | 12 | import com.vladsch.flexmark.ext.attributes.AttributesNode; |
13 | -import com.vladsch.flexmark.html.CustomNodeRenderer; | |
14 | 13 | import com.vladsch.flexmark.html.HtmlWriter; |
15 | 14 | import com.vladsch.flexmark.html.renderer.NodeRenderer; |
16 | 15 | import com.vladsch.flexmark.html.renderer.NodeRendererContext; |
@@ -26,13 +25,13 @@ | ||
26 | 25 | @Override |
27 | 26 | public Set<NodeRenderingHandler<?>> getNodeRenderingHandlers() { |
28 | 27 | Set<NodeRenderingHandler<?>> set = new HashSet<NodeRenderingHandler<?>>(); |
29 | - set.add(new NodeRenderingHandler<Paragraph>(Paragraph.class, new CustomNodeRenderer<Paragraph>() { | |
28 | + set.add(new NodeRenderingHandler<Paragraph>(Paragraph.class, new NodeRenderingHandler.CustomNodeRenderer<Paragraph>() { | |
30 | 29 | @Override |
31 | 30 | public void render(Paragraph node, NodeRendererContext context, HtmlWriter html) { |
32 | 31 | BasicNodeRenderer.this.render(node, context, html); |
33 | 32 | } |
34 | 33 | })); |
35 | - set.add(new NodeRenderingHandler<Heading>(Heading.class, new CustomNodeRenderer<Heading>() { | |
34 | + set.add(new NodeRenderingHandler<Heading>(Heading.class, new NodeRenderingHandler.CustomNodeRenderer<Heading>() { | |
36 | 35 | @Override |
37 | 36 | public void render(Heading node, NodeRendererContext context, HtmlWriter html) { |
38 | 37 | BasicNodeRenderer.this.render(node, context, html); |
@@ -2,8 +2,8 @@ | ||
2 | 2 | |
3 | 3 | import com.vladsch.flexmark.parser.Parser; |
4 | 4 | import com.vladsch.flexmark.parser.Parser.Builder; |
5 | -import com.vladsch.flexmark.util.builder.Extension; | |
6 | 5 | import com.vladsch.flexmark.util.data.MutableDataHolder; |
6 | +import com.vladsch.flexmark.util.misc.Extension; | |
7 | 7 | |
8 | 8 | public class LineDividableTableExtension implements Parser.ParserExtension { |
9 | 9 |
@@ -90,13 +90,13 @@ | ||
90 | 90 | public static class Factory implements ParagraphPreProcessorFactory { |
91 | 91 | |
92 | 92 | @Override |
93 | - public Set<? extends Class<? extends ParagraphPreProcessorFactory>> getAfterDependents() { | |
93 | + public Set<Class<?>> getAfterDependents() { | |
94 | 94 | return null; |
95 | 95 | } |
96 | 96 | |
97 | 97 | @Override |
98 | - public Set<? extends Class<? extends ParagraphPreProcessorFactory>> getBeforeDependents() { | |
99 | - Set<Class<? extends ParagraphPreProcessorFactory>> set = new HashSet<Class<? extends ParagraphPreProcessorFactory>>(); | |
98 | + public Set<Class<?>> getBeforeDependents() { | |
99 | + Set<Class<?>> set = new HashSet<>(); | |
100 | 100 | ParagraphPreProcessorFactory pf = TableParagraphPreProcessor.Factory(); |
101 | 101 | set.add(pf.getClass()); |
102 | 102 | return set; |
@@ -6,10 +6,10 @@ | ||
6 | 6 | import com.vladsch.flexmark.html.LinkResolverFactory; |
7 | 7 | import com.vladsch.flexmark.html.HtmlRenderer.Builder; |
8 | 8 | import com.vladsch.flexmark.html.HtmlRenderer.HtmlRendererExtension; |
9 | -import com.vladsch.flexmark.html.renderer.LinkResolverContext; | |
10 | -import com.vladsch.flexmark.util.builder.Extension; | |
9 | +import com.vladsch.flexmark.html.renderer.LinkResolverBasicContext; | |
11 | 10 | import com.vladsch.flexmark.util.data.DataKey; |
12 | 11 | import com.vladsch.flexmark.util.data.MutableDataHolder; |
12 | +import com.vladsch.flexmark.util.misc.Extension; | |
13 | 13 | |
14 | 14 | public class RelativeLinkExtension implements HtmlRendererExtension { |
15 | 15 | public static final DataKey<String> RELATIVE_URL_PREFIX = new DataKey<String>("RELATIVE_URL_PREFIX", ""); |
@@ -33,12 +33,12 @@ | ||
33 | 33 | private static class RelativeLinkResolverFactory implements LinkResolverFactory { |
34 | 34 | |
35 | 35 | @Override |
36 | - public Set<Class<? extends LinkResolverFactory>> getAfterDependents() { | |
36 | + public Set<Class<?>> getAfterDependents() { | |
37 | 37 | return null; |
38 | 38 | } |
39 | 39 | |
40 | 40 | @Override |
41 | - public Set<Class<? extends LinkResolverFactory>> getBeforeDependents() { | |
41 | + public Set<Class<?>> getBeforeDependents() { | |
42 | 42 | return null; |
43 | 43 | } |
44 | 44 |
@@ -48,7 +48,7 @@ | ||
48 | 48 | } |
49 | 49 | |
50 | 50 | @Override |
51 | - public LinkResolver apply(LinkResolverContext context) { | |
51 | + public LinkResolver apply(LinkResolverBasicContext context) { | |
52 | 52 | return new RelativeLinkResolver(context); |
53 | 53 | } |
54 | 54 | } |
@@ -1,20 +1,46 @@ | ||
1 | 1 | package net.osdn.catalpa.flexmark.ext; |
2 | 2 | |
3 | 3 | import com.vladsch.flexmark.html.LinkResolver; |
4 | -import com.vladsch.flexmark.html.renderer.LinkResolverContext; | |
4 | +import com.vladsch.flexmark.html.renderer.LinkResolverBasicContext; | |
5 | 5 | import com.vladsch.flexmark.html.renderer.LinkStatus; |
6 | 6 | import com.vladsch.flexmark.html.renderer.ResolvedLink; |
7 | 7 | import com.vladsch.flexmark.util.ast.Node; |
8 | +import com.vladsch.flexmark.util.data.DataHolder; | |
9 | +import com.vladsch.flexmark.util.data.DataValueFactory; | |
8 | 10 | |
9 | 11 | public class RelativeLinkResolver implements LinkResolver { |
10 | - | |
12 | + | |
13 | + private static final DataValueFactory<Object> NULL_VALUE_FACTORY = new DataValueFactory<Object>() { | |
14 | + @Override | |
15 | + public Object apply(DataHolder dataHolder) { | |
16 | + return null; | |
17 | + } | |
18 | + }; | |
19 | + | |
11 | 20 | private String relativeUrlPrefix; |
12 | 21 | |
13 | - public RelativeLinkResolver(LinkResolverContext context) { | |
14 | - relativeUrlPrefix = context.getOptions().get(RelativeLinkExtension.RELATIVE_URL_PREFIX); | |
22 | + public RelativeLinkResolver(LinkResolverBasicContext context) { | |
23 | + relativeUrlPrefix = (String)context.getOptions().getOrCompute(RelativeLinkExtension.RELATIVE_URL_PREFIX, NULL_VALUE_FACTORY); | |
15 | 24 | } |
16 | - | |
25 | + | |
17 | 26 | @Override |
27 | + public ResolvedLink resolveLink(Node node, LinkResolverBasicContext context, ResolvedLink link) { | |
28 | + String url = link.getUrl(); | |
29 | + if(url.length() > 0) { | |
30 | + if(url.charAt(0) == '/' || url.indexOf(":/") != -1 || url.startsWith("data:")) { | |
31 | + return link.withStatus(LinkStatus.VALID).withUrl(url); | |
32 | + } else if(relativeUrlPrefix != null) { | |
33 | + return link.withStatus(LinkStatus.VALID).withUrl(relativeUrlPrefix + url); | |
34 | + } else { | |
35 | + return link.withStatus(LinkStatus.VALID).withUrl(url); | |
36 | + } | |
37 | + } | |
38 | + return link; | |
39 | + } | |
40 | + | |
41 | + | |
42 | + /* | |
43 | + @Override | |
18 | 44 | public ResolvedLink resolveLink(Node node, LinkResolverContext context, ResolvedLink link) { |
19 | 45 | String url = link.getUrl(); |
20 | 46 | if(url.length() > 0) { |
@@ -27,4 +53,5 @@ | ||
27 | 53 | |
28 | 54 | return link; |
29 | 55 | } |
56 | + */ | |
30 | 57 | } |
@@ -4,11 +4,14 @@ | ||
4 | 4 | import java.io.StringWriter; |
5 | 5 | import java.util.Iterator; |
6 | 6 | import java.util.Map; |
7 | +import java.util.Objects; | |
7 | 8 | |
8 | 9 | import com.vladsch.flexmark.html.HtmlRenderer; |
9 | 10 | import com.vladsch.flexmark.parser.Parser; |
10 | 11 | import com.vladsch.flexmark.util.ast.Document; |
11 | 12 | |
13 | +import com.vladsch.flexmark.util.data.DataHolder; | |
14 | +import com.vladsch.flexmark.util.data.DataValueFactory; | |
12 | 15 | import com.vladsch.flexmark.util.data.MutableDataSet; |
13 | 16 | import freemarker.core.Environment; |
14 | 17 | import freemarker.template.TemplateBooleanModel; |
@@ -25,13 +28,21 @@ | ||
25 | 28 | |
26 | 29 | private static final String PARAM_RELATIVE_URL_PREFIX = "relative_url_prefix"; |
27 | 30 | private static final String PARAM_REPLACE_BACKSLASH_TO_YENSIGN = "replace_backslash_to_yensign"; |
28 | - | |
31 | + | |
32 | + private static final DataValueFactory<Object> NULL_VALUE_FACTORY = new DataValueFactory<Object>() { | |
33 | + @Override | |
34 | + public Object apply(DataHolder dataHolder) { | |
35 | + return null; | |
36 | + } | |
37 | + }; | |
38 | + | |
39 | + private MutableDataSet options; | |
29 | 40 | private Parser parser; |
30 | 41 | private HtmlRenderer renderer; |
31 | - | |
42 | + | |
32 | 43 | public MarkdownDirective(MutableDataSet options) { |
33 | - parser = Parser.builder(options).build(); | |
34 | - renderer = HtmlRenderer.builder(options).build(); | |
44 | + this.options = options; | |
45 | + this.parser = Parser.builder(options).build(); | |
35 | 46 | } |
36 | 47 | |
37 | 48 | @Override |
@@ -57,19 +68,29 @@ | ||
57 | 68 | } |
58 | 69 | } |
59 | 70 | |
60 | - MutableDataSet options = null; | |
61 | - if(relativeUrlPrefix != null) { | |
62 | - if(options == null) { | |
63 | - options = new MutableDataSet(); | |
64 | - } | |
65 | - options.set(RelativeLinkExtension.RELATIVE_URL_PREFIX, relativeUrlPrefix); | |
66 | - } | |
67 | - | |
68 | 71 | StringWriter input = new StringWriter(); |
69 | 72 | body.render(input); |
70 | 73 | Document document = parser.parse(input.toString()); |
71 | - String output = renderer.withOptions(options).render(document); | |
74 | + | |
75 | + String previousRelativeUrlPrefix = null; | |
76 | + if(options.contains(RelativeLinkExtension.RELATIVE_URL_PREFIX)) { | |
77 | + previousRelativeUrlPrefix = (String)options.getOrCompute(RelativeLinkExtension.RELATIVE_URL_PREFIX, NULL_VALUE_FACTORY); | |
78 | + } | |
79 | + if(!Objects.equals(relativeUrlPrefix, previousRelativeUrlPrefix)) { | |
80 | + if(options.contains(RelativeLinkExtension.RELATIVE_URL_PREFIX)) { | |
81 | + options.remove(RelativeLinkExtension.RELATIVE_URL_PREFIX); | |
82 | + } | |
83 | + if(relativeUrlPrefix != null) { | |
84 | + options.set(RelativeLinkExtension.RELATIVE_URL_PREFIX, relativeUrlPrefix); | |
85 | + } | |
86 | + renderer = null; | |
87 | + } | |
88 | + if(renderer == null) { | |
89 | + renderer = HtmlRenderer.builder(options).build(); | |
90 | + } | |
91 | + String output = renderer.render(document); | |
72 | 92 | String japaneseTextLayouted = JapaneseTextLayouter.layout(output, isReplaceBackslashToYensign); |
73 | 93 | env.getOut().write(japaneseTextLayouted); |
74 | 94 | } |
95 | + | |
75 | 96 | } |
@@ -35,8 +35,8 @@ | ||
35 | 35 | import java.util.stream.Collectors; |
36 | 36 | import java.util.stream.Stream; |
37 | 37 | |
38 | -import com.vladsch.flexmark.util.builder.Extension; | |
39 | 38 | import com.vladsch.flexmark.util.data.MutableDataSet; |
39 | +import com.vladsch.flexmark.util.misc.Extension; | |
40 | 40 | import org.brotli.wrapper.Brotli; |
41 | 41 | import org.brotli.wrapper.enc.Encoder; |
42 | 42 |