Skip to content

thirdiron/StringExtensionHTML

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StringExtensionHTML

CI Status Version License Platform

Usage

This string extension provides two main methods, stringByDecodingHTMLEntities and stringByStrippingHTMLTags.

import StringExtensionHTML

var text = ""some html string with entities ""
let decodedText = text.stringByDecodingHTMLEntities

var text = "<span><p>Some text full of <i>unwanted</i> html tags</p></span>
let decodedText = text.stringByStrippingHTMLTags

Sample Project

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

StringExtensionHTML is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "StringExtensionHTML"

Alternatively, copy StringExtensionHTML.swift and add that single file into your Swift project. If you use this method, you can omit the line "import StringExtensionHTML" at the top of your file.

Credits

Original solution and former adaptations credit to Michael Waterfall and Martin from the Stack Overflow thread How do I decode HTML entities in swift?. I upgraded to work with Swift 2.0 and made it available through CocoaPods.

Note: there is a Swift 2 version by Santiago in the original thread's comments. However, while that version will compile, it will not handle numeric character entities properly and also has some flaws which will cause it to crash anytime it comes to an entity it doesn't understand.

Author

Adela Chang, [email protected]

License

StringExtensionHTML is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 47.5%
  • Shell 44.3%
  • Ruby 5.5%
  • Objective-C 2.7%