Documentation
¶
Overview ¶
Package mdparse turns a line buffer into a contiguous sequence of line-range blocks backed by the goldmark AST, plus an Obsidian-style wikilink inline extension. It is the bridge between the raw document model (internal/doc) and the renderer/editor: the renderer walks each block's goldmark Node to style inline text, and the editor uses the line ranges to decide which block the cursor sits in. It imports no TUI library and no other internal packages.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var HighlightExt goldmark.Extender = &highlightExtender{}
HighlightExt installs the ==highlight== inline parser.
var KindHighlight = ast.NewNodeKind("Highlight")
KindHighlight is the NodeKind for Highlight nodes.
var KindWikiLink = ast.NewNodeKind("WikiLink")
KindWikiLink is the NodeKind for WikiLink nodes.
var WikiLinkExt goldmark.Extender = &wikiLinkExtender{}
WikiLinkExt is the goldmark extender that installs the wikilink inline parser. It runs at priority 199, immediately ahead of the standard link parser (200).
Functions ¶
func LinkAt ¶ added in v0.2.0
LinkAt reports the markdown link destination if the rune column col falls within a [label](dest) span on the given raw line. col is measured in runes. Prefer WikiLinkAt first when both could apply — [[x]] is never a md link.
func Markdown ¶
Markdown returns the shared, configured goldmark instance used by Parse. The renderer can reuse it so inline parsing (including wikilinks) matches exactly.
func WikiLinkAt ¶
WikiLinkAt reports the wikilink target if the rune column col falls within a [[...]] span (inclusive of the surrounding brackets) on the given raw line. col is measured in runes. It is regex-based and independent of the AST, so it works directly on the raw text under the editor cursor.
Types ¶
type Block ¶
Block is a contiguous, inclusive range of raw line indices [Start, End] with its classified Kind and (for goldmark-derived blocks) the backing AST node. Node is nil for Blank and Frontmatter blocks.
type Highlight ¶ added in v0.4.0
type Highlight struct {
ast.BaseInline
}
Highlight is an Obsidian-style ==marked== inline span.
type Kind ¶
type Kind int
Kind classifies a block for rendering and editing decisions.
const ( Blank Kind = iota Heading Paragraph CodeFence List Table Blockquote ThematicBreak Frontmatter Other // HTML block and any other unmapped content. // IndentedCode is a 4-space (or tab) indented code block. It is kept distinct // from CodeFence because it has no “` delimiter lines and no info string. // Appended last so existing Kind values (Blank..Other) keep their integers. IndentedCode )
type Result ¶
Result is the output of Parse: the ordered blocks plus the exact bytes that were parsed (all lines joined with "\n"). Source is what the renderer must use to resolve AST text segments.
func Parse ¶
Parse segments lines into contiguous blocks. The returned Blocks always cover every line index in [0, len(lines)-1] with no gaps and no overlap — the invariant the editor's virtualization depends on.
goldmark parses the FULL source, so every Block.Node's inline segments align to Result.Source by construction (the render consumer slices those segments straight out of Source). Frontmatter is detected separately (line 0 "---" with a later "---" closing it) and the blocks goldmark produced within that line range are collapsed into a single Frontmatter block (Node nil).
type WikiLink ¶
WikiLink is an inline AST node representing an Obsidian-style wikilink, either [[target]] or [[target|alias]]. Segment is the byte range of the target text within the parsed source, so the renderer can slice it directly out of Result.Source (it always aligns because goldmark parses the full source).