AttributedText is a view for displaying some HTML-tagged text using SwiftUI Text View.
A simple example of usage.
Code example:
AttributedText("A unit of <i>length</i> equal to <b>one hundred-millionth of a centimetre</b>, 10<sup>−10</sup> metre, used mainly to express <u>wavelengths and interatomic distances</u>.")
Result:
Features
You can clone the repo and run the AttributedTextExample project to explore the AttributedText features.
These are the main points to pay attention to.
You can define the tags you need or use the defaults.
You need to set the required tags and provide associated closures. Each closure must be a modifier that is applied to the SwiftUI Text View when a specific tag is encountered.
Override the default values, for example at application launch.
AttributedText
AttributedText is a view for displaying some HTML-tagged text using SwiftUI Text View.
A simple example of usage.
Code example:
Result:
Features
You can clone the repo and run the AttributedTextExample project to explore the
AttributedText
features.These are the main points to pay attention to.
You can define the tags you need or use the defaults.
You need to set the required tags and provide associated closures. Each closure must be a modifier that is applied to the SwiftUI Text View when a specific tag is encountered.
Override the default values, for example at application launch.
In this case only <b> and <i> tags will be processed. All other tags will be ignored or deleted.
Set the custom values for each instance.
Basic modifiers can still be applied, such as changing the font and color of the text.
Code example:
Result:
Handles unopened/unclosed tags.
Code example:
Result:
Supports overlapping tags.
Code example:
Result:
Deletes tags that have no modifiers.
Code example:
Result:
Does not handle HTML characters such as
&
.Code example:
Result:
Only single-word tags are supported. Tags with more than one word or containing any characters besides letters or numbers are ignored and not removed.
Code example:
Result:
Installation and usage
Via Swift Package Manager
File ▸ Swift Packages ▸ Add Package Dependency
.Manually