+ public String toMD () {
+ StringBuilder sb = new StringBuilder();
+
+ if (level > 0) sb.append(enlistTitleInMD());
+
+ // sb.append(unparsedContent);
+
+
+ children.stream().map(Heading::toMD).forEach(sb::append);
+
+ return sb.toString();
+ }
+
+ private String enlistTitleInMD() {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < level; i++)
+ sb.append("#");
+
+ sb.append(" ").append(name.compileMd()).append("\n");
+ return sb.toString();
+ }
+
+ public ListElement createListElement(FormattedText name, int targetLevel){
+ if (currentListElement.level == (targetLevel - 1)){
+ ListElement newListElement = new ListElement(name, targetLevel, currentListElement);
+ currentListElement.addChild(newListElement);
+ currentListElement = newListElement;
+ return newListElement;
+ }
+
+ if (currentListElement.level > (targetLevel - 1)){
+ currentListElement = currentListElement.parent;
+ return createListElement(name, targetLevel);
+ }
+
+ try {
+ ListElement missingIntermediate = new ListElement(
+ fromOrg("<noname>"), currentListElement.level + 1, currentListElement);
+ currentListElement.addChild(missingIntermediate);
+ currentListElement = missingIntermediate;
+ return createListElement(name, targetLevel);
+ } catch (InvalidSyntaxException e) {
+ throw new IllegalStateException("impossible situation");
+ }
+ }
+
+ public ListElement getCurrentHeading(){
+ return currentListElement;
+ }
+
+ public void parse(Tokenizer tokenizer){
+ while (tokenizer.hasMoreContent()) {
+ final TokenizerMatch tm = tokenizer.getNextToken();
+
+ if (tm.isGroup(TG_LIST)){
+ System.out.println("LIST!: " + tm.token);
+ continue;
+ }
+
+ if (tm.isGroup(TG_DOCUMENT_PROPERTY)){
+// System.out.println("DOCUMENT PROPERTY!!!: " + tm.token);
+ continue;
+ }
+
+ if (tm.isGroup(null)){
+// System.out.println(" HC: " + tm.token);
+ continue;
+ }
+
+ tokenizer.unreadToken();
+ break;
+ }
+ }