Documentation
¶
Overview ¶
Package markdown renders repository Markdown with the Obsidian syntax that the documentation viewer supports. Paths are clean, slash-separated, and relative to the repository root, for example "docs/ref/plan.md".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Highlight ¶
Highlight renders code as class-based chroma HTML in <pre class="code-block chroma" data-lang="...">. An empty lang picks a lexer from filename. With lineNumbers the lines get "L1" anchors.
func HighlightCSS ¶
func HighlightCSS() string
HighlightCSS returns chroma CSS for the light and dark viewer themes, scoped by html[data-theme]. Code block backgrounds are left to the page.
Types ¶
type Diff ¶
type Diff struct {
// Document is the merged body with diff marks, and the properties,
// title, and aliases of the new version.
*Document
// PropertiesChanged is true when the front matter differs.
PropertiesChanged bool
// Approximate is true when the line diff gave up (linediff.MaxEdits).
Approximate bool
}
Diff is the rendered diff of two versions of a note.
func RenderDiff ¶
RenderDiff renders one merged note that shows the old and the new version: unchanged blocks once, and each changed block as its old version marked removed, then its new version marked added. Paired blocks also get word marks.
type Document ¶
type Document struct {
// HTML is the rendered body. It excludes frontmatter properties.
HTML string
// Properties lists frontmatter keys in source order.
Properties []Property
// PropertiesError describes invalid frontmatter. The body still renders.
PropertiesError string
// Title is the frontmatter title, else the first level-1 heading, else "".
Title string
Aliases []string
// Tags lists frontmatter tags, then inline tags, without "#" or duplicates.
Tags []string
Headings []Heading
// Links lists internal links, wikilinks, and embeds in document order.
Links []Link
Mermaid bool
Math bool
}
Document is one rendered Markdown file.
type Link ¶
type Link struct {
// Path is the resolved repository path, or "" when unresolved.
Path string
// Target is the link target as written, without fragment or alias.
Target string
Fragment string
Embed bool
Wikilink bool
// Context is plain text around the link for backlink panes.
Context string
}
Link is one internal reference from a document.
type Property ¶
type Property struct {
Key string
List bool
Values []PropertyValue
}
Property is one frontmatter key.
type PropertyValue ¶
PropertyValue is one displayed property value. Link values have an Href.
type Resolver ¶
type Resolver interface {
// ResolveWikilink finds the file that an Obsidian link target names, as
// seen from the document at from. The target has no fragment or alias.
ResolveWikilink(from, target string) (string, bool)
// Exists reports whether path is a file or directory that the viewer serves.
Exists(path string) bool
// HeadingID returns the anchor of a heading in the Markdown file at path.
HeadingID(path, heading string) (string, bool)
// Source returns the Markdown source of an embedded note.
Source(path string) ([]byte, error)
}
Resolver answers questions about other repository files during one render.
type SourceLine ¶
type SourceLine []SourceSpan
SourceLine is one highlighted source line without its line break.
func HighlightLines ¶
func HighlightLines(code []byte, lang, filename string) ([]SourceLine, string)
HighlightLines highlights code as a whole and then splits the tokens into lines, so that a multi-line string or comment keeps its class on each line. The line texts joined with "\n" give code again: when a lexer changes the text, the lines are plain text. The second result is the language name for data-lang, as in Highlight.
func (SourceLine) HTML ¶
func (l SourceLine) HTML(tag string, marks [][2]int) string
HTML renders the line as chroma spans. Each mark is a byte range of the line text, in order. The marked text is wrapped in <tag class="diff-word"> inside the token spans, so the colors stay; a mark that crosses tokens gives one wrap in each token.
type SourceSpan ¶
type SourceSpan struct{ Class, Text string }
SourceSpan is one token of a highlighted source line. An empty Class is plain text.