Skip to content

Commit

Permalink
Add support for SPM
Browse files Browse the repository at this point in the history
  • Loading branch information
flowbe committed Feb 25, 2021
1 parent 83f8143 commit 3b0b7b8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
28 changes: 28 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "DecodeHTML",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "DecodeHTML",
targets: ["DecodeHTML"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "DecodeHTML",
dependencies: []),
.testTarget(
name: "DecodeHTMLTests",
dependencies: ["DecodeHTML"]),
]
)
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
# DecodeHTML.swift
A String extension to decode HTML entities to string
# DecodeHTML

Simply convert HTML to readable strings or attributed string in Swift!

## Installation
Just drag DecodeHTML.swift file to your project (you might want to check "Copy items if needed")

Installation can be done via Swift Package Manager or by dragging Sources/DecodeHTML into your project.
```swift
dependencies: [
.package(url: "https://github.com/flowbe/DecodeHTML.git", .upToNextMajor(from: "1.0.0"))
]
```

## Usage

This extension add 2 properties to String.
This extension add 2 properties to `String`.

### htmlToString
- `htmlToString`:

```
```swift
let myHtmlString = "C’est la France"
println("\(myHtmlString.htmlToString)") // prints "C'est la France"
print("\(myHtmlString.htmlToString)") // prints "C'est la France"
```

### htmlToNSAttributedString
- `htmlToAttributedString`:

```
```swift
let myHtmlString = "C’est la France"
let label = UILabel()
label.attributedText = myHtmlString.htmlToNSAttributedString
```
label.attributedText = myHtmlString.htmlToAttributedString
```
5 changes: 2 additions & 3 deletions DecodeHTML.swift → Sources/DecodeHTML/DecodeHTML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import Foundation

extension String {
var htmlToString: String? {
return htmlToNSAttributedString?.string
return htmlToAttributedString?.string
}

var htmlToNSAttributedString: NSAttributedString? {
var htmlToAttributedString: NSAttributedString? {
if let data = data(using: .utf8) {
return try? NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: Encoding.utf8], documentAttributes: nil)

}
return nil
}
Expand Down

0 comments on commit 3b0b7b8

Please sign in to comment.