md

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package md parses Markdown, following the block and inline structure of CommonMark 0.31 (with the GFM tables, strikethrough, task lists and extended autolinks), and renders it to HTML as a CommonMark renderer does, keeping a map from offsets in the HTML back to offsets in the Markdown. The extractor reads that HTML with the same tree builder and block walker as an HTML page, so the display reasons raw HTML in Markdown declares are read as in a page, and every block's location is in the Markdown source.

The parser follows the reference implementation's line-by-line algorithm (commonmark.js): open containers are continued or closed, new block starts are tried, and lazy continuation lines join a paragraph.

Index

Constants

View Source
const MaxNest = 100

MaxNest bounds the nesting of block quotes and lists. A marker past it is read as text.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doc

type Doc struct {

	// GFM turns on the inline extensions of GitHub Flavored Markdown
	// when the document is rendered: strikethrough, task-list items and
	// extended autolinks. Parse sets it; RenderSpec ignores it. Tables
	// are always read.
	GFM bool
	// contains filtered or unexported fields
}

Doc is a parsed Markdown document.

func Parse

func Parse(ctx context.Context, src string) (*Doc, error)

Parse parses src, which must be UTF-8.

func (*Doc) Render

func (d *Doc) Render(limit int) *HTML

Render writes the document as HTML, stopping before limit bytes. Link and image addresses are written as the source has them.

func (*Doc) RenderSpec

func (d *Doc) RenderSpec() *HTML

RenderSpec writes the document as the CommonMark reference renderer does, with addresses percent-encoded, for comparison with the spec.

type HTML

type HTML struct {
	B []byte

	// Cut reports that rendering stopped at the size limit.
	Cut bool
	// Replaced counts the character references to no character (�, a
	// surrogate, a number past U+10FFFF) read as U+FFFD.
	Replaced int
	// contains filtered or unexported fields
}

HTML is a document rendered to HTML.

func (*HTML) Source

func (o *HTML) Source(h int) int

Source returns the offset in the Markdown of offset h in the HTML.

type Ref

type Ref struct{ Dest, Title string }

Ref is a link reference definition.

Jump to

Keyboard shortcuts

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