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

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:

FunctionUse
escapeAny text: HTML-encoded, markup shown as text
field_valueA metadata value: escape, or “(none)” when blank
format_source, place_label, grid_suffix, positionThe parts of a location line
capitalizeA 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:

ScriptUsed byRole
search.jsBook index, map pagebindSearch: hides the items whose data-search doesn’t match, ignoring case and accents, or that fail an extra test (the index’s filters)
tabs.jsBook page, map pagebindTabs: shows the panel of the selected tab; a tab with a data-hash also follows the URL hash
map_view.jsMap page, embed pagemapView: the Leaflet map, its overlays and the URL
map_index.jsMap pageThe 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.