Files
polaris/vendor/gitlab.com/golang-commonmark/html/html_example_test.go
Bobby Brennan 2c1c4c2cca add new deps
2019-05-08 14:54:06 +00:00

55 lines
1.6 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright 2015 The Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package html
import (
"bytes"
"fmt"
)
func ExampleEscapeString() {
fmt.Println(EscapeString(`<a href="https://www.google.com/search?q=something&ie=utf-8">Google Search</a>`))
// Output:
// &lt;a href=&quot;https://www.google.com/search?q=something&amp;ie=utf-8&quot;&gt;Google Search&lt;/a&gt;
}
func ExampleWriteEscapedString() {
var buf bytes.Buffer
WriteEscapedString(&buf, `<a href="https://www.google.com/search?q=something&ie=utf-8">Google Search</a>`)
fmt.Println(buf.String())
// Output:
// &lt;a href=&quot;https://www.google.com/search?q=something&amp;ie=utf-8&quot;&gt;Google Search&lt;/a&gt;
}
func ExampleParseEntity() {
fmt.Println(ParseEntity("&quot;"))
fmt.Println(ParseEntity("&#x22;"))
fmt.Println(ParseEntity("&#34;"))
fmt.Println(ParseEntity("&#x00000022;"))
fmt.Println(ParseEntity("&#00000034;"))
fmt.Println(ParseEntity("&#x000000022;"))
fmt.Println(ParseEntity("&#000000034;"))
fmt.Println(ParseEntity("&#98765432;"))
// Output:
// " 6
// " 6
// " 5
// " 12
// " 11
// 0
// 0
// <20> 11
}
func ExampleUnescapeString() {
fmt.Println(UnescapeString("&nbsp; &amp; &copy; &AElig; &Dcaron; &frac34; &HilbertSpace; &DifferentialD; &ClockwiseContourIntegral; &#35; &#1234; &#992; &#98765432; &#X22; &#XD06; &#xcab; &nbsp &x; &#; &#x; &ThisIsWayTooLongToBeAnEntityIsntIt; &hi?; &copy &MadeUpEntity;"))
// Output:
//   & © Æ Ď ¾ ∲ # Ӓ Ϡ <20> " ആ ಫ &nbsp &x; &#; &#x; &ThisIsWayTooLongToBeAnEntityIsntIt; &hi?; &copy &MadeUpEntity;
}