Documentation ¶
Overview ¶
Blackfriday markdown processor.
Translates plain text with simple formatting rules into HTML or LaTeX.
Index ¶
- Constants
- func Markdown(input []byte, renderer Renderer, extensions Extensions) []byte
- func MarkdownBasic(input []byte) []byte
- func MarkdownCommon(input []byte) []byte
- func MarkdownOptions(input []byte, renderer Renderer, opts Options) []byte
- type Extensions
- type Html
- func (r *Html) AutoLink(link []byte, kind LinkType)
- func (r *Html) BeginFootnotes()
- func (r *Html) BeginHeader(level int, id string)
- func (r *Html) BeginList(flags ListType)
- func (r *Html) BeginParagraph()
- func (r *Html) BlockCode(text []byte, lang string)
- func (r *Html) BlockHtml(text []byte)
- func (r *Html) BlockQuote(text []byte)
- func (r *Html) CaptureWrites(processor func()) []byte
- func (r *Html) CodeSpan(text []byte)
- func (r *Html) CopyWrites(processor func()) []byte
- func (r *Html) DocumentFooter()
- func (r *Html) DocumentHeader()
- func (r *Html) DoubleEmphasis(text []byte)
- func (r *Html) Emphasis(text []byte)
- func (r *Html) EndFootnotes()
- func (r *Html) EndHeader(level int, id string, header []byte)
- func (r *Html) EndList(flags ListType)
- func (r *Html) EndParagraph()
- func (r *Html) Entity(entity []byte)
- func (r *Html) FootnoteItem(name, text []byte, flags ListType)
- func (r *Html) FootnoteRef(ref []byte, id int)
- func (r *Html) GetAST() *Node
- func (r *Html) GetFlags() HtmlFlags
- func (r *Html) GetResult() []byte
- func (r *Html) HRule()
- func (r *Html) Image(link []byte, title []byte, alt []byte)
- func (r *Html) LineBreak()
- func (r *Html) Link(link []byte, title []byte, content []byte)
- func (r *Html) ListItem(text []byte, flags ListType)
- func (r *Html) NormalText(text []byte)
- func (r *Html) RawHtmlTag(text []byte)
- func (r *Html) Render(ast *Node) []byte
- func (r *Html) SetAST(ast *Node)
- func (r *Html) Smartypants(text []byte)
- func (r *Html) Smartypants2(text []byte) []byte
- func (r *Html) StrikeThrough(text []byte)
- func (r *Html) Table(header []byte, body []byte, columnData []int)
- func (r *Html) TableCell(out *bytes.Buffer, text []byte, align int)
- func (r *Html) TableHeaderCell(out *bytes.Buffer, text []byte, align int)
- func (r *Html) TableRow(text []byte)
- func (r *Html) TitleBlock(text []byte)
- func (r *Html) TocFinalize()
- func (r *Html) TocHeader(text []byte, level int)
- func (r *Html) TocHeaderWithAnchor(text []byte, level int, anchor string)
- func (r *Html) TripleEmphasis(text []byte)
- func (r *Html) Write(b []byte) (int, error)
- type HtmlFlags
- type HtmlRendererParameters
- type HtmlWriter
- type Latex
- func (r *Latex) AutoLink(link []byte, kind LinkType)
- func (r *Latex) BeginFootnotes()
- func (r *Latex) BeginHeader(level int, id string)
- func (r *Latex) BeginList(flags ListType)
- func (r *Latex) BeginParagraph()
- func (r *Latex) BlockCode(text []byte, lang string)
- func (r *Latex) BlockHtml(text []byte)
- func (r *Latex) BlockQuote(text []byte)
- func (r *Latex) CaptureWrites(processor func()) []byte
- func (r *Latex) CodeSpan(text []byte)
- func (r *Latex) CopyWrites(processor func()) []byte
- func (r *Latex) DocumentFooter()
- func (r *Latex) DocumentHeader()
- func (r *Latex) DoubleEmphasis(text []byte)
- func (r *Latex) Emphasis(text []byte)
- func (r *Latex) EndFootnotes()
- func (r *Latex) EndHeader(level int, id string, header []byte)
- func (r *Latex) EndList(flags ListType)
- func (r *Latex) EndParagraph()
- func (r *Latex) Entity(entity []byte)
- func (r *Latex) FootnoteItem(name, text []byte, flags ListType)
- func (r *Latex) FootnoteRef(ref []byte, id int)
- func (r *Latex) GetAST() *Node
- func (r *Latex) GetFlags() HtmlFlags
- func (r *Latex) GetResult() []byte
- func (r *Latex) HRule()
- func (r *Latex) Image(link []byte, title []byte, alt []byte)
- func (r *Latex) LineBreak()
- func (r *Latex) Link(link []byte, title []byte, content []byte)
- func (r *Latex) ListItem(text []byte, flags ListType)
- func (r *Latex) NormalText(text []byte)
- func (r *Latex) RawHtmlTag(tag []byte)
- func (r *Latex) Render(ast *Node) []byte
- func (r *Latex) SetAST(ast *Node)
- func (r *Latex) StrikeThrough(text []byte)
- func (r *Latex) Table(header []byte, body []byte, columnData []int)
- func (r *Latex) TableCell(out *bytes.Buffer, text []byte, align int)
- func (r *Latex) TableHeaderCell(out *bytes.Buffer, text []byte, align int)
- func (r *Latex) TableRow(text []byte)
- func (r *Latex) TitleBlock(text []byte)
- func (r *Latex) TripleEmphasis(text []byte)
- func (r *Latex) Write(b []byte) (int, error)
- type LinkData
- type LinkType
- type ListData
- type ListType
- type Node
- type NodeType
- type NodeWalker
- type Options
- type Reference
- type ReferenceOverrideFunc
- type Renderer
- type TableFlags
Constants ¶
const ( Entity = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});" Escapable = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]" )
const ( HtmlFlagsNone HtmlFlags = 0 SkipHTML HtmlFlags = 1 << iota // Skip preformatted HTML blocks SkipStyle // Skip embedded <style> elements SkipImages // Skip embedded images SkipLinks // Skip all links Safelink // Only link to trusted protocols NofollowLinks // Only link with rel="nofollow" NoreferrerLinks // Only link with rel="noreferrer" HrefTargetBlank // Add a blank target Toc // Generate a table of contents OmitContents // Skip the main contents (for a standalone table of contents) CompletePage // Generate a complete HTML page UseXHTML // Generate XHTML output instead of HTML UseSmartypants // Enable smart punctuation substitutions SmartypantsFractions // Enable smart fractions (with UseSmartypants) SmartypantsDashes // Enable smart dashes (with UseSmartypants) SmartypantsLatexDashes // Enable LaTeX-style dashes (with UseSmartypants) SmartypantsAngledQuotes // Enable angled double quotes (with UseSmartypants) for double quotes rendering FootnoteReturnLinks // Generate a link at the end of a footnote to return to the source TagName = "[A-Za-z][A-Za-z0-9-]*" AttributeName = "[a-zA-Z_:][a-zA-Z0-9:._-]*" UnquotedValue = "[^\"'=<>`\\x00-\\x20]+" SingleQuotedValue = "'[^']*'" DoubleQuotedValue = "\"[^\"]*\"" AttributeValue = "(?:" + UnquotedValue + "|" + SingleQuotedValue + "|" + DoubleQuotedValue + ")" AttributeValueSpec = "(?:" + "\\s*=" + "\\s*" + AttributeValue + ")" Attribute = "(?:" + "\\s+" + AttributeName + AttributeValueSpec + "?)" OpenTag = "<" + TagName + Attribute + "*" + "\\s*/?>" CloseTag = "</" + TagName + "\\s*[>]" HTMLComment = "<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->" ProcessingInstruction = "[<][?].*?[?][>]" Declaration = "<![A-Z]+" + "\\s+[^>]*>" CDATA = "<!\\[CDATA\\[[\\s\\S]*?\\]\\]>" HTMLTag = "(?:" + OpenTag + "|" + CloseTag + "|" + HTMLComment + "|" + ProcessingInstruction + "|" + Declaration + "|" + CDATA + ")" )
Html renderer configuration options.
const ( TableAlignmentLeft = 1 << iota TableAlignmentRight TableAlignmentCenter = (TableAlignmentLeft | TableAlignmentRight) )
These are the possible flag values for the table cell renderer. Only a single one of these values will be used; they are not ORed together. These are mostly of interest if you are writing a new output format.
const ( TabSizeDefault = 4 TabSizeDouble = 8 )
The size of a tab stop.
const VERSION = "1.4"
Variables ¶
This section is empty.
Functions ¶
func Markdown ¶
func Markdown(input []byte, renderer Renderer, extensions Extensions) []byte
Markdown is the main rendering function. It parses and renders a block of markdown-encoded text. The supplied Renderer is used to format the output, and extensions dictates which non-standard extensions are enabled.
To use the supplied Html or LaTeX renderers, see HtmlRenderer and LatexRenderer, respectively.
func MarkdownBasic ¶
MarkdownBasic is a convenience function for simple rendering. It processes markdown input with no extensions enabled.
func MarkdownCommon ¶
Call Markdown with most useful extensions enabled MarkdownCommon is a convenience function for simple rendering. It processes markdown input with common extensions enabled, including:
* Smartypants processing with smart fractions and LaTeX dashes
* Intra-word emphasis suppression
* Tables
* Fenced code blocks
* Autolinking
* Strikethrough support
* Strict header parsing
* Custom Header IDs
Types ¶
type Extensions ¶
type Extensions int
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 SpaceHeaders // Be strict about prefix header 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 HeaderIDs // specify header IDs with {#id} Titleblock // Titleblock ala pandoc AutoHeaderIDs // Create the header ID from the text BackslashLineBreak // Translate trailing backslashes into line breaks DefinitionLists // Render definition lists )
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
type Html ¶
type Html struct {
// contains filtered or unexported fields
}
Html is a type that implements the Renderer interface for HTML output.
Do not create this directly, instead use the HtmlRenderer function.
func (*Html) BeginFootnotes ¶
func (r *Html) BeginFootnotes()
func (*Html) BeginHeader ¶
func (*Html) BeginParagraph ¶
func (r *Html) BeginParagraph()
func (*Html) BlockQuote ¶
func (*Html) CaptureWrites ¶
func (*Html) CopyWrites ¶
func (*Html) DocumentFooter ¶
func (r *Html) DocumentFooter()
func (*Html) DocumentHeader ¶
func (r *Html) DocumentHeader()
func (*Html) DoubleEmphasis ¶
func (*Html) EndFootnotes ¶
func (r *Html) EndFootnotes()
func (*Html) EndParagraph ¶
func (r *Html) EndParagraph()
func (*Html) FootnoteItem ¶
func (*Html) FootnoteRef ¶
func (*Html) NormalText ¶
func (*Html) RawHtmlTag ¶
func (*Html) Smartypants ¶
func (*Html) Smartypants2 ¶
func (*Html) StrikeThrough ¶
func (*Html) TableHeaderCell ¶
func (*Html) TitleBlock ¶
func (*Html) TocFinalize ¶
func (r *Html) TocFinalize()
func (*Html) TocHeaderWithAnchor ¶
func (*Html) TripleEmphasis ¶
type HtmlRendererParameters ¶
type HtmlRendererParameters struct { // Prepend this text to each relative URL. AbsolutePrefix string // Add this text to each footnote anchor, to ensure uniqueness. FootnoteAnchorPrefix string // Show this text inside the <a> tag for a footnote return link, if the // HTML_FOOTNOTE_RETURN_LINKS flag is enabled. If blank, the string // <sup>[return]</sup> is used. FootnoteReturnLinkContents string // If set, add this text to the front of each Header ID, to ensure // uniqueness. HeaderIDPrefix string // If set, add this text to the back of each Header ID, to ensure uniqueness. HeaderIDSuffix string }
type HtmlWriter ¶
type HtmlWriter struct {
// contains filtered or unexported fields
}
func (*HtmlWriter) Newline ¶
func (w *HtmlWriter) Newline()
Writes out a newline if the output is not pristine. Used at the beginning of every rendering func
func (*HtmlWriter) WriteByte ¶
func (w *HtmlWriter) WriteByte(b byte) error
func (*HtmlWriter) WriteString ¶
func (w *HtmlWriter) WriteString(s string) (n int, err error)
type Latex ¶
type Latex struct {
// contains filtered or unexported fields
}
Latex is a type that implements the Renderer interface for LaTeX output.
Do not create this directly, instead use the LatexRenderer function.
func (*Latex) BeginHeader ¶
func (*Latex) BeginParagraph ¶
func (r *Latex) BeginParagraph()
func (*Latex) BlockQuote ¶
func (*Latex) CaptureWrites ¶
func (*Latex) CopyWrites ¶
func (*Latex) DocumentFooter ¶
func (r *Latex) DocumentFooter()
func (*Latex) DoubleEmphasis ¶
func (*Latex) EndParagraph ¶
func (r *Latex) EndParagraph()
func (*Latex) FootnoteItem ¶
func (*Latex) NormalText ¶
func (*Latex) RawHtmlTag ¶
func (*Latex) StrikeThrough ¶
func (*Latex) TableHeaderCell ¶
func (*Latex) TitleBlock ¶
func (*Latex) TripleEmphasis ¶
type ListType ¶
type ListType int
const ( ListTypeOrdered ListType = 1 << iota ListTypeDefinition ListTypeTerm ListItemContainsBlock ListItemBeginningOfList ListItemEndOfList )
These are the possible flag values for the ListItem renderer. Multiple flag values may be ORed together. These are mostly of interest if you are writing a new output format.
type Node ¶
type Node struct { Type NodeType LinkData // If Type == Link, this holds link info HeaderID string // If Type == Header, this might hold header ID, if present IsTitleblock bool IsHeader bool // If Type == TableCell, this tells if it's under the header row // TODO: convert the int to a proper type Align int // If Type == TableCell, this holds the value for align attribute // contains filtered or unexported fields }
type NodeWalker ¶
type NodeWalker struct {
// contains filtered or unexported fields
}
func NewNodeWalker ¶
func NewNodeWalker(root *Node) *NodeWalker
type Options ¶
type Options struct { // Extensions is a flag set of bit-wise ORed extension bits. See the // Extensions flags defined in this package. Extensions Extensions // ReferenceOverride is an optional function callback that is called every // time a reference is resolved. // // 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 }
Options represents configurable overrides and callbacks (in addition to the extension flag set) for configuring a Markdown parse.
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.
type Renderer ¶
type Renderer interface { // block-level callbacks BlockCode(text []byte, lang string) BlockQuote(text []byte) BlockHtml(text []byte) BeginHeader(level int, id string) EndHeader(level int, id string, header []byte) HRule() BeginList(flags ListType) EndList(flags ListType) ListItem(text []byte, flags ListType) BeginParagraph() EndParagraph() Table(header []byte, body []byte, columnData []int) TableRow(text []byte) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) TableCell(out *bytes.Buffer, text []byte, flags int) BeginFootnotes() EndFootnotes() FootnoteItem(name, text []byte, flags ListType) TitleBlock(text []byte) // Span-level callbacks AutoLink(link []byte, kind LinkType) CodeSpan(text []byte) DoubleEmphasis(text []byte) Emphasis(text []byte) Image(link []byte, title []byte, alt []byte) LineBreak() Link(link []byte, title []byte, content []byte) RawHtmlTag(tag []byte) TripleEmphasis(text []byte) StrikeThrough(text []byte) FootnoteRef(ref []byte, id int) // Low-level callbacks Entity(entity []byte) NormalText(text []byte) // Header and footer DocumentHeader() GetFlags() HtmlFlags CaptureWrites(processor func()) []byte CopyWrites(processor func()) []byte Write(b []byte) (int, error) GetResult() []byte SetAST(ast *Node) GetAST() *Node Render(ast *Node) []byte }
Renderer is the rendering interface. This is mostly of interest if you are implementing a new rendering format.
When a byte slice is provided, it contains the (rendered) contents of the element.
When a callback is provided instead, it will write the contents of the respective element directly to the output buffer and return true on success. If the callback returns false, the rendering function should reset the output buffer as though it had never been called.
Currently Html and Latex implementations are provided
func HtmlRenderer ¶
HtmlRenderer creates and configures an Html object, which satisfies the Renderer interface.
flags is a set of HtmlFlags ORed together. title is the title of the document, and css is a URL for the document's stylesheet. title and css are only used when HTML_COMPLETE_PAGE is selected.
func HtmlRendererWithParameters ¶
func HtmlRendererWithParameters(flags HtmlFlags, title string, css string, renderParameters HtmlRendererParameters) Renderer
func LatexRenderer ¶
LatexRenderer creates and configures a Latex object, which satisfies the Renderer interface.
flags is a set of LATEX_* options ORed together (currently no such options are defined).
type TableFlags ¶
type TableFlags int