1 package org.simantics.scl.compiler.markdown.nodes;
3 import java.util.ArrayList;
6 import org.simantics.scl.compiler.markdown.html.HtmlGenerationContext;
7 import org.simantics.scl.compiler.markdown.internal.ExtensionNodeHandler;
8 import org.simantics.scl.compiler.markdown.internal.MarkdownParser;
11 public abstract class Node {
15 public Node firstChild;
16 public Node lastChild;
17 public boolean open = true;
18 public boolean lastLineBlank = false;
19 public StringBuilder stringContent;
20 public int lineNumber;
22 public void setLastLineBlank(boolean value) {
23 if(MarkdownParser.DEBUG)
24 System.out.println(" " + getClass().getSimpleName() + "@" + hashCode() + " lastLineBlank: " +
25 lastLineBlank + " -> " + value);
26 this.lastLineBlank = value;
29 public boolean canContain(Node node) {
33 public boolean acceptLines() {
37 public void toHtml(HtmlGenerationContext context, StringBuilder b) {
38 for(Node child = firstChild; child != null; child = child.next)
39 child.toHtml(context, b);
42 public List<HeaderNode> extractHeaders() {
43 ArrayList<HeaderNode> result = new ArrayList<HeaderNode>();
44 for(Node child = firstChild; child != null; child = child.next)
45 if(child instanceof HeaderNode)
46 result.add((HeaderNode)child);
50 public String toHtml(HtmlGenerationContext context) {
51 StringBuilder b = new StringBuilder();
54 if(len > 0 && b.charAt(len-1) == '\n')
59 public void toPlainText(StringBuilder b) {
60 for(Node child = firstChild; child != null; child = child.next)
64 public void remove() {
66 parent.firstChild = next;
70 parent.lastChild = prev;
75 public void processExtensionNodes(ExtensionNodeHandler handler) {
76 for(Node child = firstChild; child != null; child = child.next)
77 child.processExtensionNodes(handler);
80 public void addChild(Node child) {
85 lastChild.next = child;
86 child.prev = lastChild;