Documentation
¶
Overview ¶
Package petroglyph is a Markdown-to-HTML stack: a zero-config goldmark extension assembling GitHub-flavored Markdown (tables, strikethrough, task lists, autolinks, footnotes, emoji) plus heading ids built by GitHub's anchor rule with permalink anchors, GitHub alerts, `` image sizing, chroma-highlighted and mermaid fences, YAML front matter, and MathJax math in $...$ and $$...$$ delimiters. Raw HTML passes through the renderer for DisplayPolicy to gate, GitHub-style.
Convert is the intended entry point. GFMParser and GFMHTMLRenderer compose into a custom goldmark pipeline, but then raw-HTML rendering and sanitizing are the caller's business.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var GFMHTMLRenderer = []htmlrenderer.Extension{ extension.StrikethroughHTMLRenderer, extension.TaskListItemHTMLRenderer, extension.NewTableHTMLRenderer( extension.WithTableCellAlignMethod(extension.TableCellAlignAttribute), ), extension.FootnoteHTMLRenderer, emoji.HTMLRenderer, gfmHTMLExt{}, }
var GFMParser = []parser.Extension{ extension.LinkifyParser, extension.StrikethroughParser, extension.TaskListItemParser, extension.TableParser, extension.FootnoteParser, emoji.Parser, gfmExt{}, }
GFMParser and GFMHTMLRenderer hold the goldmark v2 extensions that make up this package's feature set with no configuration, in the order parser.WithExtensions and html.WithExtensions want them. goldmark applies renderer extensions in list order and a later one wins the node-renderer map, so GFMHTMLRenderer has to stay last in a longer list: its fence, heading, image and math renderers replace the CommonMark ones that way.
Functions ¶
func AddAlertTitles ¶
AddAlertTitles injects the GitHub title paragraph (octicon + label) as the first child of every alert blockquote. Callers apply it to sanitized output: the markup is this file's, never content's, so the sanitizer's GitHub raw-HTML subset — which rejects svg — stays intact.
func DisplayPolicy ¶
func DisplayPolicy() *bluemonday.Policy
DisplayPolicy renders untrusted content safely. Chroma emits class-named spans/tables and mermaid fences need a class; UGC strips class by default, so allow it back — no user-controlled CSS is ever served, classes only map to the fixed stylesheets the app ships.
func SplitFrontMatter ¶
SplitFrontMatter consumes a leading YAML front-matter block ("---" line to "---" or "..." line). It returns the table markup plus remaining source; when the block is absent or the top level is not a scalar-keyed mapping, the source passes through untouched with an empty table. Values that are nested collections render as compact inline values instead of a rejection.
This runs as a source pass before goldmark, not as an extension: an invalid front-matter block must fall through to normal Markdown parsing, and by the time any transformer or block parser could inspect it, the "---" delimiters are already thematic breaks or setext heading underlines. Convert applies it; callers running the GFM extender on their own pipeline must call it first, or front matter parses as a setext heading.
Types ¶
type Flags ¶
type Flags struct {
Math bool // TeX math present: load MathJax
Mermaid bool // mermaid fence present: load a client-side renderer
}
Flags tells the page which optional payloads the rendered HTML needs: the template loads only the vendored JS actually required.
func Convert ¶
Convert renders a whole Markdown document: the optional YAML front matter table, then the body with raw HTML gated by DisplayPolicy, every table wrapped for horizontal scrolling, and alert titles injected (trusted markup, post-sanitize). On render failure it returns the source as escaped preformatted text.