Documentation
¶
Overview ¶
Package render turns a document and its run results back into markdown.
Index ¶
- Constants
- func At(r *run.Result) string
- func Clear(d *doc.Document) []byte
- func DropEarlierRuns(src []byte, b *doc.Block, drop func(e doc.Entry) bool) []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 ¶
const Masked = "(secret)"
Masked stands for a secret block's code and output when Options.MaskSecrets is set.
Variables ¶
This section is empty.
Functions ¶
func At ¶ added in v1.6.0
At is r's start time as an output's at= writes it: UTC, RFC 3339 to the second. It is "" for a result with no start time.
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 DropEarlierRuns ¶ added in v1.7.0
DropEarlierRuns is src with the earlier runs of block b that drop says to drop taken out from under its output, and the rest numbered again from 1, newest first. Dropping all of them leaves the current output as it is. src must be the source b was parsed from.
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
// MaskSecrets prints a block marked secret with "(secret)" in place
// of its code and its output, run or saved, for a report someone
// else may read: secret keeps the output out of the file, and a
// report shouldn't carry it out either.
MaskSecrets 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
// InSource, if set, reports whether r's output is already in the
// document's source, written there by an earlier write-back of the
// same run, as mdsh-gui does as each run ends. Write-back then
// replaces that output instead of pushing it down as an earlier run
// of a block with history=.
InSource func(r *run.Result) bool
// History prints each block's earlier runs, kept by history=N, under
// its output, newest first, each under a line saying how far back
// it is, when it ran and its exit status. Otherwise printing shows
// the current output only. Write-back always keeps them.
History bool
}
Options control what Markdown prints.