Skip to content

Commit d295da9

Browse files
committed
[Doc] update readme plus class/id content
1 parent 2994760 commit d295da9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,27 @@ To extend the tag name and customize its style, you can use the ExtendTagName cl
275275
let parser = ZHTMLParserBuilder.initWithDefault().add(ExtendTagName("zhgchgli"), withCustomStyle: MarkupStyle(backgroundColor: MarkupStyleColor(name: .aquamarine))).build()
276276
```
277277

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+
278299
### Render HTML String
279300
```swift
280301
parser.render(htmlString) // NSAttributedString

0 commit comments

Comments
 (0)