rite

package
v0.10.4 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const EndHTMLTag = '>'
View Source
const StartHTMLTag = '<'

Variables

View Source
var ErrBufferExceeded = errors.New("max buffer exceeded")

ErrBufferExceeded means that the buffering limit was exceeded.

View Source
var HeadingElements = []string{"h1", "h2", "h3", "h4", "h5", "h6"}
View Source
var NoBlockElements = []string{
	"p", "code", "b", "i", "hr", "em", "strong", "small", "s",
}
View Source
var VoidElements = []string{
	"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr",
}

Functions

func EncodeOnPlaceWithUnderscore

func EncodeOnPlaceWithUnderscore(line []byte) []byte

func HasPrefix

func HasPrefix(line []byte, pre string) bool

func ReadQuotedWords

func ReadQuotedWords(workingTagSpec []byte) (word []byte, rest []byte)

func ReadTagName

func ReadTagName(tagSpec []byte) (tagName []byte, rest []byte)

func ReadWord

func ReadWord(line []byte) (word []byte, rest []byte)

func ReparentChildren

func ReparentChildren(dst, src *Node)

ReparentChildren reparents all of src's child nodes to dst.

func SkipWhiteSpace

func SkipWhiteSpace(line []byte) []byte

func TrimLeft

func TrimLeft(line []byte, s byte) (int, []byte)

Types

type AttrType

type AttrType int
const (
	Id AttrType = iota
	Class
	Src
	Href
	Attrs
)

type Attribute

type Attribute struct {
	Key string
	Val []byte
}

An Attribute is an attribute key-value pair. Key is alphabetic (and hence does not contain escapable characters like '&', '<' or '>'), and Val is unescaped (it looks like "a<b" rather than "a&lt;b").

func ReadTagAttrKey

func ReadTagAttrKey(tagSpec []byte) (Attribute, []byte)

type ByteRenderer

type ByteRenderer struct {
	bytes.Buffer
}

func (*ByteRenderer) CloneBytes

func (r *ByteRenderer) CloneBytes() []byte

CloneBytes returns a copy of the buffer contents, so the returned copy is owned by the caller

func (*ByteRenderer) Render

func (r *ByteRenderer) Render(inputs ...any)

func (*ByteRenderer) Renderln

func (r *ByteRenderer) Renderln(inputs ...any)

type Node

type Node struct {
	TreeNode
	Type    NodeType
	Level   int
	Outline string

	RawText     *Text
	InnerText   []byte
	Indentation int
	LineNumber  int
	Name        string
	Id          []byte
	Class       []byte
	Src         []byte
	Href        []byte
	Bucket      []byte
	Number      []byte
	BulletText  []byte
	Attr        []Attribute
	RestLine    []byte
	// contains filtered or unexported fields
}

func (*Node) AddClass

func (n *Node) AddClass(newClass []byte)

func (*Node) AddClassString

func (n *Node) AddClassString(newClass string)

func (*Node) AppendChild

func (n *Node) AppendChild(c *Node)

AppendChild adds a node c as a child of n.

It will panic if c already has a parent or siblings.

func (*Node) Clone

func (n *Node) Clone() *Node

Clone returns a new node with the same type, data and attributes. The Clone has no parent, no siblings and no children.

func (*Node) InsertBefore

func (n *Node) InsertBefore(newChild, oldChild *Node)

InsertBefore inserts newChild as a child of n, immediately before oldChild in the sequence of n's children. oldChild may be nil, in which case newChild is appended to the end of n's children.

It will panic if newChild already has a parent or siblings.

func (*Node) RemoveChild

func (n *Node) RemoveChild(c *Node)

RemoveChild removes a node c that is a child of n. Afterwards, c will have no parent and no siblings.

It will panic if c's parent is not n.

func (*Node) RenderDiagramNode

func (n *Node) RenderDiagramNode(br *ByteRenderer) error

func (*Node) RenderExampleNode

func (n *Node) RenderExampleNode(br *ByteRenderer) error

func (*Node) RenderHTML

func (n *Node) RenderHTML(br *ByteRenderer) error

RenderHTML renders recursively to HTML this node and its children (if any)

