blob: 27643e645527d9f91662ddd6b31416468b7a95ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
<h1> Package html </h1> <ul id="short-nav">
<li><code>import "html"</code></li>
<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
<li><a href="#pkg-index" class="indexLink">Index</a></li>
<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
<li><a href="#pkg-subdirectories">Subdirectories</a></li>
</ul> <h2 id="pkg-overview">Overview </h2> <p>Package html provides functions for escaping and unescaping HTML text. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
<li><a href="#EscapeString">func EscapeString(s string) string</a></li>
<li><a href="#UnescapeString">func UnescapeString(s string) string</a></li>
</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_EscapeString">EscapeString</a></dd> <dd><a class="exampleLink" href="#example_UnescapeString">UnescapeString</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>entity.go</span> <span>escape.go</span> </p> <h2 id="EscapeString">func <span>EscapeString</span> </h2> <pre data-language="go">func EscapeString(s string) string</pre> <p>EscapeString escapes special characters like "<" to become "&lt;". It escapes only five such characters: <, >, &, ' and ". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true. </p> <h4 id="example_EscapeString"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">const s = `"Fran & Freddie's Diner" <tasty@example.com>`
fmt.Println(html.EscapeString(s))
</pre> <p>Output:</p> <pre class="output" data-language="go">&#34;Fran &amp; Freddie&#39;s Diner&#34; &lt;tasty@example.com&gt;
</pre> <h2 id="UnescapeString">func <span>UnescapeString</span> </h2> <pre data-language="go">func UnescapeString(s string) string</pre> <p>UnescapeString unescapes entities like "&lt;" to become "<". It unescapes a larger range of entities than EscapeString escapes. For example, "&aacute;" unescapes to "á", as does "&#225;" and "&#xE1;". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true. </p> <h4 id="example_UnescapeString"> <span class="text">Example</span>
</h4> <p>Code:</p> <pre class="code" data-language="go">const s = `&quot;Fran &amp; Freddie&#39;s Diner&quot; &lt;tasty@example.com&gt;`
fmt.Println(html.UnescapeString(s))
</pre> <p>Output:</p> <pre class="output" data-language="go">"Fran & Freddie's Diner" <tasty@example.com>
</pre> <h2 id="pkg-subdirectories">Subdirectories</h2> <div class="pkg-dir"> <table> <tr> <th class="pkg-name">Name</th> <th class="pkg-synopsis">Synopsis</th> </tr> <tr> <td colspan="2"><a href="../index">..</a></td> </tr> <tr> <td class="pkg-name"> <a href="template/index">template</a> </td> <td class="pkg-synopsis"> Package template (html/template) implements data-driven templates for generating HTML output safe against code injection. </td> </tr> </table> </div><div class="_attribution">
<p class="_attribution-p">
© Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
<a href="http://golang.org/pkg/html/" class="_attribution-link">http://golang.org/pkg/html/</a>
</p>
</div>
|