html

package module
v0.0.0-...-7d7c804 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2018 License: BSD-2-Clause Imports: 4 Imported by: 4

README

This repository has moved to gitlab.com/golang-commonmark/html.

Documentation

Overview

Package html provides functions for escaping HTML and for parsing and replacing HTML entities.

Index

Examples

Constants

View Source
const BadEntity = string(utf8.RuneError)

Variables

This section is empty.

Functions

func EscapeString

func EscapeString(s string) string
Example
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 ParseEntity

func ParseEntity(s string) (string, int)
Example
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
� 11

func ReplaceEntities

func ReplaceEntities(s string) string
Example
fmt.Println(ReplaceEntities("&nbsp; &amp; &copy; &AElig; &Dcaron; &frac34; &HilbertSpace; &DifferentialD; &ClockwiseContourIntegral; &#35; &#1234; &#992; &#98765432; &#X22; &#XD06; &#xcab; &nbsp &x; &#; &#x; &ThisIsWayTooLongToBeAnEntityIsntIt; &hi?; &copy &MadeUpEntity;"))
Output:

  & © Æ Ď ¾ ℋ ⅆ ∲ # Ӓ Ϡ � " ആ ಫ &nbsp &x; &#; &#x; &ThisIsWayTooLongToBeAnEntityIsntIt; &hi?; &copy &MadeUpEntity;

func WriteEscapedString

func WriteEscapedString(w io.Writer, s string) error
Example
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;

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL