March Docs

ScrollCode

ScrollCode module — helpers for producing fenced code-block output.

Cells that want their stdout to be rendered with syntax highlighting can emit a CommonMark-style fenced code block tagged with a language. The notebook frontend (Stage 1.3 of specs/parity-plan.md) dispatches on the opening fence and hands the body to the CodeMirror highlighter.

Design:

  • fenced/2 is the only public function. It builds a markdown fence
  whose length adapts to the body so pathological inputs (bodies that
  contain backtick runs of their own) still round-trip.
- Private helpers (rtrim_newlines, longest_backtick_run, make_fence,
  repeat_char) are pfn so tests and internal callers can access them
  without enlarging the public surface.

Functions

fnfencedfenced(lang : String, value : String) : String#

Build a CommonMark fenced code block containing value, tagged with lang.

The fence length adapts so the block survives bodies containing backtick runs: if the body contains a line of 3 backticks, the fence grows to 4;

  1. Trailing newlines on value are trimmed so the closing

fence sits on its own line without an extra blank line above it.

Examples

  march> ScrollCode.fenced("json", "{}")
  "```json\n{}\n```"
  march> ScrollCode.fenced("text", "")
  "```text\n```"
  march> ScrollCode.fenced("", "hi")
  "```\nhi\n```"
  march> ScrollCode.fenced("md", "```")
  "````md\n```\n````"