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. The GFM extender alone composes 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 GFM goldmark.Extender = gfmExt{}
GFM extends a goldmark instance with the full feature set and no configuration.
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.