mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-24 20:09:02 +00:00
fix(spec): HIPs are Markdown — sync them so they render as Markdown
`sync-hips.ts` copies HIP bodies verbatim from hanzoai/hips and writes them as
`.mdx`. They are CommonMark, and three CommonMark constructs mean something
else to the MDX parser. One of them took the spec build down:
Error occurred prerendering page
"/docs/hip-0126-integrations-connectors-and-the-extension-runtime"
ReferenceError: native is not defined
from this line of prose:
(`name`, `version`, `runtime` ∈ {native, goja, wazero, v8go}, `module`,
MDX read `{native, goja, wazero, v8go}` as an expression. Seventeen more pages
were dropped before they got that far — `<100ms` and `< 5ms` in latency tables
read as tags, `\text{EFE}` in LaTeX read as an expression.
The sync now escapes `{`, `}` and `<` outside fenced code blocks and inline
code spans, and unwraps `<https://…>` autolinks. Every `<` is escaped rather
than guessed at: across all 135 HIPs, every `<name` outside code is a
placeholder (`<plugin>`, `<org>`, `<X%`) or a comparison — there is no real
inline HTML to preserve, and guessing wrong costs the whole page. Code blocks
are untouched, which is where the JSX examples live.
Fixing the synced files was never an option: `build:pre` runs this sync, so
content/docs is rewritten from hanzoai/hips on every build.
turbo run build --filter=spec
before ReferenceError: native is not defined -> build failed
17 pages skipped
after ✓ Generating static pages using 19 workers (140/140) in 4.1s
2 pages skipped -> 0 with the unconditional `<` escape
Co-authored-by: Hanzo Dev <[email protected]>
(cherry picked from commit 8a36820c0cb21253cca3c5e08577281f65aea018)
This commit is contained in:
@@ -45,6 +45,57 @@ function parseFrontmatter(raw: string): { fm: Record<string, string>; body: stri
|
||||
|
||||
const esc = (s: string) => s.replace(/"/g, '\\"')
|
||||
|
||||
const AUTOLINK = /<((?:https?|ftp|mailto):[^\s<>]+)>/g
|
||||
|
||||
/**
|
||||
* HIP bodies are CommonMark; this site renders them as MDX. Three CommonMark
|
||||
* constructs mean something else to the MDX parser, and each one costs the
|
||||
* whole page:
|
||||
*
|
||||
* `{x}` an expression — `runtime ∈ {native, goja}` compiled to a
|
||||
* reference and crashed the render with `native is not defined`
|
||||
* `<https://…>` an autolink — MDX reads `<h` as a tag and chokes on `:`
|
||||
* `<plugin>`, `<X%`, `<100ms` a tag: either an unclosed element or a name
|
||||
* that cannot start with that character
|
||||
*
|
||||
* Escape them so a HIP renders as the Markdown it is. Every `<` outside code
|
||||
* is escaped, without trying to guess which ones open a real element: across
|
||||
* the corpus every one of them is a placeholder (`<plugin>`, `<org>`, `<X%`)
|
||||
* or a comparison, and a guess that reads one wrong costs the entire page.
|
||||
* Fenced code blocks and inline code spans are left alone — that is where the
|
||||
* ecosystem's real JSX examples live, and they are meant to be shown verbatim.
|
||||
*/
|
||||
function mdxSafe(src: string): string {
|
||||
const lines = src.split('\n')
|
||||
let inFence = false
|
||||
let fence = ''
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const trimmed = lines[i].trimStart()
|
||||
if (!inFence && (trimmed.startsWith('```') || trimmed.startsWith('~~~'))) {
|
||||
inFence = true
|
||||
fence = trimmed.slice(0, 3)
|
||||
continue
|
||||
}
|
||||
if (inFence) {
|
||||
if (trimmed.startsWith(fence)) inFence = false
|
||||
continue
|
||||
}
|
||||
// Odd indices are inline code spans; leave them verbatim.
|
||||
lines[i] = lines[i]
|
||||
.split(/(`+[^`]*`+)/)
|
||||
.map((part, index) =>
|
||||
index % 2 === 1
|
||||
? part
|
||||
: part
|
||||
.replace(AUTOLINK, '$1')
|
||||
.replace(/[{}]/g, (brace) => `\\${brace}`)
|
||||
.replace(/</g, '<'),
|
||||
)
|
||||
.join('')
|
||||
}
|
||||
return lines.join('\n')
|
||||
}
|
||||
|
||||
function main() {
|
||||
const { dir, cleanup } = resolveHipsDir()
|
||||
mkdirSync(OUT, { recursive: true })
|
||||
@@ -66,7 +117,7 @@ title: "HIP-${num}: ${esc(title)}"
|
||||
description: "${esc(desc)}"
|
||||
---
|
||||
|
||||
${body.replace(/^#\s+HIP-?\d+[:\s].*\n/, '').trimStart()}
|
||||
${mdxSafe(body.replace(/^#\s+HIP-?\d+[:\s].*\n/, '').trimStart())}
|
||||
`
|
||||
writeFileSync(join(OUT, `${slug}.mdx`), out)
|
||||
entries.push({ num, slug, title, status })
|
||||
|
||||
Reference in New Issue
Block a user