parser

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var VoidElements = map[string]bool{
	"area":   true,
	"base":   true,
	"br":     true,
	"col":    true,
	"embed":  true,
	"hr":     true,
	"img":    true,
	"input":  true,
	"keygen": true,
	"link":   true,
	"meta":   true,
	"param":  true,
	"source": true,
	"track":  true,
	"wbr":    true,
}

单标签, 在渲染和解析为节点树会使用.

Functions

This section is empty.

Types

type Attr

type Attr struct {
	Key   string
	Value string
}

type Attribute

type Attribute struct {
	Key, Val string
}

type Attributes

type Attributes []Attribute

type Class

type Class []string

func NewClass

func NewClass() Class

func (Class) Exist

func (c Class) Exist(a string) bool

func (*Class) Merge

func (c *Class) Merge(a Class)

func (*Class) Remove

func (c *Class) Remove(i string)

func (Class) ToAttr

func (c Class) ToAttr() string

type Directive

type Directive struct {
	Name  string // animate
	Value string // {'a': 1}
	Arg   string // v-set:arg
}

type Directives

type Directives []Directive

type ElseIf

type ElseIf struct {
	Types      string // else / elseif
	Condition  string // elseif语句的condition表达式
	VueElement *VueElement
}

type Node

type Node struct {
	NodeType NodeType
	Tag      string
	Text     string // value of TextNode
	Attrs    []Attr
	Parent   *Node
	Child    []*Node
}

func ParseHtml

func ParseHtml(str string) (nt *Node, err error)

func (*Node) Add

func (p *Node) Add(n *Node)

func (*Node) AddBor

func (p *Node) AddBor(n *Node)

func (*Node) AddChild

func (p *Node) AddChild(n *Node)

func (*Node) Close

func (p *Node) Close(tag string) *Node

Close当前节点, 返回父级节点

func (*Node) GetParent

func (p *Node) GetParent(deep int) *Node

func (*Node) NicePrint

func (p *Node) NicePrint(lev int) string

type NodeParser

type NodeParser struct {
}

func NewNodeParser

func NewNodeParser() *NodeParser

func (*NodeParser) Parse

func (p *NodeParser) Parse(l *html.Lexer) (node *Node, err error)

type NodeType

type NodeType uint32

NodeType is the type of a Node.

const (
	ErrorNode NodeType = iota
	TextNode
	DocumentNode
	ElementNode
	CommentNode
	DoctypeNode

	// Root节点只是一个虚拟节点, 方便管理, 不会参与渲染, 而是直接渲染子级
	RootNode
)

type ParseVueNodeOptions

type ParseVueNodeOptions struct {
	CanBeAttr   func(k string) bool
	SkipComment bool
}

type Prop

type Prop struct {
	IsStatic  bool // 是否是静态的(v-bind:语法是动态, 之外是静态)
	CanBeAttr bool // 是否当成attr输出
	Key       string
	StaticVal interface{} // 静态的value, 如style和class在编译时就会被解析成map和slice
	ValCode   string      // 如果props是动态的, valCode存储js表达式
}

type Props

type Props []*Prop

func (*Props) Del

func (p *Props) Del(key string)

func (Props) Get

func (p Props) Get(key string) (val string, exist bool)

func (Props) IsStatic

func (p Props) IsStatic() bool

是否全部是静态Prop

type Style

type Style struct {
	Key, Val string
}

type Styles

type Styles map[string]string

func (Styles) Add

func (p Styles) Add(key string, val string)

func (Styles) Del

func (p Styles) Del(key string)

func (Styles) Merge

func (p Styles) Merge(a Styles)

func (Styles) ToAttr

func (p Styles) ToAttr() string

type VBind

type VBind struct {
	Val string
}

type VFor

type VFor struct {
	ArrayKey string
	ItemKey  string
	IndexKey string
}

type VIf

type VIf struct {
	Condition string // 条件表达式
	// 当此节点是if节点是, 将与if指令匹配的elseif/else节点关联在一起
	ElseIf []*ElseIf
}

func (*VIf) AddElseIf

func (p *VIf) AddElseIf(v *ElseIf)

type VSlot

type VSlot struct {
	SlotName string
	PropsKey string
}

type VueElement

type VueElement struct {
	NodeType NodeType
	Tag      string
	Text     string
	// 是否分配调用组件时传递来的属性.
	// 如果组件中只存在一个root节点, 则此节点会自动分配属性. 否则所有root节点都不会.
	// (fragments: https://v3.vuejs.org/guide/migration/fragments.html#overview)
	DistributionAttr bool

	//PropClass  *Prop // 动态Class
	//PropStyle  *Prop // 动态style
	Props      Props // props, 动态和静态, 包括class和style
	VBind      *VBind
	Directives Directives // 自定义指令, 运行时
	//Class      Class         // 静态class
	//Style      Styles        // 静态style
	Children []*VueElement // 子节点
	VIf      *VIf          // 处理v-if需要的数据
	VFor     *VFor
	VSlot    *VSlot
	VElse    bool // 如果是VElse节点则不会生成代码(而是在vif里生成代码)
	VElseIf  bool
	// v-html / v-text
	// 支持v-html / v-text指令覆盖子级内容的组件有: template / html基本标签
	// component/slot和自定义组件不支持(没有必要)v-html/v-text覆盖子级
	VHtml string
	VText string
}

func ToVueNode

func ToVueNode(node *Node, options *ParseVueNodeOptions) (vn *VueElement, err error)

将html节点转换为Vue节点

func (*VueElement) NicePrint

func (p *VueElement) NicePrint(showChild bool, lev int) string

type VueElementParser

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

func (VueElementParser) Parse

func (p VueElementParser) Parse(e *Node) (*VueElement, error)

Jump to

Keyboard shortcuts

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