markdown

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

The markdown package implements filesys.Handler for the Markdown format.

Markdown is parsed and rendered with the goldmark package. As such, it contains implementations of various goldmark interfaces, which may be used for custom parsers and renderers.

Index

Constants

This section is empty.

Variables

View Source
var KindSection = ast.NewNodeKind("Section")

KindSection is the ast.NodeKind corresponding to Section.

Functions

func NewHandler

func NewHandler(options ...goldmark.Option) filesys.HandlerFunc

NewHandler returns a filesys.HandlerFunc that handles the Markdown format.

The content of a Markdown file is divided into a tree of sections, delimited by headings. A section can be drilled into, with the name corresponding to the content of the section's heading.

A section contains all the content that follows a heading, up to the next heading of the same level. Content that follows the section's heading, and precedes the end of the section or the first sub-heading, is contained within an "orphaned" section. The name of this section is an empty string, and will be the first child section.

func NewSectionRenderer

func NewSectionRenderer() renderer.NodeRenderer

NewSectionRenderer returns a renderer.NodeRenderer that renders a Section node.

func NewSectionTransformer

func NewSectionTransformer() parser.ASTTransformer

NewSectionTransformer returns a parser.ASTTransformer that inserts Sections into the tree.

Types

type Node

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

Node implements drill.Node.

func NewNode

func NewNode(root ast.Node, source []byte, renderer renderer.Renderer) *Node

NewNode returns a Node that wraps the given ast.Node, source, and renderer. root is assumed to be an ast.Document or a Section.

The node created by NewNode is treated as the root. Nodes that derive from the root will point back to the root.

func (*Node) Descend

func (n *Node) Descend(names ...string) drill.Node

Descend recursively descends into the unordered child sections matching each given name. Returns nil if a child could not be found at any point.

func (*Node) Fragment

func (n *Node) Fragment() string

Fragment renders the wrapped node and returns the result as a string. Returns an empty string if an error occurs, or the node has no renderer.

func (*Node) FragmentReader

func (n *Node) FragmentReader() (r io.ReadCloser, err error)

FragmentReader returns a ReadCloser that renders the wrapped node.

func (*Node) Len

func (n *Node) Len() int

Len returns the number of child Sections.

func (*Node) Node

func (n *Node) Node() ast.Node

Node returns the wrapped ast.Node.

func (*Node) OrderedChild

func (n *Node) OrderedChild(i int) drill.Node

OrderedChild returns a Node that wraps the ordered child Section at index i. Returns nil if the index is out of bounds.

func (*Node) OrderedChildren

func (n *Node) OrderedChildren() []drill.Node

OrderedChildren returns a list of Nodes that wrap each ordered child Section.

func (*Node) Query

func (n *Node) Query(queries ...interface{}) drill.Node

Query recursively descends into the child nodes that match the given queries. A query is either a string or an int. If an int, then the next node is acquired using the OrderedChild method of the current node. If a string, then the next node is acquired using the UnorderedChild method of the current node. Returns nil if a child could not be found at any point.

func (*Node) Root added in v0.3.0

func (n *Node) Root() *Node

Root returns the original root Node from which the current node derives, or the node itself, if it is the root.

func (*Node) UnorderedChild

func (n *Node) UnorderedChild(name string) drill.Node

UnorderedChild returns a Node that wraps the unordered child Section whose Name is equal to name.

func (*Node) UnorderedChildren

func (n *Node) UnorderedChildren() map[string]drill.Node

UnorderedChildren returns a map of names to Nodes that wrap each unordered child Section.

func (*Node) WalkChildSections

func (n *Node) WalkChildSections(walk func(child *Section) bool)

WalkChildSections traverses each child node that is a Section. Stops if walk returns true.

func (*Node) WithRenderer added in v0.3.0

func (n *Node) WithRenderer(r renderer.Renderer) *Node

WithRenderer returns a copy of the node that uses the given renderer.

type Section

type Section struct {
	ast.BaseBlock

	Heading *ast.Heading
	Name    string
}

Section is an ast.Node that groups nodes into sections based on Headings.

A Section without a Heading is an "orphaned" section. This section contains the nodes that follow the heading of the parent section, and precede the first sub-heading.

func NewSection

func NewSection() *Section

NewSection returns an initialized Section node.

func (*Section) Dump

func (n *Section) Dump(source []byte, level int)

func (*Section) Kind

func (n *Section) Kind() ast.NodeKind

Jump to

Keyboard shortcuts

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