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