Documentation
¶
Overview ¶
Package markdown parses notes (docs/design/vault.md#parse).
Index ¶
- func Goldmark(opts ...goldmark.Option) goldmark.Markdown
- func InlineMathKind() ast.NodeKind
- func MathBlockKind() ast.NodeKind
- func MathOf(n ast.Node, source []byte) (string, bool)
- func RenderSource(note []byte) (body []byte, line int)
- func Resolve(source, target string, files func(name string) []string) string
- func TagKind() ast.NodeKind
- func TagOf(n ast.Node) (string, bool)
- func TagSpan(n ast.Node) (start, end int, ok bool)
- func WikilinkKind() ast.NodeKind
- func WikilinkSpan(n ast.Node) (start, end int, ok bool)
- type Block
- type Doc
- type Heading
- type Link
- type LinkKind
- type Split
- type Tag
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Goldmark ¶
Goldmark returns goldmark as Parse reads notes: CommonMark, GFM, footnotes and the Obsidian extension, with opts after them.
func InlineMathKind ¶
InlineMathKind is the kind of a $…$ or $$…$$ node within a line.
func MathOf ¶
MathOf returns a math node's TeX without its delimiters, read from source, the text the node was parsed from.
func RenderSource ¶
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 ¶
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 TagSpan ¶ added in v0.5.0
TagSpan returns where a tag node's "#name" is in the source it was parsed from.
func WikilinkKind ¶
WikilinkKind is the kind of a [[wikilink]] or ![embed] node.
Types ¶
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.
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 ¶
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.
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 ¶
SplitFrontmatter finds note's frontmatter.