]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/markdown/nodes/ItemNode.java
Markdown to HTML generator has now genration options
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / markdown / nodes / ItemNode.java
1 package org.simantics.scl.compiler.markdown.nodes;
2
3 import org.simantics.scl.compiler.markdown.html.HtmlGenerationContext;
4
5 public class ItemNode extends Node {
6     public int indentation;
7     
8     public ItemNode(int indentation) {
9         this.indentation = indentation;
10     }
11
12     @Override
13     public boolean canContain(Node node) {
14         return true;
15     }
16
17     public void toHtml(HtmlGenerationContext context, StringBuilder b) {
18         toHtml(context, b, true);
19     }
20     
21     public void toHtml(HtmlGenerationContext context, StringBuilder b, boolean tight) {
22         if(firstChild == null) {
23             b.append("<li></li>\n");
24             return;
25         }
26         else if(tight) {
27             b.append("<li>");
28             // This code assumes that there are no consecutive paragraphs
29             boolean noNewline = true;
30             for(Node child = firstChild; child != null; child = child.next) {
31                 if(child instanceof ParagraphNode) {
32                     for(Node n=child.firstChild;n!=null;n=n.next)
33                         n.toHtml(context, b);
34                     noNewline = true;
35                 }
36                 else {
37                     if(noNewline) {
38                         b.append('\n');
39                         noNewline = false;
40                     }
41                     child.toHtml(context, b);
42                 }
43             }
44             b.append("</li>\n");
45         }
46         else {
47             b.append("<li>\n");
48             super.toHtml(context, b);
49             b.append("</li>\n");
50         }
51     }
52 }