markdown

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package markdown parses and HTML-renders Markdown documents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBfRenderer

func NewBfRenderer() blackfriday.Renderer

NewBfRenderer creates the default blackfriday renderer to be passed to NewParser()

func NewParser

func NewParser(renderer blackfriday.Renderer) *blackfriday.Markdown

NewParser creates a new Markdown parser (the same one used by Run).

Types

type Document

type Document struct {
	// Meta is the document's metadata in the Markdown "front matter", if any.
	Meta Metadata

	// Title is taken from the metadata (if it exists) or else from the text content of the first
	// heading.
	Title string

	// HTML is the rendered Markdown content.
	HTML []byte

	// Tree is the tree of sections (used to show a table of contents).
	Tree []*SectionNode
}

Document is a parsed and HTML-rendered Markdown document.

func Run

func Run(ctx context.Context, input []byte, opt Options) (*Document, error)

Run parses and HTML-renders a Markdown document (with optional metadata in the Markdown "front matter").

type FuncInfo

type FuncInfo struct {
	Version string // the version of the content containing the page to render
}

FuncInfo contains information passed to Markdown functions about the current execution context.

type FuncMap

type FuncMap map[string]func(context.Context, FuncInfo, map[string]string) (string, error)

FuncMap contains named functions that can be invoked within Markdown documents (see (Options).Funcs).

type Metadata

type Metadata struct {
	Title                       string `yaml:"title"`
	IgnoreDisconnectedPageCheck bool   `yaml:"ignoreDisconnectedPageCheck"`
}

Metadata is document metadata in the "front matter" of a Markdown document.

type Options

type Options struct {
	// Base is the base URL (typically including only the path, such as "/" or "/help/") to use when
	// resolving relative links.
	Base *url.URL

	// ContentFilePathToLinkPath converts references to file paths of other content files to the URL
	// path to use in links. For example, ContentFilePathToLinkPath("a/index.md") == "a".
	ContentFilePathToLinkPath func(string) string

	// Funcs are custom functions that can be invoked within Markdown documents with
	// <markdownfuncjfunction-name arg="val" />.
	Funcs FuncMap

	// FuncInfo contains information passed to Markdown functions about the current execution
	// context.
	FuncInfo FuncInfo
}

Options customize how Run parses and HTML-renders the Markdown document.

type SectionNode

type SectionNode struct {
	Title    string         // section title
	URL      string         // section URL (usually an anchor link)
	Level    int            // heading level (1–6)
	Children []*SectionNode // subsections
}

SectionNode is a section and its children.

Jump to

Keyboard shortcuts

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