html2html

package module
v0.0.0-...-48ffda1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2017 License: MIT Imports: 7 Imported by: 0

README

html2html

Parse html & Convert to html.

TBD

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTokenType = errors.New("invalid token type")
View Source
var VoidElements = []string{
	"area",
	"base",
	"br",
	"col",
	"embed",
	"hr",
	"img",
	"input",
	"keygen",
	"link",
	"meta",
	"param",
	"source",
	"track",
	"wbr",
}

VoidElements is start with html.StartTagToken, but it is not with html.EndTagToken. see https://www.w3.org/TR/html5/syntax.html#void-elements

Functions

func IsVoidElement

func IsVoidElement(tag Tag) bool

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

type Converter

type Converter interface {
	DefaultConsumer() TokenConsumer
	RaiseErrorOnInvalidEndTag() bool

	ConsumerByTokenType(tokenType html.TokenType) TokenConsumer
	ConsumerByTagName(tagName string) TokenConsumer

	SetRaiseErrorOnInvalidEndTag(newVal bool)
	SetDefaultConsumer(consumer TokenConsumer)
	SetTokenTypeConsumer(tokenType html.TokenType, consumer TokenConsumer)
	SetTagNameConsumer(tagName string, consumer TokenConsumer)

	Parse(r io.Reader) (Tag, error)
	Convert(r io.Reader) (string, error)
}

func NewConverter

func NewConverter() Converter

type DefaultConsumer

type DefaultConsumer struct {
	// contains filtered or unexported fields
}

func (*DefaultConsumer) ConsumeAttrs

func (consumer *DefaultConsumer) ConsumeAttrs(tag Tag, token html.Token) error

func (*DefaultConsumer) ConsumeElementBody

func (consumer *DefaultConsumer) ConsumeElementBody(tag Tag, tokenizer *html.Tokenizer, token html.Token, tagName string) (html.Token, error)

func (*DefaultConsumer) ConsumeToken

func (consumer *DefaultConsumer) ConsumeToken(parent Tag, tokenizer *html.Tokenizer, token html.Token) (html.Token, error)

func (*DefaultConsumer) ConsumeTokenImpl

func (consumer *DefaultConsumer) ConsumeTokenImpl(parent Tag, tokenizer *html.Tokenizer, token html.Token) (html.Token, error)

func (*DefaultConsumer) SetTagAttrsConsumer

func (consumer *DefaultConsumer) SetTagAttrsConsumer(attrsConsumer TagAttrsConsumer)

type Tag

type Tag interface {
	Token

	IsDocumentRoot() bool

	Name() string
	Tokens() []Token
	SetTokens(tokens []Token)

	AddChildTokens(childlen ...Token)
	UnshiftChileToken(token Token)
	ReplateChildToken(from Token, to Token)
	GetElementsByTagName(tagName string) []Tag
	FindAncestor(tagName string) Tag

	Attrs() []*Attr
	SetAttrs(attrs []*Attr)
	AddAttr(key, value string)
	GetAttr(attrKey string) *Attr
	RemoveAttr(attrKey string)
	HasAttr(attrKey string) bool
	HasAttrValue(attrKey string, attrValue string) bool
	HasAttrValueCaseInsensitive(attrKey string, attrValue string) bool
	AddText(text string)
	AddComment(text string)
}

func CreateDocumentRoot

func CreateDocumentRoot() Tag

func CreateElement

func CreateElement(tagName string) Tag

func CreateElementSelfClosing

func CreateElementSelfClosing(tagName string) Tag

type TagAttrsConsumer

type TagAttrsConsumer interface {
	ConsumeAttrs(tag Tag, token html.Token) error
}

type TextToken

type TextToken interface {
	Token

	Text() string
}

type Token

type Token interface {
	Type() TokenType
	Parent() Tag
	BuildHTML(buf *bytes.Buffer)

	Tag() Tag
	TextToken() TextToken
	// contains filtered or unexported methods
}

func CreateCommentToken

func CreateCommentToken(text string) Token

func CreateDoctypeToken

func CreateDoctypeToken(text string) Token

func CreateTextToken

func CreateTextToken(text string) Token

func TagReplacer

func TagReplacer(tag Tag, f func(tag Tag) (Token, error)) (Token, error)

type TokenConsumer

type TokenConsumer interface {
	// ConsumeToken は渡されたTokenをキリのいいところまで処理し、次に処理するべきTokenを返す
	ConsumeToken(parent Tag, tokenizer *html.Tokenizer, token html.Token) (html.Token, error)
}

TokenConsumer はHTMLのTokenを食べて何らかの文字列を組み立てる

func NewVacuumConsumer

func NewVacuumConsumer(conv Converter) TokenConsumer

NewVacuumConsumer は渡されたTokenから始まる要素を全て捨てるTokenConsumerを返す

type TokenType

type TokenType int
const (
	TypeTagToken TokenType = 1 + iota
	TypeDoctypeToken
	TypeTextToken
	TypeCommentToken
)

Jump to

Keyboard shortcuts

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