markdown

package
v0.86.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package markdown is a small, dependency-free Markdown renderer.

It parses a constrained subset of Markdown, enough for project docs and website content, and emits HTML directly. It is not CommonMark-strict; the goal is predictable output for the inputs we actually write, not edge-case fidelity.

Supported block elements:

  • ATX headings (#, ##, … up to ######)
  • Paragraphs
  • Fenced code blocks (three or more ` or ~, with an optional info string: a language, then options this package passes through in data-meta)
  • Unordered lists (-, *, +)
  • Ordered lists (1., 2., …)
  • Blockquotes (>)
  • Horizontal rules (---, ***, ___)
  • GFM-style tables (| col | col |)
  • YAML-ish frontmatter (--- key: value --- at the top of the document)

Supported inline elements:

  • Bold (**…** or __…__)
  • Italic (*…* or _…_)
  • Inline code (`…`)
  • Links ([text](url)) and images (![alt](url))

HTML in source is escaped, never passed through. Code blocks and inline code are rendered without syntax highlighting; callers can post-process if they want highlighted output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderHTML

func RenderHTML(input string) render.HTML

RenderHTML is a convenience wrapper that returns just the HTML body.

func Unquote added in v0.86.0

func Unquote(s string) string

Unquote strips one layer of matching surrounding quotes (double or single) from a YAML frontmatter scalar, returning s unchanged when it is not quoted (or is too short to be). Exported for the skill frontmatter parser, which formerly carried a byte-identical trimYAMLQuotes copy.

Types

type Document

type Document struct {
	// Frontmatter holds key/value pairs from a leading `--- ... ---` block.
	// Values are kept as raw strings; callers do their own typing.
	Frontmatter map[string]string

	// HTML is the rendered body.
	HTML render.HTML

	// Title is the text of the first H1 in the document if present, otherwise
	// the value of the `title` frontmatter key. Useful for setting <title>.
	Title string
}

Document is the result of parsing a Markdown source.

func Render

func Render(input string) Document

Render parses Markdown source and returns the rendered Document.

type FenceInfo added in v0.83.0

type FenceInfo struct {
	// Lang is the first whitespace-delimited token, the language name
	// ("go", "bash"). Empty for a fence with no info string.
	Lang string
	// Meta is everything after Lang, verbatim and trimmed: `title="main.go"`,
	// `{1,3-5}`, `showLineNumbers`. The renderer decides what those mean; this
	// package only carries them through, in the <code> tag's data-meta
	// attribute. Empty for a plain fence.
	Meta string
}

FenceInfo is a parsed fence info string, the text after a fence's opening run.

func ParseFenceInfo added in v0.83.0

func ParseFenceInfo(info string) FenceInfo

ParseFenceInfo splits a fence info string into its language and its options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL