markdown

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 9 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 markdown reads a document's body into an outline: the tree of its blocks and inline pieces as goldmark parses them, each holding its position in the body as written. It knows nothing of documents, sections or rules, and is the only package that imports goldmark.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Walk

func Walk(n *Node, fn func(*Node) bool)

Walk calls fn for n and each node beneath it in document order, skipping the nodes beneath any for which fn returns false.

Types

type Line

type Line struct {
	Span
	Padding int
}

Line is one line of a leaf block's content: the bytes of the body it was read from, and the columns of a tab before them that a container's marker covered only in part, which the content holds as spaces.

type Node

type Node struct {
	Type Type
	Span
	Children []*Node

	// Lines is a leaf block's content, line by line.
	Lines []Line
	// Text is a text's text with escapes and entities resolved, a code span's
	// or code block's content, raw HTML and an HTML block as written, and an
	// autolink's text.
	Text string

	Level     int  // a heading's level
	Setext    bool // a heading written with an underline
	Ordered   bool // a list
	Number    int  // an ordered list's first number
	Delimiter byte // a list's marker: '-', '+', '*', '.' or ')'
	Tight     bool // a list
	Fenced    bool // a code block
	Info      string
	Closed    bool   // a fenced code block or an HTML block its end marker closes
	Align     string // a table cell: "left", "center", "right" or ""
	Hard      bool   // a line break

	// ClosedByMarker is an HTML block of CommonMark types 1 to 5, opened by
	// script, pre, style or textarea, a comment, a processing instruction, a
	// declaration or CDATA, which only its end marker closes.
	ClosedByMarker bool

	// Destination and Title are a link's, an image's or a link reference
	// definition's, resolved. Label is a reference's or a definition's label
	// as written, which the parser matches labels by, ignoring case and runs
	// of spaces for a link and neither for a footnote. Each part's span is its bytes as written, and a
	// link's or an image's TextSpan the bytes between its brackets. A link
	// or image by reference has its definition's destination and title, and
	// no span for either.
	TextSpan                              Span
	Destination, Title, Label             string
	DestinationSpan, TitleSpan, LabelSpan Span
	HasDestination, HasTitle, HasLabel    bool
	AutoLink                              bool // a link written as <...> or found by the linkify extension
	Reference                             bool // a link or image by reference
}

Node is a block or an inline piece of the outline.

func Parse

func Parse(body []byte) *Node

Parse reads body into its outline.

type Span

type Span struct{ Start, End int }

Span is a range of bytes in the body, the end exclusive.

type Type

type Type uint8

Type is the type of a block or piece. Its name is the element the reference's XML gives the same construct.

const (
	Document Type = iota
	Blockquote
	List
	ListItem
	FootnoteDefinition
	Paragraph
	Heading
	ThematicBreak
	CodeBlock
	HTMLBlock
	Table
	TableHeader
	TableRow
	TableCell
	LinkReferenceDefinition

	Text
	LineBreak
	CodeSpan
	Emphasis
	Strong
	Strikethrough
	Link
	Image
	RawHTML
	FootnoteReference
)

func (Type) IsBlock

func (t Type) IsBlock() bool

IsBlock reports whether the type is a block rather than an inline piece.

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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