1 package eu.svjatoslav.sixth.core.document.content;
3 import eu.svjatoslav.commons.string.String2;
4 import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
5 import eu.svjatoslav.sixth.core.document.text.FormattedText;
7 import java.util.ArrayList;
10 import static eu.svjatoslav.sixth.core.document.Helper.*;
12 public class ListElement implements Content {
13 public final FormattedText name;
14 public final int indent;
15 public final ListElement parent;
16 private final String type;
17 private final List<Content> content = new ArrayList<>();
18 StringBuilder normalTextAccumulator = new StringBuilder();
20 public ListElement(FormattedText name, int indent, ListElement parent, String type) {
27 public void addContent(Content content) {
28 applyTextAccumulator();
29 this.content.add(content);
32 private void applyTextAccumulator(){
33 if (normalTextAccumulator.length() == 0)
36 content.add(new TextBlock(normalTextAccumulator.toString()));
38 normalTextAccumulator.setLength(0);
41 public void parse(TokenizerMatch tm) {
43 if (tm.isGroup(TG_DOCUMENT_PROPERTY)) {
45 // System.out.println("DOCUMENT PROPERTY!!!: " + tm.token);
49 if (tm.isGroup(TG_DRAWER_PROPERTY)) {
51 // System.out.println("DOCUMENT PROPERTY!!!: " + tm.token);
55 if (tm.isGroup(TG_NORMAL_TEXT)) {
56 normalTextAccumulator.append(tm.token);
60 if (tm.isGroup(TG_MULTILINE_CODE)){
61 // System.out.println(tm.toString());
62 String[] groups = tm.getRegExpGroups();
63 addContent(new MultilineCode(
64 groups[3], // language
70 if (tm.isGroup(TG_VERSE)){
71 String[] groups = tm.getRegExpGroups();
72 addContent(new Verse(groups[5]));
76 System.out.println("ERROR!!!! Unable to handle: " + tm);
80 public void toMD(StringBuilder sb, int indent) {
81 applyTextAccumulator();
83 if (this.indent >= 0) {
84 String2 s = new String2();
85 s.append(" ", indent).append(type).append(" ").append(name.toMD(indent + 2)).append("\n");
86 sb.append(s.toString());
89 for (Content c : content) {
90 c.toMD(sb, this.indent + 2);