parser

package
v0.0.0-...-d07a634 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2024 License: MIT Imports: 6 Imported by: 0

README

A stripped-down version of the github.com/gomarkdown/markdown parser.

  • It only parses paragraphs

  • AST has been removed, instead it returns slices of links

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlnum

func IsAlnum(c byte) bool

IsAlnum returns true if c is a digit or letter TODO: check when this is looking for ASCII alnum and when it should use unicode

func IsEmpty

func IsEmpty(data []byte) int

func IsLetter

func IsLetter(c byte) bool

IsLetter returns true if c is ascii letter

func IsPunctuation

func IsPunctuation(c byte) bool

IsPunctuation returns true if c is a punctuation symbol.

func IsSpace

func IsSpace(c byte) bool

IsSpace returns true if c is a white-space charactr

func NormalizeNewlines

func NormalizeNewlines(d []byte) []byte

Types

type Code

type Code struct {
	Leaf
}

type CodeBlock

type CodeBlock struct {
	Leaf
}

type Container

type Container interface {
	GetContent() []byte // Markdown content of the block nodes
}

type HTMLSpan

type HTMLSpan struct {
	Leaf
}

HTMLSpan represents markdown html span node

type Image

type Image struct {
	Leaf

	Destination []byte // Destination is what goes into a href
	Title       []byte // Title is the tooltip thing that goes in a title attribute
}

Image represents markdown image node

type Leaf

type Leaf struct {
	Literal []byte // Text contents of the leaf nodes
	Content []byte // Markdown content of the block nodes
}

Leaf is a type of node that cannot have children

func (Leaf) GetContent

func (l Leaf) GetContent() []byte

func (Leaf) GetLiteral

func (l Leaf) GetLiteral() []byte
type Link struct {
	Leaf

	Destination []byte // Destination is what goes into a href
	Title       []byte // Title is the tooltip thing that goes in a title attribute
}

Link represents markdown link node

type Node

type Node interface {
	GetContent() []byte
	GetLiteral() []byte
}

type Paragraph

type Paragraph struct {
	Content []byte
}

func (Paragraph) GetContent

func (p Paragraph) GetContent() []byte

type Parser

type Parser struct {
	Blocks []Container
	Nodes  []Node
	// contains filtered or unexported fields
}

func New

func New() *Parser

New creates a markdown parser

func (*Parser) AddBlock

func (p *Parser) AddBlock(b Container) Container

func (*Parser) AppendNode

func (p *Parser) AppendNode(n Node)

func (*Parser) Block

func (p *Parser) Block(data []byte)

Parse Block-level data. Note: this function and many that it calls assume that the input buffer ends with a newline.

func (*Parser) Inline

func (p *Parser) Inline(data []byte)

Inline parses text within a block. Each function returns the number of consumed chars.

func (*Parser) LinksAndImages

func (p *Parser) LinksAndImages() ([]Link, []Image)

func (*Parser) Parse

func (p *Parser) Parse(input []byte)

Parse parsers input into blocks and then into slice of nodes

func (*Parser) RegisterInline

func (p *Parser) RegisterInline(n byte, fn inlineParser) inlineParser

type Text

type Text struct {
	Leaf
}

Text represents markdown text node

Jump to

Keyboard shortcuts

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