markdown

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package markdown renders Markdown with YAML front matter. It is shared by the content package, which renders collections at runtime, and by the code generator, which renders +page.md routes, so both produce the same HTML.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CodeCSS

func CodeCSS(style string) (string, error)

CodeCSS returns the CSS for highlighted code blocks in a chroma style, such as "github" or "dracula" (https://xyproto.github.io/splash/docs/).

func Split

func Split(src []byte) (front, body []byte)

Split separates YAML front matter, between "---" lines at the very start, from the Markdown body.

Types

type Document

type Document struct {
	// HTML is the rendered body.
	HTML string `json:"html"`
	// Headings lists the h2 to h4 headings in order.
	Headings []Heading `json:"headings"`
	// Words counts the words of the text.
	Words int `json:"words"`
	// ReadingMinutes estimates the reading time at 200 words a minute, at
	// least 1.
	ReadingMinutes int `json:"readingMinutes"`
	// Excerpt is the first paragraph as plain text.
	Excerpt string `json:"excerpt"`
}

Document is rendered Markdown.

func Parse

func Parse(src []byte, v any) (Document, error)

Parse decodes the front matter into v (a pointer to a struct or map) and renders the body. v may be nil.

func Render

func Render(body []byte) (Document, error)

Render renders Markdown without front matter.

func RenderSafe

func RenderSafe(body []byte) (Document, error)

RenderSafe renders Markdown from untrusted sources: raw HTML is replaced with a comment, and links with javascript: URLs are dropped.

type Heading

type Heading struct {
	Level int    `json:"level"`
	ID    string `json:"id"`
	Text  string `json:"text"`
}

Heading is a section heading, for tables of contents.

Jump to

Keyboard shortcuts

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