render

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 9 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

This section is empty.

Variables

This section is empty.

Functions

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 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
	// 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.

Jump to

Keyboard shortcuts

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