Documentation
¶
Overview ¶
Package commonmark is a pure-Go (CGO=0) strict CommonMark renderer. It implements the CommonMark specification v0.31.2 — the same core that backs the Ruby `commonmarker` gem — and can additionally enable a subset of the GFM extensions (tables, strikethrough, autolinks, task lists) behind Options.
The primary entry point is ToHTML, which converts a Markdown source string to an HTML fragment. Parse exposes the intermediate Document node tree for callers that need structured access.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Node ¶
type Node struct {
Type NodeType
// Tree links.
Parent *Node
FirstChild, LastChild *Node
Prev, Next *Node
// Literal payload for leaf nodes: Text/Code/HTMLBlock/HTMLInline/CodeBlock.
Literal []byte
// Heading level (1..6) or, during Setext resolution, the marker level.
Level int
Info []byte // fenced code info string (raw)
// Link / Image destination + title.
Destination []byte
Title []byte
// contains filtered or unexported fields
}
Node is a single node in the CommonMark parse tree. It is exported so callers that need structured access (via Parse) can walk it; ToHTML uses it internally.
type NodeType ¶
type NodeType int
NodeType enumerates the kinds of nodes in the parse tree. Block-level and inline-level nodes share one tree, following the CommonMark reference model.
const ( // Document is the root of every parse tree. Document NodeType = iota // BlockQuote is a `>`-prefixed block quote. BlockQuote // List is a bullet or ordered list container. List // Item is a single list item. Item // CodeBlock is an indented or fenced code block. CodeBlock // HTMLBlock is a raw block-level HTML region. HTMLBlock // Paragraph is a paragraph of inline content. Paragraph // Heading is an ATX or Setext heading. Heading // ThematicBreak is a horizontal rule (`---`, `***`, `___`). ThematicBreak // Text is a run of literal text. Text // Softbreak is an end-of-line that renders as a newline (or space). Softbreak // Linebreak is a hard line break (` \n` or `\\\n`). Linebreak // Code is an inline code span. Code // HTMLInline is raw inline HTML. HTMLInline // Emphasis is `*`/`_` emphasis (rendered <em>). Emphasis // Strong is `**`/`__` strong emphasis (rendered <strong>). Strong // Link is a hyperlink. Link // Image is an image reference. Image // Strikethrough is GFM `~~` strikethrough (extension). Strikethrough // Table is a GFM table (extension). Table // TableRow is a row within a GFM table. TableRow // TableCell is a cell within a GFM table row. TableCell )
type Options ¶
type Options struct {
// Tables enables GFM pipe tables.
Tables bool
// Strikethrough enables GFM `~~text~~` strikethrough.
Strikethrough bool
// Autolink enables GFM extended autolinks (bare URLs and www links).
Autolink bool
// TaskList enables GFM `- [ ]` / `- [x]` task list items.
TaskList bool
// GitHubPreLang, when true, emits fenced code language as a class on the
// <pre> element the way commonmarker's GitHub renderer does. When false
// (the CommonMark default) the class is emitted on the <code> element.
GitHubPreLang bool
// Unsafe, when true, passes raw HTML and unsafe URL schemes through instead
// of filtering them. The CommonMark reference renderer used by the spec test
// suite is unsafe, so the conformance tests set this.
Unsafe bool
// HardBreaks, when true, renders every soft line break as a <br />.
HardBreaks bool
}
Options configures the renderer. The zero value (or a nil *Options) selects strict CommonMark with all extensions disabled, which is the safe default.
