forked from alexaubry/HTMLString
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
229 lines (201 loc) · 13.8 KB
/
Copy pathindex.html
File metadata and controls
229 lines (201 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<!DOCTYPE html>
<html lang="en">
<head>
<title>HTMLString Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
</head>
<body>
<a title="HTMLString Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">HTMLString Docs</a> (100% documented)</p>
<p class="header-right"><a href="https://github.com/alexaubry/HTMLString"><img src="img/gh.png"/>View on GitHub</a></p>
<p class="header-right"><a href="dash-feed://https%3A%2F%2Falexaubry%2Egithub%2Eio%2Fdocsets%2FHTMLString%2Exml"><img src="img/dash.png"/>Install in Dash</a></p>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html">HTMLString Reference</a>
<img id="carat" src="img/carat.png" />
HTMLString Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Extensions.html">Extensions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Extensions/String.html">String</a>
</li>
<li class="nav-group-task">
<a href="Extensions/UnicodeScalar.html">UnicodeScalar</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<p align="center">
<img src="https://github.com/alexaubry/HTMLString/raw/master/logo.png" alt="HTMLString" />
<a>
<img src="https://img.shields.io/badge/Swift-3.0.2-ee4f37.svg" alt="Swift 3.0.2" />
</a>
<a href="https://travis-ci.org/alexaubry/HTMLString">
<img src="https://travis-ci.org/alexaubry/HTMLString.svg?branch=master" alt="Build Status" />
</a>
<a href="https://cocoapods.org/pods/HTMLString">
<img src="https://img.shields.io/cocoapods/v/HTMLString.svg" alt="CocoaPods" />
</a>
<a href="https://github.com/Carthage/Carthage">
<img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat" alt="Carthage compatible" />
</a>
<a href="https://codecov.io/gh/alexaubry/HTMLString">
<img src="https://codecov.io/gh/alexaubry/HTMLString/branch/master/graph/badge.svg" alt="Code coverage" />
</a>
<a href="https://twitter.com/leksantoine">
<img src="https://img.shields.io/badge/Twitter-%40leksantoine-6C7A89.svg" alt="Twitter : @leksantoine" />
</a>
</p>
<p><code>HTMLString</code> is a library written in Swift that enables your app to escape and unescape HTML entities in Strings.</p>
<table><thead>
<tr>
<th></th>
<th>Main features</th>
</tr>
</thead><tbody>
<tr>
<td>🔏</td>
<td>Adds entities for ASCII and UTF-8/UTF-16 encodings</td>
</tr>
<tr>
<td>📝</td>
<td>Removes more than 2100 named entities (like <code>&amp;</code>)</td>
</tr>
<tr>
<td>🔢</td>
<td>Supports removing decimal and hexadecimal entities</td>
</tr>
<tr>
<td>🐣</td>
<td>Designed to support Swift Extended Grapheme Clusters (→ 100% emoji-proof)</td>
</tr>
<tr>
<td>✅</td>
<td>Fully unit tested</td>
</tr>
<tr>
<td>⚡</td>
<td>Fast</td>
</tr>
<tr>
<td>📚</td>
<td><a href="https://alexaubry.github.io/HTMLString/">100% documented</a></td>
</tr>
<tr>
<td>🤖</td>
<td><a href="https://github.com/alexaubry/HTMLString/tree/master/README.md#objective%2Dc-api">Compatible with Objective-C</a></td>
</tr>
</tbody></table>
<a href='#supported-platforms' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='supported-platforms'>Supported Platforms</h2>
<ul>
<li>iOS 8.0+</li>
<li>macOS 10.10+</li>
<li>tvOS 9.0+</li>
<li>watchOS 2.0+</li>
<li>Linux</li>
</ul>
<a href='#installation' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='installation'>Installation</h2>
<a href='#swift-package-manager' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='swift-package-manager'>Swift Package Manager</h3>
<p>Add this line to your <code>Package.swift</code> :</p>
<pre class="highlight swift"><code><span class="o">.</span><span class="kt">Package</span><span class="p">(</span><span class="nv">url</span><span class="p">:</span> <span class="s">"https://github.com/alexaubry/HTMLString"</span><span class="p">,</span> <span class="nv">majorVersion</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="nv">minor</span><span class="p">:</span> <span class="mi">0</span><span class="p">)</span>
</code></pre>
<a href='#cocoapods' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='cocoapods'>CocoaPods</h3>
<p>Add this line to your <code>Podfile</code>:</p>
<pre class="highlight plaintext"><code>pod 'HTMLString'
</code></pre>
<a href='#carthage' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='carthage'>Carthage</h3>
<p>Add this line to your Cartfile:</p>
<pre class="highlight plaintext"><code>github "alexaurby/HTMLString"
</code></pre>
<a href='#manual' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='manual'>Manual</h3>
<p>Copy the <code>Sources/HTMLString/</code> directory into your project.</p>
<a href='#usage' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='usage'>Usage</h2>
<p><code>HTMLString</code> allows you to add and remove HTML entities from a String.</p>
<a href='#128271-add-html-entities-escape' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='128271-add-html-entities-escape'>🔏 Add HTML Entities (Escape)</h3>
<p>When a character is not supported into the specified encoding, the library replaces it with a decimal entitiy, such as <code>&#038;</code> <=> <code>&</code> (compatible with HTML 4+). </p>
<p>You can choose between ASCII and Unicode escaping. </p>
<blockquote>
<p>💡 <strong>Pro Tip</strong>: When your content supports UTF-8 or UTF-16, use Unicode escaping as it is faster and yields a less bloated output.</p>
</blockquote>
<a href='#docs' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='docs'>Docs</h4>
<ul>
<li><a href="https://alexaubry.github.io/HTMLString/Extensions/String.html#/s:vE10HTMLStringSS21addingUnicodeEntitiesSS"><code>addingUnicodeEntities</code></a></li>
<li><a href="https://alexaubry.github.io/HTMLString/Extensions/String.html#/s:vE10HTMLStringSS19addingASCIIEntitiesSS"><code>addingASCIIEntities</code></a></li>
</ul>
<a href='#example' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='example'>Example</h4>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">HTMLString</span>
<span class="k">let</span> <span class="nv">emoji</span> <span class="o">=</span> <span class="s">"My favorite emoji is 🙃"</span>
<span class="k">let</span> <span class="nv">escapedEmoji</span> <span class="o">=</span> <span class="n">emoji</span><span class="o">.</span><span class="n">addingASCIIEntities</span> <span class="c1">// "My favorite emoji is &#128579;"</span>
<span class="k">let</span> <span class="nv">noNeedToEscapeThatEmoji</span> <span class="o">=</span> <span class="n">emoji</span><span class="o">.</span><span class="n">addingUnicodeEntities</span> <span class="c1">// "My favorite emoji is 🙃"</span>
<span class="k">let</span> <span class="nv">snack</span> <span class="o">=</span> <span class="s">"Fish & Chips"</span>
<span class="k">let</span> <span class="nv">escapedSnack</span> <span class="o">=</span> <span class="n">snack</span><span class="o">.</span><span class="n">addingUnicodeEntities</span> <span class="c1">// "Fish &#038; Chips"</span>
</code></pre>
<a href='#128221-remove-html-entities-unescape' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='128221-remove-html-entities-unescape'>📝 Remove HTML Entities (Unescape)</h3>
<p>To remove HTML entities from a String, use the <code>removingHTMLEntities</code> property.</p>
<a href='#docs' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='docs'>Docs</h4>
<ul>
<li><a href="https://alexaubry.github.io/HTMLString/Extensions/String.html#/s:vE10HTMLStringSS20removingHTMLEntitiesSS"><code>removingHTMLEntities</code></a></li>
</ul>
<a href='#example' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h4 id='example'>Example</h4>
<pre class="highlight swift"><code><span class="kd">import</span> <span class="kt">HTMLString</span>
<span class="k">let</span> <span class="nv">escapedEmoji</span> <span class="o">=</span> <span class="s">"My favorite emoji is &#x1F643;"</span>
<span class="k">let</span> <span class="nv">emoji</span> <span class="o">=</span> <span class="n">escapedEmoji</span><span class="o">.</span><span class="n">removingHTMLEntities</span> <span class="c1">// "My favorite emoji is 🙃"</span>
<span class="k">let</span> <span class="nv">escapedSnack</span> <span class="o">=</span> <span class="s">"Fish &amp; Chips"</span>
<span class="k">let</span> <span class="nv">snack</span> <span class="o">=</span> <span class="n">escapedSnack</span><span class="o">.</span><span class="n">removingHTMLEntities</span> <span class="c1">// "Fish & Chips"</span>
</code></pre>
<a href='#objective-c-api' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='objective-c-api'>Objective-C API</h2>
<p>With Obj-C Mix and Match, you can import and use the <code>HTMLString</code> module from in Objective-C code.</p>
<p>The library introduces a set of Objective-C specific APIs as categories on the <code>NSString</code> type:</p>
<ul>
<li><code>[aString stringByAddingUnicodeEntities];</code> : Replaces every character incompatible with HTML Unicode encoding by a decimal HTML entitiy.</li>
<li><code>[aString stringByAddingASCIIEntities];</code> : Replaces every character incompatible with HTML ASCII encoding by a decimal HTML entitiy.</li>
<li><code>[aString stringByRemovingHTMLEntities];</code> : Replaces every HTML entity with the matching Unicode character.</li>
</ul>
<a href='#escaping-examples' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='escaping-examples'>Escaping Examples</h3>
<pre class="highlight objective_c"><code><span class="k">@import</span> <span class="n">HTMLString</span><span class="p">;</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">emoji</span> <span class="o">=</span> <span class="s">@"My favorite emoji is 🙃"</span><span class="p">;</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">escapedEmoji</span> <span class="o">=</span> <span class="p">[</span><span class="n">emoji</span> <span class="nf">stringByAddingASCIIEntities</span><span class="p">];</span> <span class="c1">// "My favorite emoji is &#128579;"
</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">snack</span> <span class="o">=</span> <span class="s">@"Fish & Chips"</span><span class="p">;</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">escapedSnack</span> <span class="o">=</span> <span class="p">[</span><span class="n">snack</span> <span class="nf">stringByAddingUnicodeEntities</span><span class="p">];</span> <span class="c1">// "Fish &#038; Chips"
</span></code></pre>
<a href='#unescaping-examples' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h3 id='unescaping-examples'>Unescaping Examples</h3>
<pre class="highlight objective_c"><code><span class="k">@import</span> <span class="n">HTMLString</span><span class="p">;</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">escapedEmoji</span> <span class="o">=</span> <span class="s">@"My favorite emoji is &#x1F643;"</span><span class="p">;</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">emoji</span> <span class="o">=</span> <span class="p">[</span><span class="n">escapedEmoji</span> <span class="nf">stringByRemovingHTMLEntities</span><span class="p">];</span> <span class="c1">// "My favorite emoji is 🙃"
</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">escapedSnack</span> <span class="o">=</span> <span class="s">@"Fish &amp; Chips"</span><span class="p">;</span>
<span class="n">NSString</span> <span class="o">*</span><span class="n">snack</span> <span class="o">=</span> <span class="p">[</span><span class="n">escapedSnack</span> <span class="nf">stringByRemovingHTMLEntities</span><span class="p">];</span> <span class="c1">// "Fish & Chips"
</span></code></pre>
<a href='#128175-acknowledgements' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='128175-acknowledgements'>💯 Acknowledgements</h2>
<p><img src="http://i.giphy.com/QBC5foQmcOkdq.gif" alt="Thanks @google"></p>
<p>This library was inspired by <a href="https://github.com/google/google-toolbox-for-mac"><strong>@google</strong>‘s Toolbox for Mac</a>.</p>
</section>
</section>
<section id="footer">
<p>Copyright © 2016-2017 Alexis Aubry Radanovic. Licensed under the <a class="link" href="https://github.com/alexaubry/HTMLString/blob/master/LICENSE" target="_blank" rel="external">MIT License</a>.</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.3</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</div>
</html>