html

package
v0.0.0-...-cb9f122 Latest Latest
Warning

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

Go to latest
Published: May 18, 2025 License: MIT Imports: 9 Imported by: 0

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 BrParser

type BrParser struct{}

func (*BrParser) Parse

func (p *BrParser) Parse(node *AstElement) *PMNode

Parse the tag <br>

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

func NewPMNode

func NewPMNode() *PMNode

Create a new proseMirror node

type ParserContext

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

func NewParserContext

func NewParserContext() *ParserContext

Create a new parser context

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 Stack

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

func NewStack

func NewStack() *Stack

Create a new stack

func (*Stack) Len

func (s *Stack) Len() int

Return the number of items in the stack

func (*Stack) Peek

func (s *Stack) Peek() interface{}

View the top item on the stack

func (*Stack) Pop

func (s *Stack) Pop() interface{}

Pop the top item of the stack and return it

func (*Stack) Push

func (s *Stack) Push(value interface{})

Push a value onto the top of the stack

type TableParser

type TableParser struct {
	Parsers *map[string]TagParser
}

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{}

func (*TextParser) Parse

func (p *TextParser) Parse(node *AstElement) *PMNode

Parse the tag <p>

Jump to

Keyboard shortcuts

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