markdown

package
v5.3.1+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2018 License: AGPL-3.0, Apache-2.0 Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	DefaultUrlSchemes = []string{"http", "https", "ftp", "mailto", "tel"}
)

Functions

func CharacterReference

func CharacterReference(ref string) string

func Inspect

func Inspect(markdown string, f func(interface{}) bool)

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

func InspectBlock(block Block, f func(Block) bool)

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

func InspectInline(inline Inline, f func(Inline) bool)

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

func RenderHTML(markdown string) string

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

func RenderInlineHTML(inline Inline) (result string)

func Unescape

func Unescape(markdown string) string

Types

type Autolink struct {
	Children []Inline

	RawDestination Range
	// contains filtered or unexported fields
}

func (*Autolink) Destination

func (i *Autolink) Destination() string

func (Autolink) IsInline

func (Autolink) IsInline() bool

type Block

type Block interface {
	Continuation(indentation int, r Range) *continuation
	AddLine(indentation int, r Range) bool
	Close()
	AllowsBlockStarts() bool
	HasTrailingBlankLine() bool
}

type BlockQuote

type BlockQuote struct {
	Children []Block
	// contains filtered or unexported fields
}

func (*BlockQuote) AddChild

func (b *BlockQuote) AddChild(openBlocks []Block) []Block

func (*BlockQuote) AddLine

func (*BlockQuote) AddLine(indentation int, r Range) bool

func (*BlockQuote) AllowsBlockStarts

func (*BlockQuote) AllowsBlockStarts() bool

func (*BlockQuote) Close

func (*BlockQuote) Close()

func (*BlockQuote) Continuation

func (b *BlockQuote) Continuation(indentation int, r Range) *continuation

func (*BlockQuote) HasTrailingBlankLine

func (*BlockQuote) HasTrailingBlankLine() bool

type CodeSpan

type CodeSpan struct {
	Code string
	// contains filtered or unexported fields
}

func (CodeSpan) IsInline

func (CodeSpan) IsInline() bool

type ContainerBlock

type ContainerBlock interface {
	Block
	AddChild(openBlocks []Block) []Block
}

type Document

type Document struct {
	Children []Block
	// contains filtered or unexported fields
}

func (*Document) AddChild

func (b *Document) AddChild(openBlocks []Block) []Block

func (*Document) AddLine

func (*Document) AddLine(indentation int, r Range) bool

func (*Document) AllowsBlockStarts

func (*Document) AllowsBlockStarts() bool

func (*Document) Close

func (*Document) Close()

func (*Document) Continuation

func (b *Document) Continuation(indentation int, r Range) *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) AddLine

func (b *FencedCode) AddLine(indentation int, r Range) bool

func (*FencedCode) AllowsBlockStarts

func (b *FencedCode) AllowsBlockStarts() bool

func (*FencedCode) Close

func (*FencedCode) Close()

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 FencedCodeLine struct {
	Indentation int
	Range       Range
}

type HardLineBreak

type HardLineBreak struct {
	// contains filtered or unexported fields
}

func (HardLineBreak) IsInline

func (HardLineBreak) IsInline() bool

type IndentedCode

type IndentedCode struct {
	RawCode []IndentedCodeLine
	// contains filtered or unexported fields
}

func (*IndentedCode) AddLine

func (b *IndentedCode) AddLine(indentation int, r Range) bool

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 IndentedCodeLine struct {
	Indentation int
	Range       Range
}

type Inline

type Inline interface {
	IsInline() bool
}

func MergeInlineText

func MergeInlineText(inlines []Inline) []Inline

func ParseInlines

func ParseInlines(markdown string, ranges []Range, referenceDefinitions []*ReferenceDefinition) (inlines []Inline)

type InlineImage

type InlineImage struct {
	InlineLinkOrImage
}

func (InlineImage) IsInline

func (InlineImage) IsInline() bool
type InlineLink struct {
	InlineLinkOrImage
}

func (InlineLink) IsInline

func (InlineLink) IsInline() bool

type InlineLinkOrImage

type InlineLinkOrImage struct {
	Children []Inline

	RawDestination Range
	// contains filtered or unexported fields
}

func (*InlineLinkOrImage) Destination

func (i *InlineLinkOrImage) Destination() string

func (InlineLinkOrImage) IsInline

func (InlineLinkOrImage) IsInline() bool

func (*InlineLinkOrImage) Title

func (i *InlineLinkOrImage) Title() string

type Line

type Line struct {
	Range
}

func ParseLines

func ParseLines(markdown string) (lines []Line)

type List

type List struct {
	IsLoose           bool
	IsOrdered         bool
	OrderedStart      int
	BulletOrDelimiter byte
	Children          []*ListItem
	// contains filtered or unexported fields
}

func (*List) AddChild

func (b *List) AddChild(openBlocks []Block) []Block

func (*List) AddLine

func (b *List) AddLine(indentation int, r Range) bool

func (*List) AllowsBlockStarts

func (*List) AllowsBlockStarts() bool

func (*List) Close

func (b *List) Close()

func (*List) Continuation

func (b *List) Continuation(indentation int, r Range) *continuation

func (*List) HasTrailingBlankLine

func (b *List) HasTrailingBlankLine() bool

type ListItem

type ListItem struct {
	Indentation int
	Children    []Block
	// contains filtered or unexported fields
}

func (*ListItem) AddChild

func (b *ListItem) AddChild(openBlocks []Block) []Block

func (*ListItem) AddLine

func (b *ListItem) AddLine(indentation int, r Range) bool

func (*ListItem) AllowsBlockStarts

func (*ListItem) AllowsBlockStarts() bool

func (*ListItem) Close

func (*ListItem) Close()

func (*ListItem) Continuation

func (b *ListItem) Continuation(indentation int, r Range) *continuation

func (*ListItem) HasTrailingBlankLine

func (b *ListItem) HasTrailingBlankLine() bool

type Paragraph

type Paragraph struct {
	Text                 []Range
	ReferenceDefinitions []*ReferenceDefinition
	// contains filtered or unexported fields
}

func (*Paragraph) AddLine

func (*Paragraph) AddLine(indentation int, r Range) bool

func (*Paragraph) AllowsBlockStarts

func (*Paragraph) AllowsBlockStarts() bool

func (*Paragraph) Close

func (b *Paragraph) Close()

func (*Paragraph) Continuation

func (b *Paragraph) Continuation(indentation int, r Range) *continuation

func (*Paragraph) HasTrailingBlankLine

func (*Paragraph) HasTrailingBlankLine() bool

func (*Paragraph) ParseInlines

func (b *Paragraph) ParseInlines(referenceDefinitions []*ReferenceDefinition) []Inline

type Range

type Range struct {
	Position int
	End      int
}

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
}

func (ReferenceImage) IsInline

func (ReferenceImage) IsInline() bool
type ReferenceLink struct {
	ReferenceLinkOrImage
}

func (ReferenceLink) IsInline

func (ReferenceLink) IsInline() bool

type ReferenceLinkOrImage

type ReferenceLinkOrImage struct {
	*ReferenceDefinition

	Children []Inline
	// contains filtered or unexported fields
}

func (ReferenceLinkOrImage) IsInline

func (ReferenceLinkOrImage) IsInline() bool

type SoftLineBreak

type SoftLineBreak struct {
	// contains filtered or unexported fields
}

func (SoftLineBreak) IsInline

func (SoftLineBreak) IsInline() bool

type Text

type Text struct {
	Text  string
	Range Range
	// contains filtered or unexported fields
}

func (Text) IsInline

func (Text) IsInline() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL