Documentation
¶
Overview ¶
Package render turns a document and its run results back into markdown.
Index ¶
- func Clear(d *doc.Document) []byte
- func Fence(lang, attrs, body string) string
- func Markdown(d *doc.Document, results []*run.Result, opts Options) []byte
- func NumberLines(s string, first int) string
- func Output(r *run.Result, withStderr bool) string
- func Pieces(d *doc.Document, results []*run.Result, opts Options) [][]byte
- func Prose(d *doc.Document, results []*run.Result, env []string) []byte
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Clear ¶ added in v1.3.0
Clear returns d's source with every run's output taken out, as if no block had ever run: the output after each block goes, each output copy is left empty so a later run can fill it, and placeholders that hold a block's value ({{#id/...}}, {{$?}}) lose their stored value. Includes keep what they read, since that is the file's text, not a run's output, and a copy that names no block is left as it is.
func Markdown ¶
Markdown renders d with results spliced in after their blocks. Blocks without a result, or that didn't run, keep the output already in the file. results may be nil, and is matched to blocks by position.
func NumberLines ¶ added in v1.1.0
NumberLines starts each line of s with its number, counting from first.
func Output ¶
Output renders one block's result as the markdown that follows it. stderr is included only when withStderr is set; mdsh's own errors always are. It returns "" when there is nothing to show.
Types ¶
type Options ¶
type Options struct {
// HideCode leaves out runnable blocks. Other code blocks are part of
// the prose and stay.
HideCode bool
// HideOutput leaves out output, old and new.
HideOutput bool
// WriteBack renders for saving to the file: the #! line stays,
// placeholders keep their {{...}} form with the new value inside, and
// nothing is left out by show=, show-output= or mdsh:if sections.
// Otherwise the #! line and section markers are dropped, placeholders
// print as values, and conditions decide what shows.
WriteBack bool
// Env is the caller's environment, for {{$VAR}}: only $MDSH_EXPOSE's
// names and mdsh's own MDSH_ variables are read (see run.CallerVars);
// other caller placeholders print as written. Nil means unknown:
// placeholders keep their stored values and conditions read empty.
// Write-back never stores a caller value.
Env []string
// Terminal renders for showing on a terminal: control characters in
// code blocks are shown as ^[ and the like (see termsafe.Visible),
// so the code on the screen is the code that runs.
Terminal bool
// PlainIncludes leaves a number_on include's lines unnumbered, for a
// caller that draws the numbers in a gutter of its own, as mdsh-gui
// does. Otherwise printing puts each line's number in front of it.
PlainIncludes bool
}
Options control what Markdown prints.