Documentation ¶
Overview ¶
Package parser implements parser for markdown text that generates AST (abstract syntax tree).
Index ¶
- Variables
- func IsAlnum(c byte) bool
- func IsCallout(data []byte) (id []byte, consumed int)
- func IsEmpty(data []byte) int
- func IsLetter(c byte) bool
- func IsPunctuation(c byte) bool
- func IsSafeURL(url []byte) bool
- func IsSpace(c byte) bool
- func LinesUntilEmpty(data []byte) int
- func NormalizeNewlines(d []byte) []byte
- type BlockFunc
- type Flags
- type Options
- type Parser
- type ReadIncludeFunc
- type Reference
- type ReferenceOverrideFunc
Constants ¶
This section is empty.
Variables ¶
var Paths = [][]byte{ []byte("/"), []byte("./"), []byte("../"), }
Functions ¶
func IsAlnum ¶
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 IsCallout ¶
IsCallout detects a callout in the following format: <<N>> Where N is a integer > 0.
func IsPunctuation ¶
IsPunctuation returns true if c is a punctuation symbol.
func IsSafeURL ¶
IsSafeURL returns true if url starts with one of the valid schemes or is a relative path.
func LinesUntilEmpty ¶
LinesUntilEmpty scans lines up to the first empty line.
func NormalizeNewlines ¶
Types ¶
type BlockFunc ¶
BlockFunc allows to registration of a parser function. If successful it returns an ast.Node, a buffer that should be parsed as a block and the the number of bytes consumed.
type Options ¶
type Options struct { ParserHook BlockFunc ReadIncludeFn ReadIncludeFunc Flags Flags // Flags allow customizing parser's behavior }
Options is a collection of supplementary parameters tweaking the behavior of various parts of the parser.
type Parser ¶
type Parser struct { // ReferenceOverride is an optional function callback that is called every // time a reference is resolved. It can be set before starting parsing. // // In Markdown, the link reference syntax can be made to resolve a link to // a reference instead of an inline URL, in one of the following ways: // // * [link text][refid] // * [refid][] // // Usually, the refid is defined at the bottom of the Markdown document. If // this override function is provided, the refid is passed to the override // function first, before consulting the defined refids at the bottom. If // the override function indicates an override did not occur, the refids at // the bottom will be used to fill in the link details. ReferenceOverride ReferenceOverrideFunc // IsSafeURLOverride allows overriding the default URL matcher. URL is // safe if the overriding function returns true. Can be used to extend // the default list of safe URLs. IsSafeURLOverride func(url []byte) bool Opts Options // after parsing, this is AST root of parsed markdown text Doc ast.Node // contains filtered or unexported fields }
Parser is a type that holds extensions and the runtime state used by Parse, and the renderer. You can not use it directly, construct it with New.
func New ¶
func New() *Parser
New creates a markdown parser with CommonExtensions.
You can then call `doc := p.Parse(markdown)` to parse markdown document and `markdown.Render(doc, renderer)` to convert it to another format with a renderer.
func NewWithExtensions ¶
func NewWithExtensions(extension ext.Extensions) *Parser
NewWithExtensions creates a markdown parser with given extensions.
func (*Parser) Block ¶
Parse Block-level data. Note: this function and many that it calls assume that the input buffer ends with a newline.
func (*Parser) Inline ¶
Inline parses text within a block. Each function returns the number of consumed chars.
type ReadIncludeFunc ¶
ReadIncludeFunc should read the file under path and returns the read bytes, from will be set to the name of the current file being parsed. Initially this will be empty. address is the optional address specifier of which lines of the file to return. If this function is not set no data will be read.
type Reference ¶
type Reference struct { // Link is usually the URL the reference points to. Link string // Title is the alternate text describing the link in more detail. Title string // Text is the optional text to override the ref with if the syntax used was // [refid][] Text string }
Reference represents the details of a link. See the documentation in Options for more details on use-case.
type ReferenceOverrideFunc ¶
ReferenceOverrideFunc is expected to be called with a reference string and return either a valid Reference type that the reference string maps to or nil. If overridden is false, the default reference logic will be executed. See the documentation in Options for more details on use-case.