リビジョン | 86 (tree) |
---|---|
日時 | 2019-01-28 19:39:07 |
作者 | ![]() |
* flexmark-ext-text-layout-ja 0.1.5 imgのみを含むパラグラフ(p)にclass属性images-onlyを付加するようにしました。
@@ -3,7 +3,10 @@ | ||
3 | 3 | import java.util.HashSet; |
4 | 4 | import java.util.Set; |
5 | 5 | |
6 | +import com.vladsch.flexmark.ast.HardLineBreak; | |
7 | +import com.vladsch.flexmark.ast.Image; | |
6 | 8 | import com.vladsch.flexmark.ast.Paragraph; |
9 | +import com.vladsch.flexmark.ast.SoftLineBreak; | |
7 | 10 | import com.vladsch.flexmark.html.CustomNodeRenderer; |
8 | 11 | import com.vladsch.flexmark.html.HtmlWriter; |
9 | 12 | import com.vladsch.flexmark.html.renderer.JapaneseTextLayoutAccessor; |
@@ -11,6 +14,7 @@ | ||
11 | 14 | import com.vladsch.flexmark.html.renderer.NodeRendererContext; |
12 | 15 | import com.vladsch.flexmark.html.renderer.NodeRenderingHandler; |
13 | 16 | import com.vladsch.flexmark.html.renderer.TextCollectingAppendable; |
17 | +import com.vladsch.flexmark.util.ast.Node; | |
14 | 18 | import com.vladsch.flexmark.util.options.DataHolder; |
15 | 19 | |
16 | 20 | import net.osdn.blogs.flexmark.ext.text_layout_ja.core.Processor; |
@@ -39,9 +43,28 @@ | ||
39 | 43 | TextCollectingAppendable out = new TextCollectingAppendable(); |
40 | 44 | NodeRendererContext subContext = context.getSubContext(out, true); |
41 | 45 | |
42 | - coreNodeRenderer.render(node, subContext, subContext.getHtmlWriter()); | |
46 | + HtmlWriter subHtml = subContext.getHtmlWriter(); | |
47 | + | |
48 | + boolean isImageOnly = true; | |
49 | + for(Node child : node.getChildren()) { | |
50 | + if(child instanceof Image) { | |
51 | + continue; | |
52 | + } | |
53 | + if(child instanceof SoftLineBreak) { | |
54 | + continue; | |
55 | + } | |
56 | + if(child instanceof HardLineBreak) { | |
57 | + continue; | |
58 | + } | |
59 | + isImageOnly = false; | |
60 | + } | |
61 | + if(isImageOnly) { | |
62 | + subHtml.attr("class", "images-only"); | |
63 | + } | |
64 | + | |
65 | + coreNodeRenderer.render(node, subContext, subHtml); | |
43 | 66 | html.append(Processor.layout(out.getHtml())); |
44 | - | |
67 | + | |
45 | 68 | /* |
46 | 69 | if (node.getFirstChildAnyNot(NonRenderingInline.class) != null) { |
47 | 70 | if (!(node.getParent() instanceof ParagraphItemContainer) |