code wiki / _hdl_build / nx_html_head.nx

nx_html_head.nx source

↩ module page · 54 lines · 2751 B

1// nx_html_head.nx -- THE ONE canonical accessible document head for every page emitter. 2// 3// WHY THIS EXISTS (debt seq702): a grep of the lang-less signature `<html><head>` across 4// the emitter tree found 84 distinct source files -- 19 test gates and 65 LIVE-PAGE 5// EMITTERS -- each hand-rolling its own <html><head><title>...</head><body> literal with 6// no lang attribute and no meta viewport. That count is a FLOOR: the scan hit its output 7// cap at 116 match lines, so more exist. Patching them one at a time costs 65+ build/promote 8// cycles AND leaves emitter 66 free to bake the same bad head. This library closes the class. 9// 10// Same shape as nx_gate_verdict for gates (D001): a shared base the emitters delegate to, 11// adopted MIGRATE-ON-TOUCH. Rule 15, DRY through shared libraries. 12// 13// USAGE -- three calls, composes around whatever <style> the emitter already has: 14// o = nxh_head_open(out, o, "My Page Title" as *u8) // doctype+lang+charset+viewport+title 15// o = <emitter appends its own <style>...</style> exactly as before> 16// o = nxh_body_open(out, o) // </head><body><main> 17// ... page content ... 18// o = nxh_close(out, o) // </main></body></html> 19// 20// The three things this guarantees are exactly the three nx_page_verify checks that no 21// stylesheet can supply: lang= on <html>, <meta name=viewport>, and a <main> landmark. 22// (nx_page_verify's lang/viewport checks were themselves false-passing until seq676 made 23// them structural -- so measure adoption with the REPAIRED verifier, not a banked number.) 24 25// byte-copy a NUL-terminated literal into out at offset o; returns the new offset. 26// No syscalls, no imports -- deliberately dependency-free so ANY emitter can adopt it. 27func nxh_lit(out: *u8, o: i64, s: *u8) -> i64 { 28 var i: i64 = 0 29 while s[i] != (0 as u8) { 30 out[o + i] = s[i] 31 i = i + 1 32 } 33 return o + i 34} 35 36// <!doctype html><html lang="en"><head><meta charset><meta viewport><title>TITLE</title> 37// Stops before <style> so the caller keeps full control of its own CSS. 38func nxh_head_open(out: *u8, o: i64, title: *u8) -> i64 { 39 var p: i64 = o 40 p = nxh_lit(out, p, "<!doctype html><html lang=\"en\"><head><meta charset=\"utf-8\"><meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"><title>" as *u8) 41 p = nxh_lit(out, p, title) 42 p = nxh_lit(out, p, "</title>" as *u8) 43 return p 44} 45 46// close <head>, open <body> and the <main> landmark 47func nxh_body_open(out: *u8, o: i64) -> i64 { 48 return nxh_lit(out, o, "</head><body><main>" as *u8) 49} 50 51// close <main>, <body>, <html> 52func nxh_close(out: *u8, o: i64) -> i64 { 53 return nxh_lit(out, o, "</main></body></html>" as *u8) 54}