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 ¶
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).
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.
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.
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 Markdown ¶ added in v0.5.0
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 ¶ added in v0.5.0
NoteLink reads a link Markdown wrote: a vault path and subpath (note:) or a tag (tag:); ok is false for any other link.
func Sanitize ¶
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
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.