a82fd53395394ef017afae9146cb881b62f5efc6
[sixth.git] / src / main / java / eu / svjatoslav / sixth / core / document / content / ListElement.java
1 package eu.svjatoslav.sixth.core.document.content;
2
3 import eu.svjatoslav.commons.string.String2;
4 import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
5 import eu.svjatoslav.sixth.core.document.text.FormattedText;
6
7 import java.util.ArrayList;
8 import java.util.List;
9
10 import static eu.svjatoslav.sixth.core.document.Helper.TG_DOCUMENT_PROPERTY;
11 import static eu.svjatoslav.sixth.core.document.Helper.TG_NORMAL_TEXT;
12
13 public class ListElement implements Content {
14     public final FormattedText name;
15     public final int indent;
16     public final ListElement parent;
17     private final String type;
18     private final List<Content> content = new ArrayList<>();
19
20     public ListElement(FormattedText name, int indent, ListElement parent, String type) {
21         this.indent = indent;
22         this.name = name;
23         this.type = type;
24         this.parent = parent;
25     }
26
27     public void addContent(ListElement content) {
28         this.content.add(content);
29     }
30
31     public void parse(TokenizerMatch tm) {
32
33         if (tm.isGroup(TG_DOCUMENT_PROPERTY)) {
34 //            System.out.println("DOCUMENT PROPERT!!!: " + tm.token);
35             return;
36         }
37
38         if (tm.isGroup(TG_NORMAL_TEXT)) {
39 //            System.out.println("  Plain text content: " + tm.token);
40             return;
41         }
42
43         System.out.println("ERROR!!!! Unable to handle: " + tm);
44     }
45
46
47     public void toMD(StringBuilder sb, int indent) {
48         if (this.indent >= 0) {
49             String2 s = new String2();
50             s.append(" ", indent).append(type).append(" ").append(name.toMD(indent + 2)).append("\n");
51             sb.append(s.toString());
52         }
53
54         for (Content c : content) {
55             c.toMD(sb, this.indent + 2);
56         }
57     }
58 }