package blackfriday

Import Path
	github.com/russross/blackfriday/v2 (on go.dev)

Dependency Relation
	imports 9 packages, and imported by 2 packages

Involved Source Files block.go Package blackfriday is a markdown processor. It translates plain text with simple formatting rules into an AST, which can then be further processed to HTML (provided by Blackfriday itself) or other formats (provided by the community). The simplest way to invoke Blackfriday is to call the Run function. It will take a text input and produce a text output in HTML (or other format). A slightly more sophisticated way to use Blackfriday is to create a Markdown processor and to call Parse, which returns a syntax tree for the input document. You can leverage Blackfriday's parsing for content extraction from markdown documents. You can assign a custom renderer and set various options to the Markdown processor. If you're interested in calling Blackfriday from command line, see https://github.com/russross/blackfriday-tool. esc.go html.go inline.go markdown.go node.go smartypants.go
Package-Level Type Names (total 27, in which 21 are exported)
/* sort exporteds by: | */
CellAlignFlags holds a type of alignment in a table cell. const TableAlignmentCenter const TableAlignmentLeft const TableAlignmentRight
CodeBlockData contains fields relevant to a CodeBlock node type. FenceChar byte FenceLength int FenceOffset int // This holds the info string // Specifies whether it's a fenced code block or an indented one
Extensions is a bitwise or'ed collection of enabled Blackfriday's extensions. func WithExtensions(e Extensions) Option const AutoHeadingIDs const Autolink const BackslashLineBreak const CommonExtensions const DefinitionLists const FencedCode const Footnotes const HardLineBreak const HeadingIDs const LaxHTMLBlocks const NoEmptyLineBeforeBlock const NoExtensions const NoIntraEmphasis const SpaceHeadings const Strikethrough const Tables const TabSizeEight const Titleblock
HeadingData contains fields relevant to a Heading node type. // This might hold heading ID, if present // Specifies whether it's a title block // This holds the heading level number
HTMLFlags control optional behavior of HTML renderer. func NewSmartypantsRenderer(flags HTMLFlags) *SPRenderer const CommonHTMLFlags const CompletePage const FootnoteReturnLinks const HrefTargetBlank const HTMLFlagsNone const NofollowLinks const NoopenerLinks const NoreferrerLinks const Safelink const SkipHTML const SkipImages const SkipLinks const Smartypants const SmartypantsAngledQuotes const SmartypantsDashes const SmartypantsFractions const SmartypantsLatexDashes const SmartypantsQuotesNBSP const TOC const UseXHTML
HTMLRenderer is a type that implements the Renderer interface for HTML output. Do not create this directly, instead use the NewHTMLRenderer function. HTMLRendererParameters HTMLRendererParameters Prepend this text to each relative URL. // Optional CSS file URL (used if CompletePage is set) // Flags allow customizing this renderer's behavior Add this text to each footnote anchor, to ensure uniqueness. 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. If set, add this text to the front of each Heading ID, to ensure uniqueness. If set, add this text to the back of each Heading ID, to ensure uniqueness. Increase heading levels: if the offset is 1, <h1> becomes <h2> etc. Negative offset is also valid. Resulting levels are clipped between 1 and 6. // Optional icon file URL (used if CompletePage is set) // Document title (used if CompletePage is set) RenderFooter writes HTML document footer. RenderHeader writes HTML document preamble and TOC if requested. RenderNode is a default renderer of a single node of a syntax tree. For block nodes it will be called twice: first time with entering=true, second time with entering=false, so that it could know when it's working on an open tag and when on close. It writes the result to w. The return value is a way to tell the calling walker to adjust its walk pattern: e.g. it can terminate the traversal by returning Terminate. Or it can ask the walker to skip a subtree of this node by returning SkipChildren. The typical behavior is to return GoToNext, which asks for the usual traversal to the next node. *T : Renderer func NewHTMLRenderer(params HTMLRendererParameters) *HTMLRenderer
HTMLRendererParameters is a collection of supplementary parameters tweaking the behavior of various parts of HTML renderer. Prepend this text to each relative URL. // Optional CSS file URL (used if CompletePage is set) // Flags allow customizing this renderer's behavior Add this text to each footnote anchor, to ensure uniqueness. 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. If set, add this text to the front of each Heading ID, to ensure uniqueness. If set, add this text to the back of each Heading ID, to ensure uniqueness. Increase heading levels: if the offset is 1, <h1> becomes <h2> etc. Negative offset is also valid. Resulting levels are clipped between 1 and 6. // Optional icon file URL (used if CompletePage is set) // Document title (used if CompletePage is set) func NewHTMLRenderer(params HTMLRendererParameters) *HTMLRenderer
LinkData contains fields relevant to a Link node type. // Destination is what goes into a href // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil. // NoteID contains a serial number of a footnote, zero if it's not a footnote // Title is the tooltip thing that goes in a title attribute
ListData contains fields relevant to a List and Item node type. // '*', '+' or '-' in bullet lists // '.' or ')' after the number in ordered lists // This is a list of footnotes ListFlags ListType // If not nil, turns this list item into a footnote item and triggers different rendering // Skip <p>s around list item data if true
ListType contains bitwise or'ed flags for list and list item objects. const ListItemBeginningOfList const ListItemContainsBlock const ListItemEndOfList const ListTypeDefinition const ListTypeOrdered const ListTypeTerm
Markdown is a type that holds extensions and the runtime state used by Parse, and the renderer. You can not use it directly, construct it with New. Parse is an entry point to the parsing part of Blackfriday. It takes an input markdown document and produces a syntax tree for its contents. This tree can then be rendered with a default or custom renderer, or analyzed/transformed by the caller to whatever non-standard needs they have. The return value is the root node of the syntax tree. func New(opts ...Option) *Markdown
Node is a single element in the abstract syntax tree of the parsed document. It holds connections to the structurally neighboring nodes and, for certain types of nodes, additional information that might be needed when rendering. // Populated if Type is CodeBlock CodeBlockData.FenceChar byte CodeBlockData.FenceLength int CodeBlockData.FenceOffset int // This holds the info string // Specifies whether it's a fenced code block or an indented one // Points to the first child, if any // Populated if Type is Heading // This might hold heading ID, if present // Specifies whether it's a title block // This holds the heading level number // Points to the last child, if any // Populated if Type is Link // Destination is what goes into a href // If it's a footnote, this is a direct link to the footnote Node. Otherwise nil. // NoteID contains a serial number of a footnote, zero if it's not a footnote // Title is the tooltip thing that goes in a title attribute // Populated if Type is List // '*', '+' or '-' in bullet lists // '.' or ')' after the number in ordered lists // This is a list of footnotes ListData.ListFlags ListType // If not nil, turns this list item into a footnote item and triggers different rendering // Skip <p>s around list item data if true // Text contents of the leaf nodes // Next sibling; nil if it's the last child // Points to the parent // Previous sibling; nil if it's the first child // Populated if Type is TableCell // This holds the value for align attribute // This tells if it's under the header row // Determines the type of the node AppendChild adds a node 'child' as a child of 'n'. It panics if either node is nil. InsertBefore inserts 'sibling' immediately before 'n'. It panics if either node is nil. (*T) String() string Unlink removes node 'n' from the tree. It panics if the node is nil. Walk is a convenience method that instantiates a walker and starts a traversal of subtree rooted at n. *T : expvar.Var *T : fmt.Stringer func NewNode(typ NodeType) *Node func (*Markdown).Parse(input []byte) *Node func (*HTMLRenderer).RenderFooter(w io.Writer, ast *Node) func (*HTMLRenderer).RenderHeader(w io.Writer, ast *Node) func (*HTMLRenderer).RenderNode(w io.Writer, node *Node, entering bool) WalkStatus func (*Node).AppendChild(child *Node) func (*Node).InsertBefore(sibling *Node) func Renderer.RenderFooter(w io.Writer, ast *Node) func Renderer.RenderHeader(w io.Writer, ast *Node) func Renderer.RenderNode(w io.Writer, node *Node, entering bool) WalkStatus
NodeType specifies a type of a single node of a syntax tree. Usually one node (and its type) corresponds to a single markdown feature, e.g. emphasis or code block. ( T) String() string T : expvar.Var T : fmt.Stringer func NewNode(typ NodeType) *Node const BlockQuote const Code const CodeBlock const Del const Document const Emph const Hardbreak const Heading const HorizontalRule const HTMLBlock const HTMLSpan const Image const Item const Link const List const Paragraph const Softbreak const Strong const Table const TableBody const TableCell const TableHead const TableRow const Text
NodeVisitor is a callback to be called when traversing the syntax tree. Called twice for every node: once with entering=true when the branch is first visited, then with entering=false after all the children are done. func (*Node).Walk(visitor NodeVisitor)
Option customizes the Markdown processor's default behavior. func WithExtensions(e Extensions) Option func WithNoExtensions() Option func WithRefOverride(o ReferenceOverrideFunc) Option func WithRenderer(r Renderer) Option func New(opts ...Option) *Markdown func Run(input []byte, opts ...Option) []byte
Reference represents the details of a link. See the documentation in Options for more details on use-case. Link is usually the URL the reference points to. Text is the optional text to override the ref with if the syntax used was [refid][] Title is the alternate text describing the link in more detail.
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. func WithRefOverride(o ReferenceOverrideFunc) Option
Renderer is the rendering interface. This is mostly of interest if you are implementing a new rendering format. Only an HTML implementation is provided in this repository, see the README for external implementations. RenderFooter is a symmetric counterpart of RenderHeader. RenderHeader is a method that allows the renderer to produce some content preceding the main body of the output document. The header is understood in the broad sense here. For example, the default HTML renderer will write not only the HTML document preamble, but also the table of contents if it was requested. The method will be passed an entire document tree, in case a particular implementation needs to inspect it to produce output. The output should be written to the supplied writer w. If your implementation has no header to write, supply an empty implementation. RenderNode is the main rendering method. It will be called once for every leaf node and twice for every non-leaf node (first with entering=true, then with entering=false). The method should write its rendition of the node to the supplied writer w. *HTMLRenderer func WithRenderer(r Renderer) Option
SPRenderer is a struct containing state of a Smartypants renderer. Process is the entry point of the Smartypants renderer. func NewSmartypantsRenderer(flags HTMLFlags) *SPRenderer
TableCellData contains fields relevant to a TableCell node type. // This holds the value for align attribute // This tells if it's under the header row
WalkStatus allows NodeVisitor to have some control over the tree traversal. It is returned from NodeVisitor and different values allow Node.Walk to decide which node to go to next. func (*HTMLRenderer).RenderNode(w io.Writer, node *Node, entering bool) WalkStatus func Renderer.RenderNode(w io.Writer, node *Node, entering bool) WalkStatus const GoToNext const SkipChildren const Terminate
Package-Level Functions (total 85, in which 9 are exported)
New constructs a Markdown processor. You can use the same With* functions as for Run() to customize parser's behavior and the renderer.
NewHTMLRenderer creates and configures an HTMLRenderer object, which satisfies the Renderer interface.
NewNode allocates a node of a specified type.
NewSmartypantsRenderer constructs a Smartypants renderer object.
Run is the main entry point to Blackfriday. It parses and renders a block of markdown-encoded text. The simplest invocation of Run takes one argument, input: output := Run(input) This will parse the input with CommonExtensions enabled and render it with the default HTMLRenderer (with CommonHTMLFlags). Variadic arguments opts can customize the default behavior. Since Markdown type does not contain exported fields, you can not use it directly. Instead, use the With* functions. For example, this will call the most basic functionality, with no extensions: output := Run(input, WithNoExtensions()) You can use any number of With* arguments, even contradicting ones. They will be applied in order of appearance and the latter will override the former: output := Run(input, WithNoExtensions(), WithExtensions(exts), WithRenderer(yourRenderer))
WithExtensions allows you to pick some of the many extensions provided by Blackfriday. You can bitwise OR them.
WithNoExtensions turns off all extensions and custom behavior.
WithRefOverride sets 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.
WithRenderer allows you to override the default renderer.
Package-Level Variables (total 76, none are exported)
Package-Level Constants (total 104, in which 77 are exported)
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
HTML renderer configuration options.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
GoToNext is the default traversal of every node.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
HTML renderer configuration options.
Constants for identifying different types of nodes. See NodeType.
HTML renderer configuration options.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
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.
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.
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.
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.
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.
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.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
SkipChildren tells walker to skip all children of current node.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
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.
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.
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.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
The size of a tab stop.
The size of a tab stop.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
Terminate tells walker to terminate the traversal.
Constants for identifying different types of nodes. See NodeType.
These are the supported markdown parsing extensions. OR these values together to select multiple extensions.
HTML renderer configuration options.
HTML renderer configuration options.
Version string of the package. Appears in the rendered document when CompletePage flag is on.