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 Colors(theme string) (background, foreground, muted, border string)
- func DiagramPage(source, theme string) ([]byte, error)
- func EmbedDiagram(doc, dest string) (string, bool)
- func EmbedImage(doc, dest string) ([]byte, bool)
- func EmbedMarkdown(doc, dest string, rows int) (string, bool)
- func OutputMarkdown(doc, p 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 Site(docs string, opts SiteOptions, write func(rel string, page []byte) error) error
- func ThemeOf(tuiTheme string) string
- func Themes() []string
- type Chrome
- type EmbedLine
- type Format
- type NavItem
- type Options
- type SiteOptions
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 Colors ¶ added in v0.2.0
Colors is a theme's page colours, for what is drawn in its palette (a chart): its background, its text, its muted text and its borders, as #rrggbb; dark's for a theme it does not have.
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 EmbedImage ¶ added in v0.2.1
EmbedImage is the bytes of the image dest names, found as the page finds an embed (beside doc, then in its resources folder) and within the page's limit for one image, for the Rendered view to draw. A file that is not an image (imageTypes), a URL, or one out of the folder is not.
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 OutputMarkdown ¶ added in v0.2.1
OutputMarkdown is one output file of a lab note's cell (lab.Outputs, a path in doc's folder) as the Rendered view draws it: text as a text fence; a diagram, a chart or a table as EmbedMarkdown draws it. An image is EmbedImage's, not Markdown: false.
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.
func Site ¶ added in v0.2.0
Site builds the site docs/site.toml describes, handing each page and its path in the site to write, and ".nojekyll" last, so GitHub Pages serves the site as it is. It writes nothing itself.
Types ¶
type Chrome ¶ added in v0.2.0
type Chrome struct {
Site string // the site's title, linking to its root
Page string // this page's title: the document's <title> is "Page · Site"
Root string // the path from this page to the site's root: "", "../", "../../"
Prev, Next *NavItem // within the page's section
}
Chrome is a site page's frame, drawn by the page in its palette: the site's title, the sidebar, and the previous and next pages of its section. Every Href is relative to the page.
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 NavItem ¶ added in v0.2.0
type NavItem struct {
NavItem is a sidebar entry: a section with its pages, a page, or a link out.
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
// Links maps a relative link's destination, as written, to the URL the page writes; ok false
// keeps it as written. Base, when set, is the file: mapping (fileURL) and wins over Links. For a
// site: a link to another page reaches that page (site.go).
Links func(dest string) (url string, ok bool)
// Chrome is the frame around the body: a site's sidebar and previous/next. nil: a bare page.
Chrome *Chrome
// Chart draws a Vega-Lite spec as inline SVG in the page's theme. It draws a .chart.json embed
// and a vega-lite fence. Its error says why it could not (golib's gui/vegalite's own words, a
// chart outside its subset): the spec is then the <pre class="vega-lite"> it is without Chart,
// captioned "chart not drawn: <the error>" (chartFallback). nil keeps every spec, uncaptioned.
// The GUI build gives one (golib's gui/vegalite); core/export draws none of its own.
Chart func(spec []byte, theme string) (svg string, err error)
}
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. |