You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pure Swift HTML character escape utility tool for Swift 3.0.
9
+
Pure Swift HTML encode/decode utility tool for Swift 3.0.
10
10
11
-
Currently includes support for HTML4 named character references. You can find the list of all 252 HTML4 named character references [here](https://www.w3.org/TR/html4/sgml/entities.html).
11
+
Now includes support for HTML5 named character references. You can find the list of all 2231 HTML5 named character references [here](https://www.w3.org/TR/html5/syntax.html#named-character-references).
12
12
13
-
`HTMLEntities`escapes ALL non-ASCII characters, as well as the characters `<`, `>`, `&`, `”`, `’` as these five characters are part of the HTML tag and HTML attribute syntaxes.
13
+
`HTMLEntities`can escape ALL non-ASCII characters and ASCII non-print character (i.e. NUL, ESC, DEL), as well as the characters `<`, `>`, `&`, `"`, `’` as these five characters are part of the HTML tag and HTML attribute syntaxes.
14
14
15
-
In addition, `HTMLEntities` can unescape encoded HTML text that contains decimal, hexadecimal, or HTML4 named character reference escapes.
15
+
In addition, `HTMLEntities` can unescape encoded HTML text that contains decimal, hexadecimal, or HTML5 named character references.
16
16
17
17
## Features
18
18
19
-
* Supports HTML4 named character references (`nbsp`, `cent`, etc.)
19
+
* Supports HTML5 named character references (`NegativeMediumSpace;` etc.)
// Prints ”<script>alert("abc")</script>"
53
+
// Prints "<script>alert("abc")</script>"
38
54
39
55
// decode example
40
56
let htmlencoded ="<script>alert("abc")</script>"
41
57
42
58
print(htmlencoded.htmlUnescape())
43
-
// Prints ”<script>alert(\"abc\")</script>"
59
+
// Prints "<script>alert(\"abc\")</script>"
44
60
```
45
61
46
62
## Advanced Options
@@ -56,18 +72,18 @@ Defaults to `false`. Specifies if decimal character escapes should be used inste
56
72
```swift
57
73
importHTMLEntities
58
74
59
-
let text ="한, 한, é, é, 🇺🇸"
75
+
let text ="한, 한, ế, ế, 🇺🇸"
60
76
61
77
print(text.htmlEscape())
62
-
// Prints “한, 한, é, é, 🇺🇸”
78
+
// Prints "한, 한, ế, ế, 🇺🇸"
63
79
64
80
print(text.htmlEscape(decimal: true))
65
-
// Prints “한, 한, é, é, 🇺🇸”
81
+
// Prints "한, 한, ế, ế, 🇺🇸"
66
82
```
67
83
68
84
#### `useNamedReferences`
69
85
70
-
Defaults to `true`. Specifies if named character references should be used whenever possible. Set to `false` to always use numeric character escape, i.e., for compatibility with older browsers that do not recognize named character references.
86
+
Defaults to `true`. Specifies if named character references should be used whenever possible. Set to `false` to always use numeric character references, i.e., for compatibility with older browsers that do not recognize named character references.
71
87
72
88
```swift
73
89
importHTMLEntities
@@ -77,15 +93,15 @@ let html = "<script>alert(\"abc\")</script>"
77
93
print(html.htmlEscape())
78
94
// Prints “<script>alert("abc")</script>”
// Prints “<script>alert("abc")</script>”
82
98
```
83
99
84
100
### Unescape Options
85
101
86
102
#### `strict`
87
103
88
-
Defaults to `true`. Specifies if HTML numeric character escapes MUST always end with `;`. Some browsers allow numeric character escapes (i.e., decimal and hexadecimal types) to end without `;`. Always ending character escapes with `;` is recommended; however, for compatibility reasons, `HTMLEntities` allows non-strict ending option for situations that require it.
104
+
Defaults to `false`. Specifies if HTML5 parse errors should be thrown or simply passed over. **NOTE**: `htmlUnescape()` is a throwing function if `strict` is used in call argument (no matter if it is set to `true` or `false`); `htmlUnescape()` is NOT a throwing function if no argument is provided.
89
105
90
106
```swift
91
107
importHTMLEntities
@@ -95,10 +111,10 @@ let text = "한"
0 commit comments