HTMLString is a micro-library written in Swift that enables your app to deal with Strings that contain HTML.
- ASCII and Unicode Escaping
- Unescaping
- Support of 2125 named escape sequences (
&) as well as decimal (€) and hexadecimal (🙃) sequences
- iOS 8.0
- macOS 10.10
- watchOS 2.0
- tvOS 9.0
- Linux
Add this line to your Podfile:
pod 'HTMLString' '~> 1.0.1'
Add this line to your Package.swift :
.Package(url: "https://github.com/alexaubry/HTMLString", majorVersion: 1, minor: 0)Add the HTMLString.swift and Mappings.swift files to your project.
This library adds three properties to String instances :
escapingForUnicodeHTML: Escapes the characters in the String for display in Unicode-encoded HTML pages.escapingForASCIIHTML: Escapes the characters in the String for display in ASCII-encoded HTML pagesunescapingFromHTML: Replaces all escape sequences in the String by their corresponding Unicode Scalar.
import HTMLString
let emoji = "My favorite emoji is 🙃"
let escapedEmoji = emoji.escapingForASCIIHTML // "My favorite emoji is 🙃"
let snack = "Fish & Chips"
let escapedSnack = snack.escapingForUnicodeHTML // "Fish & Chips"import HTMLString
let escapedEmoji = "My favorite emoji is 🙃"
let emoji = escapedEmoji.unescapingFromHTML // "My favorite emoji is 🙃"
let escapedSnack = "Fish & Chips"
let snack = escapedSnack.unescapingFromHTML // "Fish & Chips"This library was inspired by Google's GTMNSString+HTML.