Documentation
¶
Overview ¶
Description: The parser corresponding to each tag Author: Hughie21 Date: 2024-12-20 license that can be found in the LICENSE file.
Description: Convert ast syntax tree to proseMirror scheme Author: Hughie21 Date: 2024-12-20 license that can be found in the LICENSE file.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindTextTill ¶
func FindTextTill(node *AstElement, parent *PMNode)
This method is used to parse the text in the node it will iterates through all the child nodes under the given node
Whenever the type of a node is checked to be 3, the node is forward traversed to its parent node, looking for other possible format-related nodes
Types ¶
type AstElement ¶
type AstElement struct {
Tag string
Type int
Children []*AstElement
Parent *AstElement
Attrs map[string]string
Text string
}
the ast tree nodes
func LoadHTML ¶
func LoadHTML(html []byte) (*AstElement, error)
LoadHTML loads the given HTML byte slice and returns an AstElement object.
type CodeBlockParser ¶
type CodeBlockParser struct{}
func (*CodeBlockParser) Parse ¶
func (p *CodeBlockParser) Parse(node *AstElement) *PMNode
Parse the tag <pre>
type HTMLParser ¶
type HTMLParser struct {
// contains filtered or unexported fields
}
HTMLParser is a struct that contains the root element of the AST tree and a stack to keep track of the current element being processed.
func NewHTMLParser ¶
func NewHTMLParser() *HTMLParser
NewHTMLParser creates a new HTMLParser object and returns a pointer to it.
type HeaderParser ¶
type HeaderParser struct {
Level int
}
func (*HeaderParser) Parse ¶
func (p *HeaderParser) Parse(node *AstElement) *PMNode
Parse the tag <h1> to <h6>
type ImageParser ¶
type ImageParser struct {
FoldName string
}
func (*ImageParser) Parse ¶
func (p *ImageParser) Parse(node *AstElement) *PMNode
Parse the tag <img> or <image>
type ListParser ¶
type ListParser struct {
Type string
}
func (*ListParser) Parse ¶
func (p *ListParser) Parse(node *AstElement) *PMNode
Parse the tag <ul> or <ol>
type PMNode ¶
type PMNode struct {
Type string `json:"type"`
Attrs map[string]interface{} `json:"attrs,omitempty"`
Content []*PMNode `json:"content,omitempty"`
Text string `json:"text,omitempty"`
Mark []*PMNode `json:"marks,omitempty"`
}
func ConvertIntoProseMirrorScheme ¶
func ConvertIntoProseMirrorScheme(root *AstElement, Parsers map[string]TagParser) *PMNode
Convert ast syntax tree to proseMirror scheme
Traverse the ast tree using a depth-first algorithm, and when the tag matches a predefined rule, call its parser to parse it
type ParserContext ¶
type ParserContext struct {
// contains filtered or unexported fields
}
func (*ParserContext) Parse ¶
func (c *ParserContext) Parse(node *AstElement) *PMNode
call the parser to parse the node
func (*ParserContext) Register ¶
func (c *ParserContext) Register(tag string, parser TagParser)
Register a tag parser
type TableParser ¶
func (*TableParser) Parse ¶
func (p *TableParser) Parse(node *AstElement) *PMNode
Parse the tag <table>
type TagParser ¶
type TagParser interface {
Parse(node *AstElement) *PMNode
}
type TextParser ¶
type TextParser struct{}