Skip to content

Commit

Permalink
Merge pull request #65 from ZhgChgLi/fix/harry/list-item-and-stripper…
Browse files Browse the repository at this point in the history
…-bug-fix

Fix/harry/list item and stripper bug fix
  • Loading branch information
zhgchgli0718 authored May 29, 2024
2 parents ba02833 + 39531f5 commit b8086ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,20 @@ struct HTMLElementMarkupComponentMarkupStyleVisitor: MarkupVisitor {
let indent = (style.font.size ?? 16) * markup.styleList.indentMultiply
let dotIndent: CGFloat = (markup.styleList.type.isOrder()) ? (indent) : (0) // for 1. -> "."

// Find Parent Indent if exists.
var parentIndent: CGFloat = 0
var parentMarkup: Markup? = markup.parentMarkup
while (parentMarkup != nil) {
if let thisParentMarkup = parentMarkup as? ListMarkup {
parentIndent += visit(markup: thisParentMarkup)?.paragraphStyle.headIndent ?? 0
parentIndent = visit(markup: thisParentMarkup)?.paragraphStyle.headIndent ?? 0
break
}
parentMarkup = parentMarkup?.parentMarkup
}

var tabStops: [NSTextTab] = [.init(textAlignment: .left, location: headIndent + parentIndent)]
tabStops.append(.init(textAlignment: .left, location: headIndent + parentIndent + dotIndent + indent))


style.paragraphStyle.tabStops = style.paragraphStyle.tabStops ?? tabStops
style.paragraphStyle.headIndent = style.paragraphStyle.headIndent ?? style.paragraphStyle.tabStops?.last?.location
return style
Expand Down
7 changes: 4 additions & 3 deletions Sources/ZMarkupParser/HTML/ZHTMLParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ public final class ZHTMLParser {
}

public func stripper(_ attributedString: NSAttributedString) -> NSAttributedString {
let items = process(attributedString)
let stripedAttributedString = decodeHTMLEntities(attributedString)
let items = process(stripedAttributedString)
let reuslt = htmlParsedResultToHTMLElementWithRootMarkupProcessor.process(from: items)
let attributedString = markupStripperProcessor.process(from: reuslt.markup)
let resultAttributedString = markupStripperProcessor.process(from: reuslt.markup)

return attributedString
return resultAttributedString
}

//
Expand Down

0 comments on commit b8086ba

Please sign in to comment.