func (*Node) RenderNormalNode

func (n *Node) RenderNormalNode(br *ByteRenderer) error

func (Node) String

func (n Node) String() string

String returns a string representation of the Node.

type NodeType

type NodeType uint32

A NodeType is the type of a Node.

const (
	ErrorNode NodeType = iota
	DocumentNode
	SectionNode
	BlockNode
	DiagramNode
	ExplanationNode
	VerbatimNode
	IncludeNode
)

func (NodeType) String

func (n NodeType) String() string

String returns a string representation of the TokenType.

type Parser

type Parser struct {
	Ids  map[string]int // To provide numbering of different entity classes
	Figs map[string]int // To provide numbering of figs of different types in the document
	Xref map[string]*Node

	Config *yaml.YAML
	// contains filtered or unexported fields
}

func NewParser

func NewParser(fileName string, linescanner *bufio.Scanner) *Parser

NewParser parses a document reading lines from linescanner. filename is for logging/tracing purposes.

func ParseFromFile

func ParseFromFile(fileName string, processYAML bool) (*Parser, error)

ParseFromFile reads a file and preprocesses it in memory

func (*Parser) NewNode

func (p *Parser) NewNode(parent *Node, text *Text) *Node

NewNode creates a node from the text that is passed. The new node is set to the proper type and its attributes populated. If the line starts with a proper tag, it is processed and the node is updated accordingly.

func (*Parser) Parse

func (p *Parser) Parse() error

func (*Parser) ParseBlock

func (p *Parser) ParseBlock(parent *Node)

ParseBlock parses the segment of the document that belongs to the block represented by the node. The node will have as child nodes all elements that are at the same indentation

func (*Parser) ParseIncludeFile

func (p *Parser) ParseIncludeFile(parent *Node, fileName string, processYAML bool) (*Parser, error)

ParseIncludeFile reads an included file and preprocesses it in memory

func (*Parser) ParseVerbatim

func (p *Parser) ParseVerbatim(parent *Node) error

func (*Parser) ParseVerbatimIncluded

func (p *Parser) ParseVerbatimIncluded(parent *Node) error

func (*Parser) PeekParagraphFirstLine

func (p *Parser) PeekParagraphFirstLine() *Text

func (*Parser) PreprocesLine

func (p *Parser) PreprocesLine(lineSt *Text) *Text

PreprocesLine applies some preprocessing to the raw line that was just read from the stream. Only preprocessing which is local to the current line can be applied.

func (*Parser) ReadAnyParagraph

func (p *Parser) ReadAnyParagraph(min_indentation int) *Text

ReadAnyParagraph reads all contiguous lines with the same indentation, if their indentation equal or greater than min_indentation. It skips all blank lines at the beginning.

func (*Parser) ReadLine

func (p *Parser) ReadLine() *Text

ReadLine returns one line from the underlying bufio.Scanner. It supports one-level backtracking, with the UnreadLine method.

func (*Parser) ReadParagraph

func (p *Parser) ReadParagraph(indentation int) *Text

ReadParagraph is like ReadLine but returns all contiguous lines at the same level of indentation. The paragraph starts at the first non-blank line with more indentation than the specified one. A line starting with a block tag is considered a different paragraph, and stops the current paragraph.

func (*Parser) RenderHTML

func (p *Parser) RenderHTML() []byte

func (*Parser) SkipBlankLines

func (p *Parser) SkipBlankLines() bool

SkipBlankLines skips blank or comment lines until EOF. Returns true if a non-blank line was found, false on EOF.

func (*Parser) UnreadLine

func (p *Parser) UnreadLine(line *Text)

UnreadLine allows one-level backtracking by buffering one line that was already returned from bufio.Scanner

func (*Parser) UnreadParagraph

func (p *Parser) UnreadParagraph(para *Text)

UnreadParagraph allows one-level backtracking by buffering one paragraph that was already returned from bufio.Scanner

type Text

type Text struct {
	Indentation int
	LineNumber  int
	Content     []byte
}

func (*Text) String

func (para *Text) String() string

String represents the Text with the 20 first characters

type TreeNode

type TreeNode struct {
	Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node
}

Jump to

Keyboard shortcuts

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