render

package
v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package render turns a document and its run results back into markdown.

Index

Constants

View Source
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

func At(r *run.Result) string

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

func Clear(d *doc.Document) []byte

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

func DropEarlierRuns(src []byte, b *doc.Block, drop func(e doc.Entry) bool) []byte

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 Fence

func Fence(lang, attrs, body string) string

Fence wraps body in a backtick fence long enough that body can't close it.

func Markdown

func Markdown(d *doc.Document, results []*run.Result, opts Options) []byte

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

func NumberLines(s string, first int) string

NumberLines starts each line of s with its number, counting from first.

func Output

func Output(r *run.Result, withStderr bool) string

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.

func Pieces

func Pieces(d *doc.Document, results []*run.Result, opts Options) [][]byte

Pieces renders d like Markdown, cut at its blocks so a run can print the document as it goes. For block i, piece 3i is the prose before it, 3i+1 the block and 3i+2 its output; the last piece is the prose after the last block. results may hold nil for blocks that haven't finished.

func Prose

func Prose(d *doc.Document, results []*run.Result, env []string) []byte

Prose renders d with every runnable block and all output left out. results may hold the include blocks' lines, as from run.Includes.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL