nx_wiki_doc_render.nx
buildroot/runtime/wiki/nx_wiki_doc_render.nx
about
nx_wiki_doc_render.nx -- markdown source -> HTTP-ready HTML body.
Composes existing substrate primitives (per the duplicate-primitives
audit inp NISHI_PRODUCT_OPS_PLATFORM §4):
markdown_block CommonMark subset block-level parser
markdown_inline CommonMark subset inline parser
html_escape HTML-unsafe-byte escape
Adds wiki-specific structural rendering on top:
- NISHIDOC_STANDARD section sidebar TOC (sealed: §1 - §17)
- [N] / [I] / [R] paragraph-tag CSS class injection
- [[wikilink-target]] cross-reference resolution
- Page chrome (header, footer, sidebar)
Status: V1 SEED. 2026-05-27.
WINNER-TIER: BASELINE-C provisional (no incumbent matches the
NISHIDOC-aware rendering + sealed cross-reference
resolution; provisional pending paired render-speed
bench vs pandoc + commonmark.js)
INCUMBENTS: pandoc (Haskell), commonmark.js, markdown-it,
GitHub's gh-markdown, MediaWiki Parsoid
NUMBERS: V1 ships the render path; throughput vs pandoc on
100 docs / 1MB total pending paired bench
GAP: pandoc covers more markdown features (footnotes,
definition lists, raw HTML passthrough); V1 covers
the subset NISHIDOC_STANDARD uses + adds the
NISHIDOC-specific structural rendering pandoc
doesn't ship
PLAN: M-next paired render-speed bench vs pandoc;
extend block syntax to footnotes when an actual
doc needs them
EXEMPTION REASON: n/a; provisional pending measurement
Hygiene-standard compliance per NISHI_CODE_HYGIENE_STANDARD.md:
M1 no NULL creation: callers receive verdict + buffer-offset
via out-param; no *T returns
M2 overflow safety: all length arithmetic checked against caller cap
M3 bounded loops: every while has an explicit max-iter cap
M4 alloc safety: sys_mmap calls use sized named constants
M5 index safety: every src[i] access bounded by len check
dependencies 7 imports · 9 importers
imports: nx_syscalls.nxmarkdown_block.nxmarkdown_inline.nxhtml_escape.nxnx_nishi_page_emit.nxnx_wiki_cite_render.nxnx_wiki_toc.nx
imported by: _wiki_discovery_gate.nxnx_wiki_article.nxnx_wiki_dashboard.nxnx_wiki_doc_handler.nxnx_wiki_projects.nxnx_wiki_queue.nxnx_wiki_routes.nxnx_wiki_search_render.nxnx_wiki_status.nx
structs
| 103 | struct NxWikiDocCtx |
consts
| 65 | const NX_WIKI_DOC_OK: i64 = 0 |
| 66 | const NX_WIKI_DOC_BAD_INPUT: i64 = 1 |
| 67 | const NX_WIKI_DOC_OUTPUT_OVERFLOW: i64 = 2 |
| 68 | const NX_WIKI_DOC_PARSE_FAILED: i64 = 3 |
| 69 | const NX_WIKI_DOC_BROKEN_WIKILINK: i64 = 4 |
| 70 | const NX_WIKI_DOC_LOOP_BUDGET_EXCEEDED: i64 = 5 |
| 71 | const NX_WIKI_DOC_RENDER_NOT_IMPLEMENTED: i64 = 6 |
| 74 | const NX_WIKI_DOC_MAX_SECTIONS: i64 = 32 // NISHIDOC §1-§17 + headroom |
| 75 | const NX_WIKI_DOC_MAX_TITLE_LEN: i64 = 256 |
| 76 | const NX_WIKI_DOC_MAX_WIKILINKS: i64 = 256 |
| 77 | const NX_WIKI_DOC_MAX_WIKILINK_LEN: i64 = 128 |
| 78 | const NX_WIKI_DOC_MAX_PARSE_ITER: i64 = 100000 // hard cap per render call |
| 79 | const NX_WIKI_DOC_HTML_SCRATCH_BYTES: i64 = 32 // for itoa + small temp writes |
| 80 | const NX_WIKI_DOC_TITLE_SCRATCH_BYTES: i64 = 256 |
| 81 | const NX_WIKI_DOC_CITE_CAP: i64 = 1048576 // 1 MB cite-expanded body buffer (standalone render path) |
| 82 | const NX_WIKI_DOC_MD_TMP_CAP: i64 = 1048576 // 1 MB markdown-HTML temp (R4 TOC/id-inject staging) |
| 83 | const NX_WIKI_DOC_INJECT_CAP: i64 = 1310720 // 1.25 MB id-injected copy (headroom for id= attrs) |
| 84 | const NX_WIKI_DOC_TOC_CAP: i64 = 131072 // 128 KB TOC nav |
| 87 | const NX_ASCII_LT: i64 = 0x3C // '<' |
| 88 | const NX_ASCII_GT: i64 = 0x3E // '>' |
| 89 | const NX_ASCII_QUOT: i64 = 0x22 // '"' |
| 90 | const NX_ASCII_LBRACKET: i64 = 0x5B // '[' |
| 91 | const NX_ASCII_RBRACKET: i64 = 0x5D // ']' |
| 92 | const NX_ASCII_LF: i64 = 0x0A // '\n' |
| 93 | const NX_ASCII_CR: i64 = 0x0D // '\r' |
| 94 | const NX_ASCII_HASH: i64 = 0x23 // '#' |
| 95 | const NX_ASCII_SP: i64 = 0x20 // ' ' |
| 96 | const NX_ASCII_SECTION: i64 = 0xA7 // '§' first UTF-8 byte (sentinel for §<NN>) |
| 266 | const NX_WIKI_DOC_NAME_ENTRY_BYTES: i64 = 64 |
| 267 | const NX_WIKI_DOC_NAME_MAX_LEN: i64 = 63 |
| 272 | const NX_WIKI_DOC_NAME_SCAN_CAP: i64 = 1000 |
functions
| 149 | func nx_wiki_doc_ctx_init(ctx: *NxWikiDocCtx, |
| 195 | func nx_wiki_doc_write_byte(ctx: *NxWikiDocCtx, b: i64) -> i64 |
| 203 | func nx_wiki_doc_write_bytes(ctx: *NxWikiDocCtx, src: *u8, n: i64) -> i64 called by 1: nx_wiki_doc_write_z |
| 222 | func nx_wiki_doc_write_run(ctx: *NxWikiDocCtx, src: *u8, n: i64) -> i64 called by 1: nx_wiki_doc_render |
| 237 | func nx_wiki_doc_write_z(ctx: *NxWikiDocCtx, s: *u8) -> i64 |
| 248 | func nx_wiki_doc_write_escaped(ctx: *NxWikiDocCtx, src: *u8, n: i64) -> i64 |
| 274 | func nx_wiki_doc_name_resolves(ctx: *NxWikiDocCtx, name: *u8, name_n: i64) -> i64 called by 1: nx_wiki_doc_postpass_wikilinks |
| 323 | func nx_wiki_doc_preprocess_wikilinks(ctx: *NxWikiDocCtx, called by 1: nx_wiki_doc_render |
| 353 | func nx_wiki_doc_postpass_wikilinks(ctx: *NxWikiDocCtx, |
| 532 | func nx_wiki_doc_postpass_cite(ctx: *NxWikiDocCtx, prefix: *u8, |
| 634 | func nx_wiki_doc_ctx_set_meta(ctx: *NxWikiDocCtx, called by 1: nx_wiki_dashboard_handle |
| 680 | func nx_wiki_doc_emit_css(ctx: *NxWikiDocCtx) -> i64 |
| 700 | func nx_wiki_doc_meta(ctx: *NxWikiDocCtx, name_z: *u8, name_n: i64, |
| 709 | func nx_wiki_doc_write_header_v1(ctx: *NxWikiDocCtx, |
| 779 | func nx_wiki_doc_write_header(ctx: *NxWikiDocCtx, doc_title: *u8, doc_title_n: i64) -> i64 |
| 800 | func nx_wiki_doc_write_footer(ctx: *NxWikiDocCtx) -> i64 |
| 814 | func nx_wiki_doc_render(ctx: *NxWikiDocCtx, |
| 895 | func nx_wiki_doc_wikilinks_resolved(ctx: *NxWikiDocCtx) -> i64 |
| 900 | func nx_wiki_doc_wikilinks_broken(ctx: *NxWikiDocCtx) -> i64 |