markdown

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: Apache-2.0 Imports: 24 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 EvalMarkdownFuncs added in v1.3.0

func EvalMarkdownFuncs(ctx context.Context, htmlFragment []byte, opt Options) ([]byte, error)

func GetAttributeID added in v1.9.0

func GetAttributeID(node ast.Node) string

func GetTitle added in v1.1.0

func GetTitle(doc ast.Node, source []byte) string

func IsDocumentTopTitleHeadingNode added in v1.4.0

func IsDocumentTopTitleHeadingNode(node ast.Node) bool

IsDocumentTopTitleHeadingNode reports whether node is an h1-heading at the top of the document.

func New added in v1.9.0

func New(opts Options) goldmark.Markdown

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(source []byte, opts Options) (doc *Document, err 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 {
	IgnoreDisconnectedPageCheck bool `yaml:"ignoreDisconnectedPageCheck"`

	Title       string   `yaml:"title"`
	Description string   `yaml:"description"`
	Category    string   `yaml:"category"`
	ImageURL    string   `yaml:"imageURL"`
	Type        string   `yaml:"type"`
	Tags        []string `yaml:"tags"`
}

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