SwiftRichString icon indicating copy to clipboard operation
SwiftRichString copied to clipboard

Parsing Html List Items

Open AmirHossein1372 opened this issue 5 years ago • 1 comments

Hi, I'm trying to parse an html text in a way that each list item (<li> tag) begins at the new line.

I've tried:

let text = "<ul><li>First</li><li>Second</li><li>Third</li></ul>" let style = Style { $0.color = UIColor.black } let liStyle = Style { $0.color = UIColor.green } let htmlStyle = StyleXML(base: style, ["li": liStyle]) label.attributedText = text.set(style: htmlStyle)

And the output is: Screen Shot 2020-02-10 at 23 10 10 Is there any way to style them like: Screen Shot 2020-02-10 at 23 20 21

Thanks, best wishes.

AmirHossein1372 avatar Feb 10 '20 19:02 AmirHossein1372

you could use .textTransforms to do something like

let liStyle = Style {
   ...
   $0.textTransforms = [
       .custom { "\n• " + $0 },
   ]
}

In general, I do think it would be nice to have access to some defaults or out-of-the-box configuration for handling stuff like <li> and <p> tags, which I'm currently wrestling with.

marcusway avatar Jul 25 '20 20:07 marcusway