markdown

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: BSD-2-Clause Imports: 16 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.

README

vault-markdown

Obsidian-style markdown rendering for Go. Renders vault pages — frontmatter, callouts, embeds, wikilinks — to HTML so a service can display them without handing off to Obsidian.

Features

  • GFM tables and task lists (via goldmark)
  • YAML frontmatter rendered as a two-column <table class="frontmatter">
  • Callouts: > [!note] Title → <div class="callout" data-callout="note">
  • Embeds: a line holding only ![[page]] is inlined one level deep; the embedded page's frontmatter is not inlined, and a nested embed is dropped
  • Wikilinks: [[Page]], [[Page|alias]], [[Page#Heading]] through a pluggable resolver; missing targets render <span class="wikilink missing">
  • Backlinks(pages, target) — the pages linking to a target, sorted by path, ignoring links inside frontmatter, fenced blocks and inline code

Raw HTML in the source is escaped (goldmark's safe default), so a page that was not authored by the vault owner cannot inject script into the rendered output.

Install

go get github.com/bborbe/vault-markdown

Usage

package main

import (
	"context"
	"fmt"

	markdown "github.com/bborbe/vault-markdown"
)

func main() {
	renderer := markdown.New(
		markdown.WithResolver(markdown.ResolverFunc(func(target string) (string, bool) {
			return "/p/" + target, true
		})),
		markdown.WithPages(markdown.PagesFunc(func(name string) (string, bool) {
			return "", false
		})),
	)
	out, err := renderer.Render(context.Background(), "# Hello\n\n[[Page]]\n")
	if err != nil {
		panic(err)
	}
	fmt.Print(out)
}

Backlinks works on a plain map of page name to content:

links := markdown.Backlinks(map[string]string{
	"zeta.md":  "see [[A]]",
	"alpha.md": "see [[A|the page]]",
}, "A")
// links == []string{"alpha.md", "zeta.md"}

License

BSD-style — see LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KindCallout = ast.NewNodeKind("Callout")

KindCallout is the node kind for a > [!type] callout.

View Source
var KindEmbed = ast.NewNodeKind("Embed")

KindEmbed is the node kind for an inline ![embed].

View Source
var KindWikilink = ast.NewNodeKind("Wikilink")

KindWikilink is the node kind for a [[wikilink]].

Functions

func Backlinks(pages map[string]string, target string) []string

Backlinks returns the names of the pages that link to target, sorted by path. Both [[target]] and ![[target]] count, with an optional alias or heading anchor. A link that appears inside frontmatter, a fenced block or an inline code span is not a backlink.

Types

type Option

type Option func(*renderer)

Option configures a Renderer.

func WithPages

func WithPages(p Pages) Option

WithPages sets the source used to expand ![[embeds]]. Without one an embed is dropped.

func WithResolver

func WithResolver(r Resolver) Option

WithResolver sets the wikilink resolver. Without one every wikilink is missing.

type Pages

type Pages interface {
	// Page returns the content of name and whether it exists.
	Page(name string) (string, bool)
}

Pages returns page content by name so ![[embeds]] can be inlined.

type PagesFunc

type PagesFunc func(name string) (string, bool)

PagesFunc adapts a function to Pages.

func (PagesFunc) Page

func (f PagesFunc) Page(name string) (string, bool)

Page implements Pages.

type Renderer

type Renderer interface {
	// Render renders source to HTML.
	Render(ctx context.Context, source string) (string, error)
}

Renderer renders Obsidian-flavoured markdown to HTML.

func New

func New(opts ...Option) Renderer

New returns a Renderer configured with opts.

type Resolver

type Resolver interface {
	// Resolve returns the href for target and whether target exists.
	Resolve(target string) (string, bool)
}

Resolver resolves a wikilink target to an href.

type ResolverFunc

type ResolverFunc func(target string) (string, bool)

ResolverFunc adapts a function to Resolver.

func (ResolverFunc) Resolve

func (f ResolverFunc) Resolve(target string) (string, bool)

Resolve implements Resolver.

Jump to

Keyboard shortcuts

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