parsren

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 2 Imported by: 0

README

Parsers and renderers

In the beginning, mdrip had its own custom markdown parser and its own custom markdown renderer.

As fun as that was, time passed and folks created many extensions to markdown; tables of contents, mermaid diagrams, etc.

Both parsing and rendering have gotten better dedicated parsers and renders with plugin architectures, exceeding the capabilities of the parser and renderer builtin to mdrip.

So the original parser and renderer was retired, to be replaced by one or both of these:

The MdParserRenderer interface was defined - an mdrip-specific interface. The idea was to slap an adapter over each of these two packages allowing them to implement this interface. Then provide an mdrip command line flag to pick one of the two implementations at run time and inject it.

Work began on adapting gomarkdown/markdown to the interface, but paused when it became clear that yuin/goldmark was working fine. Keeping this arrangement for a while, just in case it becomes desirable to try gomarkdown/markdown again.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MdParserRenderer

type MdParserRenderer interface {
	loader.TreeVisitor
	// RenderedMdFiles is a slice of rendered markdown files
	// in depth-first order.
	RenderedMdFiles() []*RenderedMdFile
	// FilteredBlocks returns all blocks with the given label,
	// from all files in the tree.
	FilteredBlocks(loader.Label) []*loader.CodeBlock
	// Reset resets the parser.  Handy if you want to run another visitation,
	// and don't data to accumulate.
	Reset()
}

MdParserRenderer is a tree visitor that parses and renders markdown. The two operations are closely coupled by a shared abstract syntax tree and shared raw bytes from the source markdown. Usage:

  • Load markdown files into a tree of treeNode.
  • Accept this visitor into the tree.
  • After the call to Accept finishes, consult RenderMdFiles() and/or FilteredBlocks() for whatever purpose.

type RenderedMdFile

type RenderedMdFile struct {
	// Index is a zero-relative unique integer ID of the file for whatever
	// purpose.
	Index int
	// Path is the path to the file.
	Path loader.FilePath
	// Html is the ready-to-rock HTML rendered from the file's markdown.
	Html template.HTML
	// Blocks holds all the code blocks found in the file.
	Blocks []*loader.CodeBlock
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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