Change content at specific TAG before build
chingling123 opened this issue · 10 comments
I need to change the text at a specific tag, like H2 I need that all H2 tag needs to but uppercase.
Let me confirm first, are you requesting to convert the text to uppercase or lowercase? If so, I can consider capitalization as a style feature and extend it to MarkupStyle. This is because capitalization requires modifying the actual text itself, which is not controlled by NSAttributedString Attributes.
Thanks, it's working, I'm using the main branch from swift package. BTW, when I have this html:
heading 2
the H2 custom style not working at all, I can change the color, but font and the new font case is ignored, it's something that I need to do at the code?
could you provide the full code?
I've try:
<h2 style="text-align: justify;"><span style="color: #e67e23;"><span style="color: #0000ff;">heading 2</span></span></h2>
Hello, I tested the following code:
let parser = ZHTMLParserBuilder.initWithDefault().add(H2_HTMLTagName(), withCustomStyle: MarkupStyle(font:MarkupStyleFont(UIFont.boldSystemFont(ofSize: 14)), fontCase: MarkupStyleFont.CaseStyle.uppercase, foregroundColor:MarkupStyleColor.init(color: .yellow))).build()
let textView = UITextView()
textView.frame.size.width = 390
textView.isScrollEnabled = false
textView.backgroundColor = .white
textView.setHtmlString("sss <h2 style=\"text-align: justify;\"><span style=\"color: #e67e23;\"><span style=\"color: #0000ff;\">heading 2</span></span></h2> sss", with: parser)
textView.layoutIfNeeded()
The result is normal.
I suspect that your use of UIFont.bold(14)
as a non-official Foundation UIFont initialization might be causing the issue.
Can you try print(UIFont.bold(14).pointSize)
?
Alternatively, you can directly declare a custom bold font size using MarkupStyleFont(size: 15, weight: .bold).
Thank you!
Printed: FONT: 14.0
FONT: <UICTFont: 0x7fe4180fc820> font-family: "Roboto"; font-weight: bold; font-style: normal; font-size: 14.00pt
It's my custom font