parser

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTagASTTransformer

func NewTagASTTransformer() parser.ASTTransformer

NewTagASTTransformer runs after inline parsing and splits plain *ast.Text runs into Text + HashTag fragments for Logseq-style #tags (letters, digits, _, /, -, Unicode letters).

func NewWikilinkInlineParser

func NewWikilinkInlineParser() parser.InlineParser

NewWikilinkInlineParser registers on '[' and wins over the standard Link parser when the lookahead is '[['. Priority should be lower numeric than LinkParser (200), e.g. 150.

func NormalizeAliasKey

func NormalizeAliasKey(s string) string

NormalizeAliasKey lowercases and strips wikilink brackets for alias lookup.

func ParseFrontmatterYAML

func ParseFrontmatterYAML(yamlBytes []byte) (props map[string]string, aliases []string, err error)

ParseFrontmatterYAML parses YAML frontmatter into flat string properties and extracted aliases. Known alias keys: alias, aliases (string, slice, or nested wikilink strings).

func SplitFrontmatter

func SplitFrontmatter(src []byte) (yamlBytes []byte, body []byte, ok bool)

SplitFrontmatter returns YAML bytes and markdown body when the file starts with a YAML frontmatter block (--- ... ---). Otherwise ok is false and body is the full src.

func StableBlockID

func StableBlockID(sourcePath string, lineStart, lineEnd int) string

StableBlockID returns a deterministic UUID (v5-style SHA-1) for a block span in a file. IDs remain stable across re-parses as long as the same source path and line span represent the same block; after edits, line ranges change and IDs update accordingly.

func StripWikilinkBrackets

func StripWikilinkBrackets(s string) string

StripWikilinkBrackets trims optional Obsidian-style [[ ... ]] around a title.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine holds a reusable Goldmark parser configured for Dingovault (wikilinks + #tags).

func NewEngine

func NewEngine() *Engine

NewEngine builds a parser with:

  • default block/inline parsers, plus a [[wikilink]] inline parser before LinkParser;
  • an AST transformer that splits #tags out of plain text (skipping code spans).

func (*Engine) ParseSource

func (e *Engine) ParseSource(src []byte, sourcePath string) (ParseResult, error)

ParseSource parses UTF-8 Markdown into blocks, wikilinks, and tags. It does not read or write the filesystem.

type HashTag

type HashTag struct {
	ast.BaseInline
	Name    []byte
	Segment text.Segment
}

HashTag is an inline AST node for #tags discovered after plain-text tokenization.

func NewHashTag

func NewHashTag(name []byte, seg text.Segment) *HashTag

NewHashTag constructs a tag node; seg covers the full "#name" span in the source.

func (*HashTag) Dump

func (n *HashTag) Dump(source []byte, level int)

Dump implements ast.Node.Dump.

func (*HashTag) Kind

func (n *HashTag) Kind() ast.NodeKind

Kind implements ast.Node.Kind.

type ParseResult

type ParseResult struct {
	Blocks    []domain.Block
	Wikilinks []WikilinkRef
	Tags      []TagRef
}

ParseResult is the output of Markdown parsing for one file.

type TagRef

type TagRef struct {
	BlockID string
	Tag     string
}

TagRef records a hashtag attached to a block.

type Wikilink struct {
	ast.BaseInline
	Target []byte
	Alias  []byte
}

Wikilink is an inline AST node for Logseq-style [[page]] or [[page|alias]].

func NewWikilink(target, alias []byte) *Wikilink

NewWikilink returns a wikilink node with trimmed target and optional display alias.

func (*Wikilink) Dump

func (n *Wikilink) Dump(source []byte, level int)

Dump implements ast.Node.Dump.

func (*Wikilink) Kind

func (n *Wikilink) Kind() ast.NodeKind

Kind implements ast.Node.Kind.

type WikilinkRef

type WikilinkRef struct {
	SourceBlockID string
	Target        string
	Alias         string
}

WikilinkRef records a wikilink emitted by a specific block.

Jump to

Keyboard shortcuts

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