Templating
Pages are rendered with Scriban. The .sbn files in
Templates/ hold the HTML; a page writer (BookPageWriter, IndexPageWriter,
LanguageIndexPageWriter, MapPageWriter) builds a plain ScriptObject model (strings, numbers,
lists, no project types) and calls TemplateEngine.Render(template, model). Templates, scripts and
the stylesheet are embedded resources: the published binary has no file to deploy beside it.
Escaping
Scriban doesn’t escape its output. Every value goes through one of the functions of
TemplateFunctions, registered by TemplateEngine.CreateFunctions:
| Function | Use |
|---|---|
escape | Any text: HTML-encoded, markup shown as text |
field_value | A metadata value: escape, or “(none)” when blank |
format_source, place_label, grid_suffix, position | The parts of a location line |
capitalize | A language’s display name |
An attribute value built in C# uses WebUtility.HtmlEncode (the map menu’s data-worldspace, the
book index’s data-search).
Some HTML is built in C# and passed to a template as is: the book content
(BookContentSanitizer.RenderParagraphsHtml, which needs the texture and font resolvers), the
locations, leveled lists, scripts and menu art (*HtmlBuilder, see Performance),
and the map menu, a tree of any depth.
layout.sbn wraps every page. HtmlPage.Wrap takes optional <head> content and a <body> class;
the map pages use them for their libraries and full-window layout.
Templates are parsed once and cached in a ConcurrentDictionary: books render in parallel, and a
parsed Template is safe to share as long as each render has its own TemplateContext.
LoopLimit is unbounded, since a book can have thousands of locations.
Scripts
The scripts are embedded .js files, read by TemplateEngine.Resource and inlined in <script>
elements. Each page includes the shared ones before its own:
| Script | Used by | Role |
|---|---|---|
search.js | Book index, map page | bindSearch: hides the items whose data-search doesn’t match, ignoring case and accents, or that fail an extra test (the index’s filters) |
tabs.js | Book page, map page | bindTabs: shows the panel of the selected tab; a tab with a data-hash also follows the URL hash |
map_view.js | Map page, embed page | mapView: the Leaflet map, its overlays and the URL |
map_index.js | Map page | The menu around the map: links, search, tabs, resizing |
Map data reaches the scripts as a maps-data JSON block, written with System.Text.Json’s default
encoder, which escapes <, > and &.
Native AOT
Register each function as a delegate with ScriptObject.Import(name, delegate). Scriban finds the
static methods of a ScriptObject subclass by reflection only, so Native AOT trims them and the
published binary fails on the first template (“The function escape was not found”) while the JIT
build and the tests pass. A delegate references its method, so the trimmer keeps it.
Import still calls the method by reflection; its IL2026 warning is suppressed on
CreateFunctions. After a Scriban upgrade, run the published binary: the tests run under JIT and
can’t catch this.