FormattedText title = FormattedText.fromOrg(parseFullListTitle(getPartialTitle(listSections), tm.getTokenizer(), indent));
if (indent > currentListElement.indent){
+ // list dept increases
ListElement newElement = new ListElement(title, indent, currentListElement, type);
currentListElement.addContent(newElement);
currentListElement = newElement;
}
if (indent == currentListElement.indent){
+ // list depth is the same
ListElement newElement = new ListElement(title, indent, currentListElement.parent, type);
currentListElement.parent.addContent(newElement);
currentListElement = newElement;
return;
}
+ // list dept decreases
while (true){
if (currentListElement.parent.indent <= indent){
- ListElement newElement = new ListElement(title, indent, currentListElement.parent, type);
- currentListElement.parent.addContent(newElement);
+ if (currentListElement.parent.indent < 0){
+ // reached first depth level, cannot go any deeper.
+ // This special situation arisesbb only when lint indents are not properly aligned.
+ // That is, document structure is incorrect.
+ ListElement newElement = new ListElement(title, indent, currentListElement.parent, type);
+ currentListElement.parent.addContent(newElement);
+ currentListElement = newElement;
+ return;
+ }
+
+ ListElement newElement = new ListElement(title, indent, currentListElement.parent.parent, type);
+ currentListElement.parent.parent.addContent(newElement);
currentListElement = newElement;
return;
}