{"modulePath":"github.com/wavetermdev/htmltoken","version":"v0.2.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package htmltoken\n\n## Variables\n\n```go\nvar ErrBufferExceeded = errors.New(\"max buffer exceeded\")\n```\nErrBufferExceeded means that the buffering limit was exceeded.\n\n## Functions\n\n```go\nfunc EscapeString(s string) string\n```\nEscapeString escapes special characters like \"\\\u003c\" to become \"\u0026lt;\". It escapes only five such characters: \\\u003c, \u003e, \u0026, ' and \". UnescapeString(EscapeString(s)) == s always holds, but the converse isn't always true.\n\n## Types\n\n```go\ntype Attribute struct {\n\tNamespace, Key, Val string\n\tIsJson              bool // MOD - added to support json attributes\n}\n```\nAn Attribute is an attribute namespace-key-value triple. Namespace is non-empty for foreign attributes like xlink, Key is alphabetic (and hence does not contain escapable characters like '\u0026', '\\\u003c' or '\u003e'), and Val is unescaped (it looks like \"a\\\u003cb\" rather than \"a\u0026lt;b\").\n\nNamespace is only used by the parser, not the tokenizer.\n\n```go\ntype Token struct {\n\tType     TokenType\n\tDataAtom atom.Atom\n\tData     string\n\tAttr     []Attribute\n}\n```\nA Token consists of a TokenType and some Data (tag name for start and end tags, content for text, comments and doctypes). A tag Token may also contain a slice of Attributes. Data is unescaped for all Tokens (it looks like \"a\\\u003cb\" rather than \"a\u0026lt;b\"). For tag Tokens, DataAtom is the atom for Data, or zero if Data is not a known tag name.\n\n```go\nfunc (t Token) String() string\n```\nString returns a string representation of the Token.\n\n```go\ntype TokenType uint32\n```\nA TokenType is the type of a Token.\n\n```go\nconst (\n\t// ErrorToken means that an error occurred during tokenization.\n\tErrorToken TokenType = iota\n\t// TextToken means a text node.\n\tTextToken\n\t// A StartTagToken looks like \u003ca\u003e.\n\tStartTagToken\n\t// An EndTagToken looks like \u003c/a\u003e.\n\tEndTagToken\n\t// A SelfClosingTagToken tag looks like \u003cbr/\u003e.\n\tSelfClosingTagToken\n\t// A CommentToken looks like \u003c!--x--\u003e.\n\tCommentToken\n\t// A DoctypeToken looks like \u003c!DOCTYPE x\u003e\n\tDoctypeToken\n)\n```\n\n```go\nfunc (t TokenType) String() string\n```\nString returns a string representation of the TokenType.\n\n```go\ntype Tokenizer struct {\n\t// contains filtered or unexported fields\n}\n```\nA Tokenizer returns a stream of HTML Tokens.\n\n```go\nfunc NewTokenizer(r io.Reader) *Tokenizer\n```\nNewTokenizer returns a new HTML Tokenizer for the given Reader. The input is assumed to be UTF-8 encoded.\n\n```go\nfunc NewTokenizerFragment(r io.Reader, contextTag string) *Tokenizer\n```\nNewTokenizerFragment returns a new HTML Tokenizer for the given Reader, for tokenizing an existing element's InnerHTML fragment. contextTag is that element's tag, such as \"div\" or \"iframe\".\n\nFor example, how the InnerHTML \"a\\\u003cb\" is tokenized depends on whether it is for a \\\u003cp\u003e tag or a \\\u003cscript\u003e tag.\n\nThe input is assumed to be UTF-8 encoded.\n\n```go\nfunc (z *Tokenizer) AllowCDATA(allowCDATA bool)\n```\nAllowCDATA sets whether or not the tokenizer recognizes \\\u003c!\\[CDATA\\[foo]]\u003e as the text \"foo\". The default value is false, which means to recognize it as a bogus comment \"\\\u003c!-- \\[CDATA\\[foo]] --\u003e\" instead.\n\nStrictly speaking, an HTML5 compliant tokenizer should allow CDATA if and only if tokenizing foreign content, such as MathML and SVG. However, tracking foreign-contentness is difficult to do purely in the tokenizer, as opposed to the parser, due to HTML integration points: an \\\u003csvg\u003e element can contain a \\\u003cforeignObject\u003e that is foreign-to-SVG but not foreign-to- HTML. For strict compliance with the HTML5 tokenization algorithm, it is the responsibility of the user of a tokenizer to call AllowCDATA as appropriate. In practice, if using the tokenizer without caring whether MathML or SVG CDATA is text or comments, such as tokenizing HTML to find all the anchor text, it is acceptable to ignore this responsibility.\n\n```go\nfunc (z *Tokenizer) Buffered() []byte\n```\nBuffered returns a slice containing data buffered but not yet tokenized.\n\n```go\nfunc (z *Tokenizer) Err() error\n```\nErr returns the error associated with the most recent ErrorToken token. This is typically io.EOF, meaning the end of tokenization.\n\n```go\nfunc (z *Tokenizer) Next() TokenType\n```\nNext scans the next token and returns its type.\n\n```go\nfunc (z *Tokenizer) NextIsNotRawText()\n```\nNextIsNotRawText instructs the tokenizer that the next token should not be considered as 'raw text'. Some elements, such as script and title elements, normally require the next token after the opening tag to be 'raw text' that has no child elements. For example, tokenizing \"\\\u003ctitle\u003ea\\\u003cb\u003ec\\\u003c/b\u003ed\\\u003c/title\u003e\" yields a start tag token for \"\\\u003ctitle\u003e\", a text token for \"a\\\u003cb\u003ec\\\u003c/b\u003ed\", and an end tag token for \"\\\u003c/title\u003e\". There are no distinct start tag or end tag tokens for the \"\\\u003cb\u003e\" and \"\\\u003c/b\u003e\".\n\nThis tokenizer implementation will generally look for raw text at the right times. Strictly speaking, an HTML5 compliant tokenizer should not look for raw text if in foreign content: \\\u003ctitle\u003e generally needs raw text, but a \\\u003ctitle\u003e inside an \\\u003csvg\u003e does not. Another example is that a \\\u003ctextarea\u003e generally needs raw text, but a \\\u003ctextarea\u003e is not allowed as an immediate child of a \\\u003cselect\u003e; in normal parsing, a \\\u003ctextarea\u003e implies \\\u003c/select\u003e, but one cannot close the implicit element when parsing a \\\u003cselect\u003e's InnerHTML. Similarly to AllowCDATA, tracking the correct moment to override raw-text- ness is difficult to do purely in the tokenizer, as opposed to the parser. For strict compliance with the HTML5 tokenization algorithm, it is the responsibility of the user of a tokenizer to call NextIsNotRawText as appropriate. In practice, like AllowCDATA, it is acceptable to ignore this responsibility for basic usage.\n\nNote that this 'raw text' concept is different from the one offered by the Tokenizer.Raw method.\n\n```go\nfunc (z *Tokenizer) Raw() []byte\n```\nRaw returns the unmodified text of the current token. Calling Next, Token, Text, TagName or TagAttr may change the contents of the returned slice.\n\nThe token stream's raw bytes partition the byte stream (up until an ErrorToken). There are no overlaps or gaps between two consecutive token's raw bytes. One implication is that the byte offset of the current token is the sum of the lengths of all previous tokens' raw bytes.\n\n```go\nfunc (z *Tokenizer) SetMaxBuf(n int)\n```\nSetMaxBuf sets a limit on the amount of data buffered during tokenization. A value of 0 means unlimited.\n\n```go\nfunc (z *Tokenizer) TagAttr() (key, val []byte, isJson bool, moreAttr bool)\n```\nTagAttr returns the lower-cased key and unescaped value of the next unparsed attribute for the current tag token and whether there are more attributes. The contents of the returned slices may change on the next call to Next. MOD -- added isJson bool return value\n\n```go\nfunc (z *Tokenizer) TagName() (name []byte, hasAttr bool)\n```\nTagName returns the lower-cased name of a tag token (the \\`img\\` out of \\`\\\u003cIMG SRC=\"foo\"\u003e\\`) and whether the tag has attributes. The contents of the returned slice may change on the next call to Next.\n\n```go\nfunc (z *Tokenizer) Text() []byte\n```\nText returns the unescaped text of a text, comment or doctype token. The contents of the returned slice may change on the next call to Next.\n\n```go\nfunc (z *Tokenizer) Token() Token\n```\nToken returns the current Token. The result's Data and Attr values remain valid after subsequent Next calls.\n\n","path":"github.com/wavetermdev/htmltoken","name":"htmltoken","synopsis":"","isRedistributable":true}
