markdown

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 20 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 parses notes (docs/design/vault.md#parse).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Goldmark

func Goldmark(opts ...goldmark.Option) goldmark.Markdown

Goldmark returns goldmark as Parse reads notes: CommonMark, GFM, footnotes and the Obsidian extension, with opts after them.

func InlineMathKind

func InlineMathKind() ast.NodeKind

InlineMathKind is the kind of a $…$ or $$…$$ node within a line.

func MathBlockKind

func MathBlockKind() ast.NodeKind

MathBlockKind is the kind of a $$ block.

func MathOf

func MathOf(n ast.Node, source []byte) (string, bool)

MathOf returns a math node's TeX without its delimiters, read from source, the text the node was parsed from.

func RenderSource

func RenderSource(note []byte) (body []byte, line int)

RenderSource returns what a note renders from, its body after any frontmatter and a leading BOM with each %%…%% comment outside code replaced by the newlines it held, and the 1-based line of the note on which the body starts, so a body offset's line is that line plus the '\n' bytes before it.

func Resolve

func Resolve(source, target string, files func(name string) []string) string

Resolve finds the file a link names, by Obsidian's rules (docs/specs/markdown.md#link-resolution). source is the linking note's vault path and target the link's Target. files returns every vault path whose last segment, lower-cased, equals name. Resolve returns the path as files spells it, or "" when the link is unresolved.

func TagKind

func TagKind() ast.NodeKind

TagKind is the kind of an inline #tag node.

func TagOf

func TagOf(n ast.Node) (string, bool)

TagOf returns a tag node's name, without '#'.

func WikilinkKind

func WikilinkKind() ast.NodeKind

WikilinkKind is the kind of a [[wikilink]] or ![embed] node.

Types

type Block

type Block struct {
	ID   string // without '^'
	Line int    // 1-based
}

Block is a block ID.

type Doc

type Doc struct {
	Links     []Link         // wikilinks, markdown links to vault files and property links, in order of Start
	Tags      []Tag          // each once, compared ignoring case: frontmatter tags first, then inline ones
	Headings  []Heading      // in order
	Blocks    []Block        // block IDs, in order
	Tasks     []Task         // in order, nested ones included
	Aliases   []string       // from the aliases property, in order
	Props     map[string]any // the frontmatter mapping as decoded, tags and aliases included; nil without one
	PropError error          // why the frontmatter is not a YAML mapping; nil when it is or there is none
	Words     int            // words in the body outside comments
}

Doc is what one note says, as docs/specs/markdown.md#parse-output defines it. Every string in it is valid UTF-8.

func Parse

func Parse(note []byte) Doc

Parse reads one note as docs/specs/markdown.md specifies. It never fails: frontmatter that is not a YAML mapping is a PropError, and the body is parsed whatever it holds.

type Heading

type Heading struct {
	Level int    // 1–6
	Text  string // the content as written, trimmed, without an ATX closing sequence
	Line  int    // 1-based line of its first line
}

Heading is an ATX or setext heading.

type Link struct {
	Kind    LinkKind
	Target  string // the file named, before any '#'; empty for the note itself
	Subpath string // heading or block ID, with its leading '#'
	Alias   string // display text: after '|', or a markdown link's text
	Embed   bool   // ![[…]] or an image
	Key     string // the frontmatter key, for a property link
	Start   int    // byte offset in the note of '[[', '[' or '!'
	End     int    // byte offset just past the link
	Line    int    // 1-based line of Start; a property link's key's line
}

Link is a link to a vault file.

func WikilinkOf

func WikilinkOf(n ast.Node) (Link, bool)

WikilinkOf returns a wikilink or embed node's link: its target, subpath, alias and embed mark. Its offsets are not set.

type LinkKind

type LinkKind string

LinkKind says where a link was written.

const (
	LinkWiki     LinkKind = "wiki"     // [[wikilink]] or ![[embed]] in the body
	LinkMarkdown LinkKind = "markdown" // [text](path) or ![alt](path) to a vault file
	LinkProperty LinkKind = "property" // a wikilink in a frontmatter value
)

The kinds of link.

type Split

type Split struct {
	HasFront  bool   // the note has frontmatter
	Front     []byte // the YAML between the delimiter lines, with its line endings; empty without frontmatter
	Body      []byte // everything after the closing delimiter line; the whole note without frontmatter
	BodyStart int    // the byte offset of Body in the note
}

Split is a note divided at its frontmatter.

func SplitFrontmatter

func SplitFrontmatter(note []byte) Split

SplitFrontmatter finds note's frontmatter.

type Tag

type Tag struct {
	Name  string // without '#', as first spelled
	Front bool   // from the frontmatter
	Line  int    // 1-based; the tags key's line for a frontmatter tag
}

Tag is a #tag or a frontmatter tag.

type Task

type Task struct {
	Status string // the character between the brackets: " " open, "x" or "X" done, or another
	Text   string // the rest of the item's first line, trimmed
	Line   int    // 1-based
}

Task is a list item with a [ ] status.

Jump to

Keyboard shortcuts

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