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

Output Editing and Formatting

Under the lantern by the gate, Juniper reads the latest pages aloud, then hands them over without a word.

From here you can hear the market gathering behind you, but only the script is in your hands. That is how you know you are close. The bakery lines are accurate but stiff. The omen lines are eerie in the wrong places. You know this stage of the work: the script functions, and still does not sound like itself. This page is about revising output after it exists, helping inserted values sit naturally in prose, and adding the last bit of shine.

@edit can rewrite what came before

The @edit operator grabs the caller's current output and lets you replace it.

"Opening bell" { @edit x: `<x>, then `<x> again. }
Opening bell, then Opening bell again.

If you do not need the old output, you can discard it completely.

"rough note" { @edit: "Opening bell." }
Opening bell.

@text for values, parameters, and whole functions

Auto-hinting is a wonderful gift to prose-heavy code. It tells Ranty, "Whenever this value shows up in text, give it proper breathing room."

At first, you write the sentence without @text.

Wrong attempt

[$pitch: treat] { Fresh <treat> for moonlit travelers. }
Say hello to Mira. [pitch: saffron buns]

What happened

Say hello to Mira.Fresh saffron buns for moonlit travelers.

The function result is correct, but it lands in the prose too tightly.

# Auto-hint this stored value.
<@text $vendor = Mira>

# Auto-hint the parameter and the whole function result.
[$pitch: @text treat] @text {
  Fresh <treat> for moonlit travelers.
}

Say hello to <vendor>. [pitch: saffron buns]
Say hello to Mira. Fresh saffron buns for moonlit travelers.

Whitespace formatting

[ws-fmt] changes how printed whitespace is normalized in the current scope. Juniper uses that when she wants to test how a sign or chant will breathe on the page.

[ws-fmt: verbatim]Welcome   travelers\n
[ws-fmt: ignore-all]Welcome   travelers
Welcome   travelers
Welcometravelers

Number formatting

[num-fmt] changes how numbers print when they appear in text output. Tavi likes this for labels and coded tokens.

# Print 255 as an alternate, uppercase, padded hexadecimal value.
Lantern tag: `[num-fmt: (:: system = hex; upper = @true; alt = @true; padding = 4)]255\n
Lantern tag: 0x00FF

A few finishing tools

These helpers are not new syntax, but they are excellent for final cleanup.

[trim: "  opening bell  "]\n
[upper: hush]\n
[lower: GLOW]
opening bell
HUSH
glow

More information about output polish can be found in the Ranty documentation for Output modifiers, @text, Whitespace, Numbers, and Strings.

At last the words sound at home beneath these awnings. The bakery patter is warm. The omen lines prickle in the right places. Juniper folds the pages once, crisply, and carries them to the trunk beside the gate where the last parts are waiting. One task remains: make the whole contraption sturdy enough to survive the night.

Previous: Pipes and Argument Spreading | Next: Prototypes, Modules, and Determinism