March Docs

Highlight

Highlight — lightweight, server-side syntax highlighting for fenced code blocks. No client-side JavaScript: every token is html-escaped and wrapped in a <span class="tok-*"> so the CSS theme in the host page colors it.

Design / RC discipline (mirrors markdown.march):

  • The tokenizer walks a List(String) of single-character strings
  (`string_chars`) and accumulates output as a List(String) that is
  reversed + joined at the very end.  We NEVER use the recursive
  `acc ++ char` string-accumulation pattern (a known compiled-codegen /
  Perceus RC hazard); multi-character tokens are collected as a
  List(String) of chars and joined with String.join(_, "").
* Every inner scanning loop is a top-level `pfn` (not a self-capturing
  recursive closure) to avoid Perceus RC underflow.
* html_escape is applied to token *text* before it is wrapped in a span,
  so we can never emit unescaped source (e.g. `<` always becomes `&lt;`).

Robustness contract: the tokenizer never crashes and never drops a character. Anything it does not recognize is emitted as escaped text with no span. Correctness (escaping + no character loss) beats completeness.

Functions

fnallows_block_commentallows_block_comment(lang : String) : Bool#
fnallows_dash_commentallows_dash_comment(lang : String) : Bool#
fnallows_hash_commentallows_hash_comment(lang : String) : Bool#
fnallows_slash_commentallows_slash_comment(lang : String) : Bool#
fnhighlighthighlight(lang : String, code : String) : String#

Syntax-highlight a fenced code block. lang is the fence language (may be ""); code is the raw block body. Returns HTML with tokens wrapped in <span class="tok-*"> — always html-escaped, never crashing or dropping chars. An empty/unknown language still gets a generic strings/comments/numbers pass.

fnhtml_escapehtml_escape(s : String) : String#
fnkeywords_forkeywords_for(lang : String) : List(String)#
fnkw_bashkw_bash()#
fnkw_jskw_js()#
fnkw_jsonkw_json()#
fnkw_marchkw_march()#
fnkw_pythonkw_python()#
fnkw_rustkw_rust()#
fnkw_tomlkw_toml()#
fnplainplain(text : String) : String#
fnspanspan(cls : String, text : String) : String#