Skip to content

Commit ad4dc3c

Browse files
committed
Fix nested list repelling for cases when they are buried deeper within other blocks
1 parent 019b983 commit ad4dc3c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecParser.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ class AztecParser(val plugins: List<IAztecPlugin> = ArrayList()) {
133133
val parent = IAztecNestable.getParent(spanned, SpanWrapper(spanned, it))
134134

135135
// a list item "repels" a child list so the list will appear in the next line
136-
val repelling = it is AztecListSpan && parent?.span is AztecListItemSpan
136+
val parentListItem = spanned.getSpans(spanned.getSpanStart(it), spanned.getSpanEnd(it), AztecListItemSpan::class.java)
137+
.filter { item -> item.nestingLevel < it.nestingLevel }
138+
.sortedBy { item -> item.nestingLevel }
139+
.firstOrNull()
140+
val repelling = it is AztecListSpan && parentListItem != null
137141

138142
val spanStart = spanned.getSpanStart(it)
139143
val spanEnd = spanned.getSpanEnd(it)
@@ -160,6 +164,10 @@ class AztecParser(val plugins: List<IAztecPlugin> = ArrayList()) {
160164
return@forEach
161165
}
162166

167+
if (repelling && spanStart > 0 && spanned[spanStart - 1] == '\n' && spanStart - 1 >= spanned.getSpanStart(parentListItem)) {
168+
return@forEach
169+
}
170+
163171
// well, it seems we need a visual newline so, add one and mark it as such
164172
spanned.insert(spanStart, "\n")
165173

0 commit comments

Comments
 (0)