render

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 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 render renders a note to HTML for the reading view and embeds (ADR-0007; docs/specs/render.md): goldmark over the tree the index reads, with Obsidian's syntax drawn as the spec pins it, then sanitized.

Index

Constants

View Source
const (
	EmbedLanguage   = "frostnotes-embed"
	CalloutLanguage = "frostnotes-callout"
	MediaLanguage   = "frostnotes-media"
)

The languages of the fenced blocks Markdown writes for what CommonMark has no syntax for, which a native view draws itself (docs/specs/render.md#markdown-for-native-views).

View Source
const (
	NoteScheme = "note:" // a vault note or file, by path, with a subpath
	TagScheme  = "tag:"  // a tag, without '#'
	BlobScheme = "blob:" // a vault file's content, by hash and extension
)

The schemes of the links Markdown writes.

View Source
const (
	MaxEmbeds     = 100
	MaxEmbedBytes = 4 << 20
)

MaxEmbeds and MaxEmbedBytes bound the note embeds one render draws, at every depth together: past either, an embed is a link, as one too deep is, so a few notes that embed each other many times over cannot make notesd render without end.

View Source
const MaxEmbedDepth = 3

MaxEmbedDepth is how deep embedded notes nest below the note rendered: embeds three levels down show their notes, and a fourth level is a link.

Variables

This section is empty.

Functions

func HTML

func HTML(note []byte, opts Options) string

HTML renders note to HTML before it is sanitized: what the spec's fixtures pin.

func Markdown added in v0.5.0

func Markdown(note []byte, opts Options) string

Markdown renders note as Markdown that a native view (MyGo's) reads with CommonMark and GitHub's extensions: Obsidian's syntax becomes links with the schemes above, <mark> and fenced blocks of the languages above, and everything else stays as written. It is what note.renderMarkdown returns. A native view shows raw HTML as text, so nothing needs sanitizing.

func NoteLink(href string) (path, subpath, tag string, ok bool)

NoteLink reads a link Markdown wrote: a vault path and subpath (note:) or a tag (tag:); ok is false for any other link.

func Render

func Render(note []byte, opts Options) string

Render renders note to sanitized HTML: what note.render returns.

func Sanitize

func Sanitize(h string) string

Sanitize keeps only the elements and attributes of the spec's allowlist (docs/specs/render.md#sanitizer): what the renderer draws, and the harmless part of a note's raw HTML. It never adds markup and keeps the order of what it keeps. Text is passed through as the tokenizer read it, so entities stay as written, but for <; attribute values are written escaped.

Types

type NativeMarkdown added in v0.5.0

type NativeMarkdown struct {
	Markdown    string
	SourceLines []int
}

rewrite rewrites a body (a note's, or a callout's inside) as Markdown. NativeMarkdown includes source-line provenance for interactive native views.

func MarkdownWithSourceLines added in v0.5.0

func MarkdownWithSourceLines(note []byte, opts Options) NativeMarkdown

MarkdownWithSourceLines renders the note and maps output lines to its source. Embedded notes map to zero: clicks must never write a different document.

type Options

type Options struct {
	// Path is the note's vault path; links resolve from its folder.
	Path string
	// Resolve returns the vault path a link target (without subpath or
	// alias) leads to from the note at from, or "" when it is unresolved.
	// An embedded note's links resolve from the embedded note.
	Resolve func(from, target string) string
	// File returns a vault file's content hash, or false when the vault
	// has no file at path.
	File func(path string) (hash string, ok bool)
	// Note returns an embedded note's content, or false when there is
	// none at path or it is larger than MaxEmbedBytes.
	Note func(path string) ([]byte, bool)
}

Options say where a note sits and how to reach what it links to.

Jump to

Keyboard shortcuts

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