Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Transformer Reference

Quick reference for all available transformers.

Summary table

TransformerArgumentsDescription
trimnoneRemove whitespace from both ends
trimStartnoneRemove whitespace from the start
trimEndnoneRemove whitespace from the end
indentstring (optional), bool (optional)Prepend string to each line
prefixstring (optional)Prepend string to entire content
suffixstring (optional)Append string to entire content
linePrefixstring (optional), bool (optional)Prepend string to each line
lineSuffixstring (optional), bool (optional)Append string to each line
wrapstring (optional)Wrap content with string on both sides
codenoneWrap in inline code backticks
codeBlocklanguage (optional)Wrap in fenced code block
replacesearch, replacement (both required)Replace all occurrences

Alias table

Primary nameAlias
trimStarttrim_start
trimEndtrim_end
codeBlockcode_block
linePrefixline_prefix
lineSuffixline_suffix

Detailed reference

trim

|trim

Removes leading and trailing whitespace (spaces, tabs, newlines).

Arguments: none

Example:

InputOutput
\n hello \nhello

trimStart

|trimStart

Removes leading whitespace only.

Arguments: none


trimEnd

|trimEnd

Removes trailing whitespace only.

Arguments: none


indent

|indent:"  "
|indent:"  ":true
|indent

Prepends the given string to each line. By default, empty lines are left empty. Pass true as a second argument to also indent empty lines.

Arguments: 0-2 (string, optional boolean)

  • First argument: the indent string (defaults to empty string)
  • Second argument: true to include empty lines, false or omitted to skip them

Example:

Input:

line 1

line 3

With |indent:" " (default — skips empty lines):

  line 1

  line 3

With |indent:" ":true, every line gets the indent — including empty lines (which become lines containing only the indent string).


prefix

|prefix:"# "
|prefix

Prepends the string to the entire content (once, not per-line).

Arguments: 0-1 string


suffix

|suffix:"\n"
|suffix

Appends the string to the entire content.

Arguments: 0-1 string


linePrefix

|linePrefix:"// "
|linePrefix:"//! ":true
|line_prefix:"// "

Prepends the string to each line. By default, empty lines are left empty. Pass true as a second argument to also prefix empty lines — essential for code comment blocks.

Arguments: 0-2 (string, optional boolean)

  • First argument: the prefix string (defaults to empty string)
  • Second argument: true to include empty lines, false or omitted to skip them

Example:

Input:

A fast HTTP client.

Supports async and blocking modes.

With |linePrefix:"/// ":true:

/// A fast HTTP client.
///
/// Supports async and blocking modes.

Without true, the empty line would be left blank (breaking Rust doc comments).


lineSuffix

|lineSuffix:" \\"
|lineSuffix:";":true
|line_suffix:" \\"

Appends the string to each line. By default, empty lines are left empty. Pass true as a second argument to also suffix empty lines.

Arguments: 0-2 (string, optional boolean)

  • First argument: the suffix string (defaults to empty string)
  • Second argument: true to include empty lines, false or omitted to skip them

wrap

|wrap:"**"

Wraps the entire content: prepends and appends the same string.

Arguments: 0-1 string

Example:

InputWith |wrap:"**"
bold text**bold text**

code

|code

Wraps the content in inline code backticks.

Arguments: none

Example:

InputOutput
my-lib`my-lib`

codeBlock

|codeBlock:"rust"
|codeBlock
|code_block:"typescript"

Wraps the content in a fenced code block. The optional argument specifies the language.

Arguments: 0-1 string (language identifier)

Example with language:

Input: let x = 1;

Output:

```rust
let x = 1;
```

replace

|replace:"search":"replacement"

Replaces all occurrences of the search string with the replacement.

Arguments: exactly 2 strings (search, replacement)

Example:

InputWith |replace:"foo":"bar"
foo and foobar and bar

To delete occurrences, use an empty replacement:

|replace:"unwanted":""

Argument validation

mdt validates transformer arguments at runtime:

TransformerExpected args
trim, trimStart, trimEnd, code0
prefix, suffix, wrap, codeBlock0-1
indent, linePrefix, lineSuffix0-2
replaceexactly 2

Passing the wrong number of arguments produces an error:

error: transformer `replace` expects 2 argument(s), got 1