package parser
import "shirakumo.org/markless/parser"
The standard Parser implementation according to the interface required for directives. This parser supports the full standard feature set including line counting and line break mode handling.
To create a new parser instance, call one of New, NewDefault, NewSafe, or NewMessage.
The main entry point is the standard method Parser.Parse. Also see shirakumo.org/markless.Parse.
Index
- Variables
-
type Parser
- func New(dirs []directives.Constructor, insts []instructions.Constructor, ...) *Parser
- func NewDefault() *Parser
- func NewMessage() *Parser
- func NewNamed(directives []string) (*Parser, error)
- func NewSafe() *Parser
- func (p *Parser) Bottom() directives.StackEntry
- func (p *Parser) Commit(d directives.Directive, c components.Component) directives.Parser
- func (p *Parser) CompoundOption(name string) (directives.OptionType, error)
- func (p *Parser) Directive(name string) (directives.Directive, error)
- func (p *Parser) DispatchBlock(line string, cursor int) directives.Directive
- func (p *Parser) Embed(name string) (directives.EmbedType, error)
- func (p *Parser) EmbedOption(name string) (directives.OptionType, error)
- func (p *Parser) GetLabel(label string) components.Component
- func (p *Parser) Instruction(name string) (directives.InstructionType, error)
- func (p *Parser) LineBreakMode() directives.LineBreakMode
- func (p *Parser) LineNumber() int
- func (p *Parser) Parse(in io.Reader) directives.Parser
- func (p *Parser) ParseLine(line string) directives.Parser
- func (p *Parser) Peek() directives.StackEntry
- func (p *Parser) Pop() directives.StackEntry
- func (p *Parser) Push(d directives.Directive, c components.Component) directives.Parser
- func (p *Parser) ReadBlock(line string, cursor int) int
- func (p *Parser) ReadInline(line string, cursor int, end byte) int
- func (p *Parser) Root() *components.Root
- func (p *Parser) SetLabel(label string, c components.Component) directives.Parser
- func (p *Parser) SetLineBreakMode(mode directives.LineBreakMode)
- func (p *Parser) StackLength() int
- func (p *Parser) Top() directives.StackEntry
- func (p *Parser) Unwind(until int) directives.Parser
Variables
var DefaultCompoundOptions = []compounds.OptionConstructor{ compounds.NewBold, compounds.NewItalic, compounds.NewUnderline, compounds.NewStrikethrough, compounds.NewSpoiler, compounds.NewSize, compounds.NewColor, compounds.NewFont, compounds.NewLink, compounds.NewInternalLink, }
Set of default compound options as specified by Markless.
var DefaultDirectives = []directives.Constructor{ directives.NewEmbed, directives.NewBlockquote, directives.NewBlockquoteHeader, directives.NewOrderedList, directives.NewUnorderedList, directives.NewCodeBlock, directives.NewFootnote, directives.NewAlignLeft, directives.NewAlignRight, directives.NewCenter, directives.NewJustify, directives.NewHeader, directives.NewHorizontalRule, directives.NewComment, directives.NewInstruction, directives.NewParagraph, directives.NewCompound, directives.NewBold, directives.NewItalic, directives.NewUnderline, directives.NewStrikethrough, directives.NewSupertext, directives.NewSubtext, directives.NewCode, directives.NewURL, directives.NewFootnoteReference, directives.NewDashes, directives.NewNewline, }
Set of default directives specified by Markless.
var DefaultEmbedOptions = []embeds.OptionConstructor{ embeds.NewLoop, embeds.NewAutoplay, embeds.NewWidth, embeds.NewHeight, embeds.NewFloat, embeds.NewLabel, embeds.NewDescription, embeds.NewCaption, embeds.NewLink, embeds.NewOptions, embeds.NewLanguage, embeds.NewEncoding, embeds.NewStart, embeds.NewEnd, }
Set of default embed options as specified by Markless.
var DefaultEmbeds = []embeds.Constructor{ embeds.NewImage, embeds.NewAudio, embeds.NewVideo, embeds.NewSource, }
Set of default embed types as specified by Markless.
var DefaultInstructions = []instructions.Constructor{ instructions.NewSet, instructions.NewInfo, instructions.NewError, instructions.NewDisable, instructions.NewEnable, instructions.NewLabel, instructions.NewRaw, instructions.NewInclude, }
Set of default directives as specified by Markless.
var MessageDirectives = []directives.Constructor{ directives.NewEmbed, directives.NewBlockquote, directives.NewBlockquoteHeader, directives.NewOrderedList, directives.NewUnorderedList, directives.NewCodeBlock, directives.NewHeader, directives.NewHorizontalRule, directives.NewParagraph, directives.NewCompound, directives.NewBold, directives.NewItalic, directives.NewUnderline, directives.NewStrikethrough, directives.NewSupertext, directives.NewSubtext, directives.NewCode, directives.NewURL, directives.NewDashes, directives.NewNewline, }
Set of directives safe for use in untrusted user messages. Notably this excludes things like the instruction, comments, and footnote directives.
var MessageEmbedOptions = []embeds.OptionConstructor{ embeds.NewLoop, embeds.NewWidth, embeds.NewHeight, embeds.NewFloat, embeds.NewLabel, embeds.NewDescription, embeds.NewCaption, embeds.NewLink, }
Set of embed options safe for use in untrusted user messages. Notably this excludes options related to the source embed and autoplay.
var MessageEmbeds = []embeds.Constructor{ embeds.NewImage, embeds.NewAudio, embeds.NewVideo, }
Set of instructions safe for use in untrusted user messages. Notably this excludes the source embed, as it could touch the file system.
var MessageInstructions = []instructions.Constructor{}
Set of instructions safe for use in untrusted user messages. This is the empty set.
var SafeEmbedOptions = []embeds.OptionConstructor{ embeds.NewLoop, embeds.NewAutoplay, embeds.NewWidth, embeds.NewHeight, embeds.NewFloat, embeds.NewLabel, embeds.NewDescription, embeds.NewCaption, embeds.NewLink, }
Set of embed options safe for use in untrusted user files. Notably this excludes options related to the source embed.
var SafeEmbeds = []embeds.Constructor{ embeds.NewImage, embeds.NewAudio, embeds.NewVideo, }
Set of instructions safe for use in untrusted user files. Notably this excludes the source embed, as it could touch the file system.
var SafeInstructions = []instructions.Constructor{ instructions.NewSet, instructions.NewInfo, instructions.NewError, instructions.NewDisable, instructions.NewEnable, instructions.NewLabel, }
Set of instructions safe for use in untrusted user files. Notably this excludes things that could touch the file system like include and raw.
Types
type Parser
type Parser struct { // contains filtered or unexported fields }
Representation of a standard parser. Implements the directives.Parser interface. To construct an instance, please use New, NewDefault, NewSafe, or NewMessage.
func New
func New(dirs []directives.Constructor, insts []instructions.Constructor, embeds []embeds.Constructor, embedOptions []embeds.OptionConstructor, compoundOptions []compounds.OptionConstructor) *Parser
Constructs a new Parser instance. The dirs specify the directives the parser will understand. Part of those directives **must** always be the paragraph directive, via directives.NewParagraph.
The insts specify the instructions that the instruction directive will understand. If the instruction directive is omitted, this option will have no effect.
The embeds specify the embed types that the embed directive will understand. Note that any embed directive outside this set will still be permitted, though no embed component will be output. If the embed directive is omitted, this option will have no effect.
The embedOptions specify the options that may be passed to an embed. Any option outside this set will be ignored. If the embed directive is omitted, this option will have no effect.
The compoundOptions specify the options that may be passed to a compound. Any option outside this set will be ignored. If the compound directive is omitted, this option will have no effect.
For information on the available methods, see directives.Parser
func NewDefault
func NewDefault() *Parser
Constructs a new parser using DefaultDirectives, DefaultInstructions, DefaultEmbeds, DefaultEmbedOptions, DefaultCompoundOptions
func NewMessage
func NewMessage() *Parser
Constructs a new parser using MessageDirectives, MessageInstructions, MessageEmbeds, MessageEmbedOptions, DefaultCompoundOptions
func NewNamed
func NewNamed(directives []string) (*Parser, error)
func NewSafe
func NewSafe() *Parser
Constructs a new parser using DefaultDirectives, SafeInstructions, SafeEmbeds, SafeEmbedOptions, DefaultCompoundOptions
func (*Parser) Bottom
func (p *Parser) Bottom() directives.StackEntry
Returns the bottom stack entry. This must always contain a directives.Root and components.Root.
func (*Parser) Commit
func (p *Parser) Commit(d directives.Directive, c components.Component) directives.Parser
Commits the given directive and component to the parser. This inserts the component as a child into the current top component and then invokes Parser.Push.
func (*Parser) CompoundOption
func (p *Parser) CompoundOption(name string) (directives.OptionType, error)
Retruns the compound option type of the requested name. If not found, nil and a directives.Error is returned.
func (*Parser) Directive
func (p *Parser) Directive(name string) (directives.Directive, error)
Retruns the directive of the requested name. If not found, nil and a directives.Error is returned.
func (*Parser) DispatchBlock
func (p *Parser) DispatchBlock(line string, cursor int) directives.Directive
Try to dispatch to a new block directive. This is always successful as it, in the very least, returns the directives.Paragraph directive.
func (*Parser) Embed
func (p *Parser) Embed(name string) (directives.EmbedType, error)
Retruns the embed type of the requested name. If not found, nil and a directives.Error is returned.
func (*Parser) EmbedOption
func (p *Parser) EmbedOption(name string) (directives.OptionType, error)
Retruns the embed option type of the requested name. If not found, nil and a directives.Error is returned.
func (*Parser) GetLabel
func (p *Parser) GetLabel(label string) components.Component
Retrieve the component associated with the given label name, if any.
func (*Parser) Instruction
func (p *Parser) Instruction(name string) (directives.InstructionType, error)
Retruns the instruction type of the requested name. If not found, nil and a directives.Error is returned.
func (*Parser) LineBreakMode
func (p *Parser) LineBreakMode() directives.LineBreakMode
Retrieves the line break handling mode.
func (*Parser) LineNumber
func (p *Parser) LineNumber() int
func (*Parser) Parse
func (p *Parser) Parse(in io.Reader) directives.Parser
Reads from the reader line by line and calls Parser.ParseLine on each. Once all lines have been processed, calls Parser.Unwind to complete the document. Returns the Parser again.
func (*Parser) ParseLine
func (p *Parser) ParseLine(line string) directives.Parser
Parses a single line of content. This will also handle line break escapes. Once a full, unescaped line has been assembled, the actual parsing machinery is invoked. This will cause the usual methods on relevant directives.Directive s to be invoked. Please see the directive interface and the Markless specification for closer description of the machinery.
func (*Parser) Peek
func (p *Parser) Peek() directives.StackEntry
Returns the second to topmost stack entry.
func (*Parser) Pop
func (p *Parser) Pop() directives.StackEntry
Removes the topmost stack entry and returns it.
func (*Parser) Push
func (p *Parser) Push(d directives.Directive, c components.Component) directives.Parser
Creates a new stack entry for the given directive and component and pushes that entry to the top. Retruns the parser again.
func (*Parser) ReadBlock
func (p *Parser) ReadBlock(line string, cursor int) int
Dispatches a block according to Parser.DispatchBlock and then calls directives.Directive.Begin.
func (*Parser) ReadInline
func (p *Parser) ReadInline(line string, cursor int, end byte) int
Handles the inline directive dispatch logic and consumption of textual content.
func (*Parser) Root
func (p *Parser) Root() *components.Root
Returns the components.Root.
func (*Parser) SetLabel
func (p *Parser) SetLabel(label string, c components.Component) directives.Parser
Associate the component c with the given label name.
func (*Parser) SetLineBreakMode
func (p *Parser) SetLineBreakMode(mode directives.LineBreakMode)
Updates the line break handling mode.
func (*Parser) StackLength
func (p *Parser) StackLength() int
Returns the current count of stack entries. Should always be at least 1.
func (*Parser) Top
func (p *Parser) Top() directives.StackEntry
Returns the topmost stack entry.
func (*Parser) Unwind
func (p *Parser) Unwind(until int) directives.Parser
Unwinds the stack until the given stack height. For each unwind it calls Parser.Pop followed by invoking directives.Directive.End on the directive and component of that stack entry.