Documentation ¶
Overview ¶
Package parser implements parser for markdown text that generates AST (abstract syntax tree).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 Extensions ¶
type Extensions int
Extensions is a bitmask of enabled parser extensions.
const ( NoExtensions Extensions = 0 NoIntraEmphasis Extensions = 1 << iota // Ignore emphasis markers inside words Tables // Render tables FencedCode // Render fenced code blocks Autolink // Detect embedded URLs that are not explicitly marked Strikethrough // Strikethrough text using ~~test~~ LaxHTMLBlocks // Loosen up HTML block parsing rules SpaceHeadings // Be strict about prefix heading rules HardLineBreak // Translate newlines into line breaks TabSizeEight // Expand tabs to eight spaces instead of four Footnotes // Pandoc-style footnotes NoEmptyLineBeforeBlock // No need to insert an empty line to start a (code, quote, ordered list, unordered list) block HeadingIDs // specify heading IDs with {#id} Titleblock // Titleblock ala pandoc AutoHeadingIDs // Create the heading ID from the text BackslashLineBreak // Translate trailing backslashes into line breaks DefinitionLists // Parse definition lists MathJax // Parse MathJax OrderedListStart // Keep track of the first number used when starting an ordered list. Attributes // Block Attributes SuperSubscript // Super- and subscript support: 2^10^, H~2~O. Includes // Support including other files. Mmark // Support Mmark syntax, see https://mmark.nl/syntax CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode | Autolink | Strikethrough | SpaceHeadings | HeadingIDs | BackslashLineBreak | DefinitionLists | MathJax )
Bit flags representing markdown parsing extensions. Use | (or) to specify multiple extensions.
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 Opts ParserOptions // 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 Extensions) *Parser
NewWithExtensions creates a markdown parser with given extensions.
func (*Parser) Inline ¶
Inline parses text within a block. Each function returns the number of consumed chars.
type ParserOptions ¶
type ParserOptions struct { ParserHook BlockFunc ReadIncludeFn ReadIncludeFunc Flags Flags // Flags allow customizing the parser's behavior, beyond the extensions which control what is parsed. }
ParserOptions is a collection of supplementary parameters tweaking the behavior of various parts of the parser.
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.