Fixes #4683 - Add support for nested lists

This commit is contained in:
Stefan Ceriu
2025-11-12 10:41:53 +02:00
committed by Stefan Ceriu
parent cbe0cfe129
commit 14f8e9c1df
2 changed files with 67 additions and 6 deletions
@@ -236,19 +236,25 @@ struct AttributedStringBuilder: AttributedStringBuilderProtocol {
}
content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: tag, listIndex: &listIndex, indentLevel: indentLevel + 1)
if indentLevel > 0 {
content.insert(NSAttributedString("\n"), at: 0)
}
case "li":
var bullet = ""
var bullet = String(repeating: " ", count: indentLevel)
if listTag == "ol" {
bullet = "\(listIndex). "
bullet += "\(listIndex). "
listIndex += 1
} else {
bullet = "• "
bullet += "• "
}
content = attributedString(element: childElement, documentBody: documentBody, preserveFormatting: preserveFormatting, listTag: listTag, listIndex: &childIndex, indentLevel: indentLevel + 1)
content.insert(NSAttributedString(string: bullet), at: 0)
content.append(NSAttributedString(string: "\n"))
if !(content.string.last?.isNewline ?? false) {
content.append(NSAttributedString(string: "\n"))
}
case "img":
if let alt = try? childElement.attr("alt"), !alt.isEmpty {