Documentation
¶
Overview ¶
Package export renders a Markdown document as a standalone HTML page or as plain text, and draws a single Mermaid diagram as a page of its own, for an export and for a preview.
An HTML page is whole: its colours are one of the shipped themes' (Themes, ThemeOf, Background), its Content-Security-Policy allows no network access, and an image is shown as its alt text, unless Options.Document names the source's file: then an embed of a file beside it (a Mermaid diagram, a CSV table, an image) is drawn in the page (embed.go), an image as a data: URI. A ```mermaid block is drawn in the page by the vendored mermaid.js (core/export/mermaid); the page then holds that script, and its policy admits it and the one that starts it by their digests. A page without a diagram has no script. Options.Base makes the source's relative links file: URLs of the files they name, so the page's links reach them wherever it is written. Plain text drops frontmatter, link reference definitions and raw HTML, and keeps code blocks as written.
Concurrency: every exported function may be called from any number of goroutines. Each call parses its own tree from the source and does not change the source; the package's shared state is read-only after init (the themes, the mermaid regexp) or built once under a sync.Once (the vendored script and its digest). The package reads the disk only for Options.Document's embeds, inside the document's folder; RenderWith reads the process's working directory when Options.Base or Options.Document is relative.
Index ¶
- func Background(theme string) string
- func CSVMarkdown(data []byte, rows int) (string, bool)
- func DiagramPage(source, theme string) ([]byte, error)
- func EmbedDiagram(doc, dest string) (string, bool)
- func EmbedMarkdown(doc, dest string, rows int) (string, bool)
- func Render(source []byte, format Format, theme string) ([]byte, error)
- func RenderWith(source []byte, format Format, theme string, options Options) ([]byte, error)
- func ThemeOf(tuiTheme string) string
- func Themes() []string
- type EmbedLine
- type Format
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Background ¶
Background is a theme's page colour; dark's for a theme it does not have.
func CSVMarkdown ¶ added in v0.1.46
CSVMarkdown is CSV (a file's, or a csv fence's) as the Rendered view draws it: a Markdown table of literal cells, its first row the header, of at most rows rows (0: maxTableRows), and a last row saying what is not shown. ok is false for no rows, or what is not CSV.
func DiagramPage ¶ added in v0.1.11
DiagramPage is a page of one Mermaid diagram, drawn at its own size on the theme's background: for a preview, which renders it whole and scrolls it.
func EmbedDiagram ¶ added in v0.1.45
EmbedDiagram is the Mermaid source of an embed of dest (.mmd) in the document at doc, read as the page reads it: beside the document, then in its resources folder, never out of its folder. ok is false for any other embed, and for a file that is missing, refused or too large.
func EmbedMarkdown ¶ added in v0.1.44
EmbedMarkdown is the Markdown an editor's Rendered view draws in place of a line that embeds dest in the document at doc, read as the page reads it (beside the document, then in its resources folder, never out of its folder): a Mermaid diagram (.mmd) as a mermaid fence, a Vega-Lite chart (.chart.json) as a vega-lite fence, a table (.csv) as a Markdown table of at most rows rows (0: maxTableRows). ok is false for any other embed, and for a file that is missing, refused, too large or not CSV: the line stays as written.
func RenderWith ¶ added in v0.1.15
RenderWith renders the Markdown source as format. HTML is a whole page in the named theme (one of Themes), its Mermaid diagrams drawn by the page's own script; theme is ignored for Text.
Types ¶
type EmbedLine ¶ added in v0.1.45
EmbedLine is a source line that holds an image and nothing else, as Markdown is parsed for the page (kind.ParseMarkdown): an editor draws Dest in the line's place when the image is Alone, its paragraph's only content, as the page draws a diagram or a table. From and To are the lines of the paragraph (or setext heading) it is in, whose shape decides whether it is alone.
Only an inline image () is Alone: an editor keeps a line's layout while the lines around it are unchanged, and a reference's (![t][ref]) destination is its definition's, which may be anywhere in the source. The page draws it all the same.
func EmbedLines ¶ added in v0.1.45
EmbedLines are source's lines that hold only an image, in order.
type Options ¶ added in v0.1.15
type Options struct {
// Base is the directory the source's relative links are read from: each becomes the file: URL
// of the file it names there, so the page's links reach their files wherever it is written. ""
// writes every link as the source has it.
Base string
// SourceSpans puts each block element's source bytes on it (data-src="start-end"), for a
// view that follows the editor: the GUI's native HTML preview scrolls to the cursor's block.
SourceSpans bool
// Document is the source's own file on disk. Its embeds () of a Mermaid diagram
// (.mmd), a Vega-Lite chart (.chart.json), a table (.csv) or an image are read beside it, or in
// its resources folder, and drawn in the page (embed.go). "" draws each as its alt text.
Document string
// TableRows is how many rows an embedded table, or a csv fence's, shows (0: 1000); TableWidth
// is the width, in characters, its columns are fit in: those that fit are shown, and the table
// says how many are not (0: any width, 64 columns at most). For a view narrower than a
// browser: the GUI's Rendered view of a note.
TableRows, TableWidth int
}
Options are what a render reads besides the source, its format and its theme.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mermaid is mermaid.js, vendored: the diagrams a page draws from its ```mermaid blocks, drawn as the Mermaid project draws them.
|
Package mermaid is mermaid.js, vendored: the diagrams a page draws from its ```mermaid blocks, drawn as the Mermaid project draws them. |