+++ /dev/null
-package eu.svjatoslav.sixth.core.document.content;
-
-import eu.svjatoslav.commons.string.String2;
-import eu.svjatoslav.commons.string.tokenizer.TokenizerMatch;
-import eu.svjatoslav.sixth.core.document.text.FormattedText;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static eu.svjatoslav.sixth.core.document.Helper.*;
-
-public class ListElement implements Content {
- public final FormattedText name;
- public final int indent;
- public final ListElement parent;
- private final String type;
- private final List<Content> content = new ArrayList<>();
- StringBuilder normalTextAccumulator = new StringBuilder();
-
- public ListElement(FormattedText name, int indent, ListElement parent, String type) {
- this.indent = indent;
- this.name = name;
- this.type = type;
- this.parent = parent;
- }
-
- public void addContent(Content content) {
- applyTextAccumulator();
- this.content.add(content);
- }
-
- private void applyTextAccumulator(){
- if (normalTextAccumulator.length() == 0)
- return;
-
- content.add(new TextBlock(normalTextAccumulator.toString()));
-
- normalTextAccumulator.setLength(0);
- }
-
- public void parse(TokenizerMatch tm) {
-
- if (tm.isGroup(TG_DOCUMENT_PROPERTY)) {
- // TODO
- // System.out.println("DOCUMENT PROPERTY!!!: " + tm.token);
- return;
- }
-
- if (tm.isGroup(TG_DRAWER_PROPERTY)) {
- // TODO
- // System.out.println("DOCUMENT PROPERTY!!!: " + tm.token);
- return;
- }
-
- if (tm.isGroup(TG_NORMAL_TEXT)) {
- normalTextAccumulator.append(tm.token);
- return;
- }
-
- if (tm.isGroup(TG_MULTILINE_CODE)){
- // System.out.println(tm.toString());
- String[] groups = tm.getRegExpGroups();
- addContent(new MultilineCode(
- groups[3], // language
- groups[5] // code
- ));
- return;
- }
-
- if (tm.isGroup(TG_VERSE)){
- String[] groups = tm.getRegExpGroups();
- addContent(new Verse(groups[5]));
- return;
- }
-
- System.out.println("ERROR!!!! Unable to handle: " + tm);
- }
-
-
- public void toMD(StringBuilder sb, int indent) {
- applyTextAccumulator();
-
- if (this.indent >= 0) {
- String2 s = new String2();
- s.append(" ", indent).append(type).append(" ").append(name.toMD(indent + 2)).append("\n");
- sb.append(s.toString());
- }
-
- for (Content c : content) {
- c.toMD(sb, this.indent + 2);
- }
- }
-}