package parser

Import Path
	github.com/yuin/goldmark/parser (on go.dev)

Dependency Relation
	imports 10 packages, and imported by 5 packages


Package-Level Type Names (total 60, in which 26 are exported)
/* sort exporteds by: | */
ASTTransformer transforms entire Markdown document AST tree. Transform transforms the given AST tree. *golang.org/x/pkgsite/internal/postgres.ASTTransformer func github.com/yuin/goldmark/extension.NewFootnoteASTTransformer() ASTTransformer func github.com/yuin/goldmark/extension.NewTableASTTransformer() ASTTransformer
An Attribute is an attribute of the markdown elements Name []byte Value interface{}
An Attributes is a collection of attributes. Find returns a (value, true) if an attribute correspond with given name is found, otherwise (nil, false). func ParseAttributes(reader text.Reader) (Attributes, bool)
A Block struct holds a node and correspond parser pair. Node is a BlockNode. Parser is a BlockParser. func Context.LastOpenedBlock() Block func Context.OpenedBlocks() []Block func Context.SetOpenedBlocks([]Block)
A BlockParser interface parses a block level element like Paragraph, List, Blockquote etc. CanAcceptIndentedLine returns true if the parser can open new node when the given line is being indented more than 3 spaces. CanInterruptParagraph returns true if the parser can interrupt paragraphs, otherwise false. Close will be called when the parser returns Close. Continue parses the current line and returns a result of parsing. Continue must not parse beyond the current line. If Continue has been able to parse the current line, Continue must advance a reader position by consumed byte length. If Continue has not been able to parse the current line, Continue should returns Close. If Continue has been able to parse the current line, Continue should returns (Continue | NoChildren) or (Continue | HasChildren) Open parses the current line and returns a result of parsing. Open must not parse beyond the current line. If Open has been able to parse the current line, Open must advance a reader position by consumed byte length. If Open has not been able to parse the current line, Open should returns (nil, NoChildren). If Open has been able to parse the current line, Open should returns a new Block node and returns HasChildren or NoChildren. Trigger returns a list of characters that triggers Parse method of this parser. If Trigger returns a nil, Open will be called with any lines. func NewATXHeadingParser(opts ...HeadingOption) BlockParser func NewBlockquoteParser() BlockParser func NewCodeBlockParser() BlockParser func NewFencedCodeBlockParser() BlockParser func NewHTMLBlockParser() BlockParser func NewListItemParser() BlockParser func NewListParser() BlockParser func NewParagraphParser() BlockParser func NewSetextHeadingParser(opts ...HeadingOption) BlockParser func NewThematicBreakParser() BlockParser func github.com/yuin/goldmark/extension.NewDefinitionDescriptionParser() BlockParser func github.com/yuin/goldmark/extension.NewDefinitionListParser() BlockParser func github.com/yuin/goldmark/extension.NewFootnoteBlockParser() BlockParser
A CloseBlocker interface is a callback function that will be called when block is closed in the inline parsing. CloseBlock will be called when a block is closed.
A Config struct is a data structure that holds configuration of the Parser. // <ASTTransformer> // <BlockParser> // <InlineParser> Options map[OptionName]interface{} // <ParagraphTransformer> func NewConfig() *Config func HeadingOption.SetParserOption(*Config) func Option.SetParserOption(*Config) func github.com/yuin/goldmark/extension.LinkifyOption.SetParserOption(*Config) func github.com/yuin/goldmark/extension.TypographerOption.SetParserOption(*Config) func github.com/yuin/goldmark-emoji.ParserOption.SetParserOption(*Config)
A Context interface holds a information that are necessary to parse Markdown text. AddReference adds the given reference to this context. BlockIndent returns an indent width on current line. This value is valid only for BlockParser.Open. BlockIndent returns -1 if current line is blank. BlockOffset returns a first non-space character position on current line. This value is valid only for BlockParser.Open. BlockOffset returns -1 if current line is blank. ClearDelimiters clears the current delimiter list. ComputeIfAbsent computes a value if a value associated with the given key is absent and returns the value. FirstDelimiter returns a first delimiter of the current delimiter list. Get returns a value associated with the given key. IDs returns a collection of the element ids. IsInLinkLabel returns true if current position seems to be in link label. LastDelimiter returns a last delimiter of the current delimiter list. LastOpenedBlock returns a last node that is currently in parsing. OpenedBlocks returns a list of nodes that are currently in parsing. PushDelimiter appends the given delimiter to the tail of the current delimiter list. Reference returns (a reference, true) if a reference associated with the given label exists, otherwise (nil, false). References returns a list of references. RemoveDelimiter removes the given delimiter from the current delimiter list. Set sets the given value to the context. BlockIndent sets an indent width on current line. This value is valid only for BlockParser.Open. BlockOffset sets a first non-space character position on current line. This value is valid only for BlockParser.Open. SetOpenedBlocks sets a list of nodes that are currently in parsing. String implements Stringer. T : expvar.Var T : fmt.Stringer func NewContext(options ...ContextOption) Context func ProcessDelimiters(bottom ast.Node, pc Context) func WithContext(context Context) ParseOption func ASTTransformer.Transform(node *ast.Document, reader text.Reader, pc Context) func BlockParser.Close(node ast.Node, reader text.Reader, pc Context) func BlockParser.Continue(node ast.Node, reader text.Reader, pc Context) State func BlockParser.Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) func CloseBlocker.CloseBlock(parent ast.Node, block text.Reader, pc Context) func InlineParser.Parse(parent ast.Node, block text.Reader, pc Context) ast.Node func ParagraphTransformer.Transform(node *ast.Paragraph, reader text.Reader, pc Context) func golang.org/x/pkgsite/internal/postgres.(*ASTTransformer).Transform(node *ast.Document, reader text.Reader, pc Context)
A ContextConfig struct is a data structure that holds configuration of the Context. IDs IDs
ContextKey is a key that is used to set arbitrary values to the context. func NewContextKey() ContextKey func Context.ComputeIfAbsent(ContextKey, func() interface{}) interface{} func Context.Get(ContextKey) interface{} func Context.Set(ContextKey, interface{}) var ContextKeyMax
An ContextOption is a functional option type for the Context. func WithIDs(ids IDs) ContextOption func NewContext(options ...ContextOption) Context
A Delimiter struct represents a delimiter like '*' of the Markdown text. BaseInline ast.BaseInline BaseInline.BaseNode ast.BaseNode CanClose is set true if this delimiter can close a span for a new node. See https://spec.commonmark.org/0.29/#can-open-emphasis for details. CanOpen is set true if this delimiter can open a span for a new node. See https://spec.commonmark.org/0.29/#can-open-emphasis for details. Char is a character of this delimiter. Length is a remaining length of this delimiter. NextDelimiter is a next sibling delimiter node of this delimiter. OriginalLength is a original length of this delimiter. PreviousDelimiter is a previous sibling delimiter node of this delimiter. Processor is a DelimiterProcessor associated with this delimiter. Segment text.Segment AppendChild implements Node.AppendChild . Attribute implements Node.Attribute. AttributeString implements Node.AttributeString. Attributes implements Node.Attributes CalcComsumption calculates how many characters should be used for opening a new span correspond to given closer. ChildCount implements Node.ChildCount . ConsumeCharacters consumes delimiters. Dump implements Node.Dump. FirstChild implements Node.FirstChild . HasBlankPreviousLines implements Node.HasBlankPreviousLines. HasChildren implements Node.HasChildren . Inline implements Inline.Inline. InsertAfter implements Node.InsertAfter . InsertBefore implements Node.InsertBefore . IsRaw implements Node.IsRaw Kind implements Node.Kind LastChild implements Node.LastChild . Lines implements Node.Lines NextSibling implements Node.NextSibling . OwnerDocument implements Node.OwnerDocument Parent implements Node.Parent . PreviousSibling implements Node.PreviousSibling . RemoveAttributes implements Node.RemoveAttributes RemoveChild implements Node.RemoveChild . RemoveChildren implements Node.RemoveChildren . ReplaceChild implements Node.ReplaceChild . SetAttribute implements Node.SetAttribute. SetAttributeString implements Node.SetAttributeString SetBlankPreviousLines implements Node.SetBlankPreviousLines. SetLines implements Node.SetLines SetNextSibling implements Node.SetNextSibling . SetParent implements Node.SetParent . SetPreviousSibling implements Node.SetPreviousSibling . SortChildren implements Node.SortChildren Text implements Node.Text Type implements Node.Type *T : github.com/yuin/goldmark/ast.Node func NewDelimiter(canOpen, canClose bool, length int, char byte, processor DelimiterProcessor) *Delimiter func ScanDelimiter(line []byte, before rune, min int, processor DelimiterProcessor) *Delimiter func Context.FirstDelimiter() *Delimiter func Context.LastDelimiter() *Delimiter func Context.PushDelimiter(delimiter *Delimiter) func Context.RemoveDelimiter(d *Delimiter) func (*Delimiter).CalcComsumption(closer *Delimiter) int func DelimiterProcessor.CanOpenCloser(opener, closer *Delimiter) bool
A DelimiterProcessor interface provides a set of functions about Delimiter nodes. CanOpenCloser returns true if given opener can close given closer, otherwise false. IsDelimiter returns true if given character is a delimiter, otherwise false. OnMatch will be called when new matched delimiter found. OnMatch should return a new Node correspond to the matched delimiter. func NewDelimiter(canOpen, canClose bool, length int, char byte, processor DelimiterProcessor) *Delimiter func ScanDelimiter(line []byte, before rune, min int, processor DelimiterProcessor) *Delimiter
A HeadingConfig struct is a data structure that holds configuration of the renderers related to headings. Attribute bool AutoHeadingID bool SetOption implements SetOptioner. *T : SetOptioner func HeadingOption.SetHeadingOption(*HeadingConfig)
A HeadingOption interface sets options for heading parsers. ( T) SetHeadingOption(*HeadingConfig) ( T) SetParserOption(*Config) T : Option func WithAutoHeadingID() HeadingOption func WithHeadingAttribute() HeadingOption func NewATXHeadingParser(opts ...HeadingOption) BlockParser func NewSetextHeadingParser(opts ...HeadingOption) BlockParser
An IDs interface is a collection of the element ids. Generate generates a new element id. Put puts a given element id to the used ids table. func Context.IDs() IDs func WithIDs(ids IDs) ContextOption
An InlineParser interface parses an inline level element like CodeSpan, Link etc. Parse parse the given block into an inline node. Parse can parse beyond the current line. If Parse has been able to parse the current line, it must advance a reader position by consumed byte length. Trigger returns a list of characters that triggers Parse method of this parser. Trigger characters must be a punctuation or a halfspace. Halfspaces triggers this parser when character is any spaces characters or a head of line func NewAutoLinkParser() InlineParser func NewCodeSpanParser() InlineParser func NewEmphasisParser() InlineParser func NewLinkParser() InlineParser func NewRawHTMLParser() InlineParser func github.com/yuin/goldmark/extension.NewFootnoteParser() InlineParser func github.com/yuin/goldmark/extension.NewLinkifyParser(opts ...extension.LinkifyOption) InlineParser func github.com/yuin/goldmark/extension.NewStrikethroughParser() InlineParser func github.com/yuin/goldmark/extension.NewTaskCheckBoxParser() InlineParser func github.com/yuin/goldmark/extension.NewTypographerParser(opts ...extension.TypographerOption) InlineParser func github.com/yuin/goldmark-emoji.NewParser(opts ...emoji.ParserOption) InlineParser
An Option interface is a functional option type for the Parser. ( T) SetParserOption(*Config) HeadingOption (interface) github.com/yuin/goldmark/extension.LinkifyOption (interface) github.com/yuin/goldmark/extension.TypographerOption (interface) github.com/yuin/goldmark-emoji.ParserOption (interface) func WithASTTransformers(ps ...util.PrioritizedValue) Option func WithAttribute() Option func WithBlockParsers(bs ...util.PrioritizedValue) Option func WithInlineParsers(bs ...util.PrioritizedValue) Option func WithOption(name OptionName, value interface{}) Option func WithParagraphTransformers(ps ...util.PrioritizedValue) Option func NewParser(options ...Option) Parser func Parser.AddOptions(...Option) func github.com/yuin/goldmark.WithParserOptions(opts ...Option) goldmark.Option
OptionName is a name of parser options. func WithOption(name OptionName, value interface{}) Option func (*HeadingConfig).SetOption(name OptionName, value interface{}) func SetOptioner.SetOption(name OptionName, value interface{}) func github.com/yuin/goldmark/extension.(*LinkifyConfig).SetOption(name OptionName, value interface{}) func github.com/yuin/goldmark/extension.(*TypographerConfig).SetOption(name OptionName, value interface{}) func github.com/yuin/goldmark-emoji.(*ParserConfig).SetOption(name OptionName, value interface{})
A ParagraphTransformer transforms parsed Paragraph nodes. For example, link references are searched in parsed Paragraphs. Transform transforms the given paragraph. func github.com/yuin/goldmark/extension.NewTableParagraphTransformer() ParagraphTransformer
A ParseConfig struct is a data structure that holds configuration of the Parser.Parse. Context Context
A ParseOption is a functional option type for the Parser.Parse. func WithContext(context Context) ParseOption func Parser.Parse(reader text.Reader, opts ...ParseOption) ast.Node func github.com/yuin/goldmark.Convert(source []byte, w io.Writer, opts ...ParseOption) error func github.com/yuin/goldmark.Markdown.Convert(source []byte, writer io.Writer, opts ...ParseOption) error
A Parser interface parses Markdown text into AST nodes. AddOption adds the given option to this parser. Parse parses the given Markdown text into AST nodes. func NewParser(options ...Option) Parser func github.com/yuin/goldmark.DefaultParser() Parser func github.com/yuin/goldmark.Markdown.Parser() Parser func github.com/yuin/goldmark.WithParser(p Parser) goldmark.Option func github.com/yuin/goldmark.Markdown.SetParser(Parser)
A Reference interface represents a link reference in Markdown text. Destination returns a destination(URL) of the reference. Label returns a label of the reference. String implements Stringer. Title returns a title of the reference. T : expvar.Var T : fmt.Stringer func NewReference(label, destination, title []byte) Reference func Context.Reference(label string) (Reference, bool) func Context.References() []Reference func Context.AddReference(Reference)
A SetOptioner interface sets the given option to the object. SetOption sets the given option to the object. Unacceptable options may be passed. Thus implementations must ignore unacceptable options. *HeadingConfig *github.com/yuin/goldmark/extension.LinkifyConfig *github.com/yuin/goldmark/extension.TypographerConfig *github.com/yuin/goldmark-emoji.ParserConfig
State represents parser's state. State is designed to use as a bit flag. func BlockParser.Continue(node ast.Node, reader text.Reader, pc Context) State func BlockParser.Open(parent ast.Node, reader text.Reader, pc Context) (ast.Node, State) const Close const Continue const HasChildren const NoChildren const RequireParagraph
Package-Level Functions (total 62, in which 37 are exported)
DefaultBlockParsers returns a new list of default BlockParsers. Priorities of default BlockParsers are: SetextHeadingParser, 100 ThematicBreakParser, 200 ListParser, 300 ListItemParser, 400 CodeBlockParser, 500 ATXHeadingParser, 600 FencedCodeBlockParser, 700 BlockquoteParser, 800 HTMLBlockParser, 900 ParagraphParser, 1000
DefaultInlineParsers returns a new list of default InlineParsers. Priorities of default InlineParsers are: CodeSpanParser, 100 LinkParser, 200 AutoLinkParser, 300 RawHTMLParser, 400 EmphasisParser, 500
DefaultParagraphTransformers returns a new list of default ParagraphTransformers. Priorities of default ParagraphTransformers are: LinkReferenceParagraphTransformer, 100
NewATXHeadingParser return a new BlockParser that can parse ATX headings.
NewAutoLinkParser returns a new InlineParser that parses autolinks surrounded by '<' and '>' .
NewBlockquoteParser returns a new BlockParser that parses blockquotes.
NewCodeBlockParser returns a new BlockParser that parses code blocks.
NewCodeSpanParser return a new InlineParser that parses inline codes surrounded by '`' .
NewConfig returns a new Config.
NewContext returns a new Context.
NewContextKey return a new ContextKey value.
NewDelimiter returns a new Delimiter node.
NewEmphasisParser return a new InlineParser that parses emphasises.
NewFencedCodeBlockParser returns a new BlockParser that parses fenced code blocks.
NewHTMLBlockParser return a new BlockParser that can parse html blocks.
NewLinkParser return a new InlineParser that parses links.
NewListItemParser returns a new BlockParser that parses list items.
NewListParser returns a new BlockParser that parses lists. This parser must take precedence over the ListItemParser.
NewParagraphParser returns a new BlockParser that parses paragraphs.
NewParser returns a new Parser with given options.
NewRawHTMLParser return a new InlineParser that can parse inline htmls
NewReference returns a new Reference.
NewSetextHeadingParser return a new BlockParser that can parse Setext headings.
NewThematicBreakParser returns a new BlockParser that parses thematic breaks.
ParseAttributes parses attributes into a map. ParseAttributes returns a parsed attributes and true if could parse attributes, otherwise nil and false.
ProcessDelimiters processes the delimiter list in the context. Processing will be stop when reaching the bottom. If you implement an inline parser that can have other inline nodes as children, you should call this function when nesting span has closed.
ScanDelimiter scans a delimiter by given DelimiterProcessor.
WithASTTransformers is a functional option that allow you to add ASTTransformers to the parser.
WithAttribute is a functional option that enables custom attributes.
WithAutoHeadingID is a functional option that enables custom heading ids and auto generated heading ids.
WithBlockParsers is a functional option that allow you to add BlockParsers to the parser.
WithContext is a functional option that allow you to override a default context.
WithHeadingAttribute is a functional option that enables custom heading attributes.
WithIDs is a functional option for the Context.
WithInlineParsers is a functional option that allow you to add InlineParsers to the parser.
WithOption is a functional option that allow you to set an arbitrary option to the parser.
WithParagraphTransformers is a functional option that allow you to add ParagraphTransformers to the parser.
Package-Level Variables (total 50, in which 2 are exported)
ContextKeyMax is a maximum value of the ContextKey.
LinkReferenceParagraphTransformer is a ParagraphTransformer implementation that parses and extracts link reference from paragraphs.
Package-Level Constants (total 14, in which 5 are exported)
Close indicates parser cannot parse anymore.
Continue indicates parser can continue parsing.
HasChildren indicates parser may have child blocks.
NoChildren indicates parser does not have child blocks.
RequireParagraph indicates parser requires that the last node must be a paragraph and is not converted to other nodes by ParagraphTransformers.