Documentation ¶
Overview ¶
This package implements a parser for the subset of the CommonMark spec necessary for us to do server-side processing. It is not a full implementation and lacks many features. But it is complete enough to efficiently and accurately allow us to do what we need to like rewrite image URLs for proxying.
Index ¶
- Variables
- func CharacterReference(ref string) string
- func Inspect(markdown string, f func(interface{}) bool)
- func InspectBlock(block Block, f func(Block) bool)
- func InspectInline(inline Inline, f func(Inline) bool)
- func Parse(markdown string) (*Document, []*ReferenceDefinition)
- func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefinition)
- func RenderBlockHTML(block Block, referenceDefinitions []*ReferenceDefinition) (result string)
- func RenderHTML(markdown string) string
- func RenderInlineHTML(inline Inline) (result string)
- func Unescape(markdown string) string
- type Autolink
- type Block
- type BlockQuote
- func (b *BlockQuote) AddChild(openBlocks []Block) []Block
- func (*BlockQuote) AddLine(indentation int, r Range) bool
- func (*BlockQuote) AllowsBlockStarts() bool
- func (*BlockQuote) Close()
- func (b *BlockQuote) Continuation(indentation int, r Range) *continuation
- func (*BlockQuote) HasTrailingBlankLine() bool
- type CodeSpan
- type ContainerBlock
- type Document
- type FencedCode
- func (b *FencedCode) AddLine(indentation int, r Range) bool
- func (b *FencedCode) AllowsBlockStarts() bool
- func (*FencedCode) Close()
- func (b *FencedCode) Code() (result string)
- func (b *FencedCode) Continuation(indentation int, r Range) *continuation
- func (*FencedCode) HasTrailingBlankLine() bool
- func (b *FencedCode) Info() string
- type FencedCodeLine
- type HardLineBreak
- type IndentedCode
- func (b *IndentedCode) AddLine(indentation int, r Range) bool
- func (b *IndentedCode) AllowsBlockStarts() bool
- func (b *IndentedCode) Close()
- func (b *IndentedCode) Code() (result string)
- func (b *IndentedCode) Continuation(indentation int, r Range) *continuation
- func (*IndentedCode) HasTrailingBlankLine() bool
- type IndentedCodeLine
- type Inline
- type InlineImage
- type InlineLink
- type InlineLinkOrImage
- type Line
- type List
- type ListItem
- type Paragraph
- func (*Paragraph) AddLine(indentation int, r Range) bool
- func (*Paragraph) AllowsBlockStarts() bool
- func (b *Paragraph) Close()
- func (b *Paragraph) Continuation(indentation int, r Range) *continuation
- func (*Paragraph) HasTrailingBlankLine() bool
- func (b *Paragraph) ParseInlines(referenceDefinitions []*ReferenceDefinition) []Inline
- type Range
- type ReferenceDefinition
- type ReferenceImage
- type ReferenceLink
- type ReferenceLinkOrImage
- type SoftLineBreak
- type Text
Constants ¶
This section is empty.
Variables ¶
var (
DefaultUrlSchemes = []string{"http", "https", "ftp", "mailto", "tel"}
)
Functions ¶
func CharacterReference ¶
func Inspect ¶
Inspect traverses the markdown tree in depth-first order. If f returns true, Inspect invokes f recursively for each child of the block or inline, followed by a call of f(nil).
func InspectBlock ¶
InspectBlock traverses the blocks in depth-first order, starting with block. If f returns true, InspectBlock invokes f recursively for each child of the block, followed by a call of f(nil).
func InspectInline ¶
InspectInline traverses the blocks in depth-first order, starting with block. If f returns true, InspectInline invokes f recursively for each child of the block, followed by a call of f(nil).
func Parse ¶
func Parse(markdown string) (*Document, []*ReferenceDefinition)
func ParseBlocks ¶
func ParseBlocks(markdown string, lines []Line) (*Document, []*ReferenceDefinition)
func RenderBlockHTML ¶
func RenderBlockHTML(block Block, referenceDefinitions []*ReferenceDefinition) (result string)
func RenderHTML ¶
RenderHTML produces HTML with the same behavior as the example renderer used in the CommonMark reference materials except for one slight difference: for brevity, no unnecessary whitespace is inserted between elements. The output is not defined by the CommonMark spec, and it exists primarily as an aid in testing.
func RenderInlineHTML ¶
Types ¶
type Autolink ¶
type Autolink struct { Children []Inline RawDestination Range // contains filtered or unexported fields }
func (*Autolink) Destination ¶
type BlockQuote ¶
type BlockQuote struct { Children []Block // contains filtered or unexported fields }
func (*BlockQuote) AddChild ¶
func (b *BlockQuote) AddChild(openBlocks []Block) []Block
func (*BlockQuote) AllowsBlockStarts ¶
func (*BlockQuote) AllowsBlockStarts() bool
func (*BlockQuote) Continuation ¶
func (b *BlockQuote) Continuation(indentation int, r Range) *continuation
func (*BlockQuote) HasTrailingBlankLine ¶
func (*BlockQuote) HasTrailingBlankLine() bool
type ContainerBlock ¶
type Document ¶
type Document struct { Children []Block // contains filtered or unexported fields }
func (*Document) AllowsBlockStarts ¶
func (*Document) AllowsBlockStarts() bool
func (*Document) Continuation ¶
func (*Document) HasTrailingBlankLine ¶
func (*Document) HasTrailingBlankLine() bool
type FencedCode ¶
type FencedCode struct { Indentation int OpeningFence Range RawInfo Range RawCode []FencedCodeLine // contains filtered or unexported fields }
func (*FencedCode) AllowsBlockStarts ¶
func (b *FencedCode) AllowsBlockStarts() bool
func (*FencedCode) Code ¶
func (b *FencedCode) Code() (result string)
func (*FencedCode) Continuation ¶
func (b *FencedCode) Continuation(indentation int, r Range) *continuation
func (*FencedCode) HasTrailingBlankLine ¶
func (*FencedCode) HasTrailingBlankLine() bool
func (*FencedCode) Info ¶
func (b *FencedCode) Info() string
type FencedCodeLine ¶
type HardLineBreak ¶
type HardLineBreak struct {
// contains filtered or unexported fields
}
type IndentedCode ¶
type IndentedCode struct { RawCode []IndentedCodeLine // contains filtered or unexported fields }
func (*IndentedCode) AllowsBlockStarts ¶
func (b *IndentedCode) AllowsBlockStarts() bool
func (*IndentedCode) Close ¶
func (b *IndentedCode) Close()
func (*IndentedCode) Code ¶
func (b *IndentedCode) Code() (result string)
func (*IndentedCode) Continuation ¶
func (b *IndentedCode) Continuation(indentation int, r Range) *continuation
func (*IndentedCode) HasTrailingBlankLine ¶
func (*IndentedCode) HasTrailingBlankLine() bool
type IndentedCodeLine ¶
type Inline ¶
type Inline interface {
IsInline() bool
}
func MergeInlineText ¶
func ParseInlines ¶
func ParseInlines(markdown string, ranges []Range, referenceDefinitions []*ReferenceDefinition) (inlines []Inline)
type InlineImage ¶
type InlineImage struct {
InlineLinkOrImage
}
type InlineLink ¶
type InlineLink struct {
InlineLinkOrImage
}
type InlineLinkOrImage ¶
type InlineLinkOrImage struct { Children []Inline RawDestination Range // contains filtered or unexported fields }
func (*InlineLinkOrImage) Destination ¶
func (i *InlineLinkOrImage) Destination() string
func (*InlineLinkOrImage) Title ¶
func (i *InlineLinkOrImage) Title() string
type List ¶
type List struct { IsLoose bool IsOrdered bool OrderedStart int BulletOrDelimiter byte Children []*ListItem // contains filtered or unexported fields }
func (*List) AllowsBlockStarts ¶
func (*List) AllowsBlockStarts() bool
func (*List) Continuation ¶
func (*List) HasTrailingBlankLine ¶
type ListItem ¶
func (*ListItem) AllowsBlockStarts ¶
func (*ListItem) AllowsBlockStarts() bool
func (*ListItem) Continuation ¶
func (*ListItem) HasTrailingBlankLine ¶
type Paragraph ¶
type Paragraph struct { Text []Range ReferenceDefinitions []*ReferenceDefinition // contains filtered or unexported fields }
func (*Paragraph) AllowsBlockStarts ¶
func (*Paragraph) AllowsBlockStarts() bool
func (*Paragraph) Continuation ¶
func (*Paragraph) HasTrailingBlankLine ¶
func (*Paragraph) HasTrailingBlankLine() bool
func (*Paragraph) ParseInlines ¶
func (b *Paragraph) ParseInlines(referenceDefinitions []*ReferenceDefinition) []Inline
type ReferenceDefinition ¶
type ReferenceDefinition struct { RawDestination Range // contains filtered or unexported fields }
func (*ReferenceDefinition) Destination ¶
func (d *ReferenceDefinition) Destination() string
func (*ReferenceDefinition) Label ¶
func (d *ReferenceDefinition) Label() string
func (*ReferenceDefinition) Title ¶
func (d *ReferenceDefinition) Title() string
type ReferenceImage ¶
type ReferenceImage struct {
ReferenceLinkOrImage
}
type ReferenceLink ¶
type ReferenceLink struct {
ReferenceLinkOrImage
}
type ReferenceLinkOrImage ¶
type ReferenceLinkOrImage struct { *ReferenceDefinition Children []Inline // contains filtered or unexported fields }
type SoftLineBreak ¶
type SoftLineBreak struct {
// contains filtered or unexported fields
}