File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -275,6 +275,27 @@ To extend the tag name and customize its style, you can use the ExtendTagName cl
275
275
let parser = ZHTMLParserBuilder.initWithDefault ().add (ExtendTagName (" zhgchgli" ), withCustomStyle : MarkupStyle (backgroundColor : MarkupStyleColor (name : .aquamarine ))).build ()
276
276
```
277
277
278
+ ####Support for Class/ ID Style Mapping and Parsing
279
+
280
+ The class HTML attribute can use the HTMLTagClassAttribute to define classNames with pre- defined styles.
281
+
282
+ HTML allows specifying multiple `class` attributes separated by spaces, but the `id` attribute can only be assigned a single value per HTML tag.
283
+
284
+ e.g.:
285
+ ```
286
+ < span id= " header" > hey</ span> hey < span id= " text-red text-small" > Teste de texto text small</ span> hey< span class= " text-red" > hey</ span> heyhey
287
+ ```
288
+
289
+ ```
290
+ let parser = ZHTMLParserBuilder.initWithDefault ().add (HTMLTagClassAttribute (className : " text-red" , render : {
291
+ return MarkupStyle (foregroundColor : MarkupStyleColor (color : .red ))
292
+ })).add (HTMLTagClassAttribute (className : " text-small" , render : {
293
+ return MarkupStyle (font : MarkupStyleFont (.systemFont (ofSize : 6 )))
294
+ })).add (HTMLTagIdAttribute (idName : " header" , render : {
295
+ return MarkupStyle (font : MarkupStyleFont (.systemFont (ofSize : 36 )))
296
+ })).build ()
297
+ ```
298
+
278
299
### Render HTML String
279
300
```swift
280
301
parser.render (htmlString) // NSAttributedString
You can’t perform that action at this time.
0 commit comments