Skip to content

carabina/HTMLString

 
 

Repository files navigation

import HTMLString

Build Status Swift 3.0 CocoaPods The MIT License

HTMLString is a micro-library written in Swift that enables your app to deal with Strings that contain HTML.

Features

  • ASCII and Unicode Escaping
  • Unescaping
  • Support of 2125 named escape sequences (&) as well as decimal (€) and hexadecimal (🙃) sequences

Supports

  • iOS 8.0
  • macOS 10.10
  • watchOS 2.0
  • tvOS 9.0
  • Linux

Installation

CocoaPods

Add this line to your Podfile:

pod 'HTMLString' '~> 1.0.1'

Swift Package Manager

Add this line to your Package.swift :

.Package(url: "https://github.com/alexaubry/HTMLString", majorVersion: 1, minor: 0)

Manual

Add the HTMLString.swift and Mappings.swift files to your project.

Usage

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 pages
  • unescapingFromHTML : Replaces all escape sequences in the String by their corresponding Unicode Scalar.

Escaping

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"

Unescaping

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"

Acknowledgements

This library was inspired by Google's GTMNSString+HTML.

About

Deal with Strings that contain HTML in Swift

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Swift 99.1%
  • Ruby 0.9%