ZhgChgLi / ZMarkupParser

ZMarkupParser is a pure-Swift library that helps you convert HTML strings into NSAttributedString with customized styles and tags.
https://zhgchg.li
MIT License
294 stars 23 forks source link

Double line breaks are stripped out #40

Closed danielallsopp closed 8 months ago

danielallsopp commented 10 months ago

In the following HTML example: One<br /><b>Two</b><br /><i>Three</i><br /><i><b>Four</b></i><br /><br />New <b>Paragraph</b>!

should render with a line break after the 'Four' and before the 'New Paragraph' is rendered. However, I've noticed when the HTML string is parsed, the second line break is stripped out, so the render ends up like this:

incorrect

instead of this:

correct

Can this functionality be switched off, or is there a bug present?

EDIT: I've found this function in the source code which seems to the be the culprit:

func reduceBreaklineInResultNSAttributedString(_ attributedString: NSAttributedString) -> NSAttributedString

but I can't find anyway of switching it off, or overriding the functionality.

charrondev commented 9 months ago

@danielallsopp You can see in my recent PR here I added a policy to modify line break behaviour. https://github.com/ZhgChgLi/ZMarkupParser/pull/37

For me I found the behaviour was adding more line breaks that I preferred. Maybe there could be another line break policy added that makes no changes to the built-in line breaks. (call it raw or something like that?).

zhgchgli0718 commented 9 months ago

v1.7.0 fixed and release, thanks to @charrondev

www-r3m1x commented 9 months ago

@zhgchgli0718 This bug not fixed in 1.7.0

zhgchgli0718 commented 8 months ago

image In the latest version 1.8.0, the issues have been addressed. Thank you for your patience.