diff --git a/kit/preprocessors/mdsvex/index.js b/kit/preprocessors/mdsvex/index.js index 39dceafb..40bd6a23 100644 --- a/kit/preprocessors/mdsvex/index.js +++ b/kit/preprocessors/mdsvex/index.js @@ -34,6 +34,20 @@ function renderCode(code) { ); } +/** + * Svelte 5 raises a compile error (`node_invalid_placement`) when `` is a + * direct child of ``, because browsers auto-insert `` during + * parsing, which would break hydration. Raw-HTML tables in doc markdown + * commonly omit `` (e.g. `
...`), so add it explicitly — + * the resulting DOM is identical to what browsers produced for the old output. + * @param {string} code + */ +function wrapTableRowsInTbody(code) { + return code + .replace(/(]*>)(\s*)($3") + .replace(/(<\/tr>)(\s*)(<\/table>)/g, "$1$2$3"); +} + function addFullWidthClassToTables(code) { return code.replace(/]*)>/g, (match, attrs) => { if (attrs.includes('class="')) { @@ -68,6 +82,7 @@ export const mdsvexPreprocess = { const processed = await _mdsvexPreprocess.markup({ content, filename }); processed.code = renderKatex(processed.code, markedKatex); processed.code = renderCode(processed.code, filename); + processed.code = wrapTableRowsInTbody(processed.code); if (stretchTables) { processed.code = addFullWidthClassToTables(processed.code); } diff --git a/kit/svelte.config.js b/kit/svelte.config.js index 910d2bae..5ae59234 100644 --- a/kit/svelte.config.js +++ b/kit/svelte.config.js @@ -53,7 +53,9 @@ const config = { if ( warning.message.includes("unused export property") || warning.code?.startsWith("a11y") || - warning.message.includes("A11y") + warning.message.includes("A11y") || + // md-generated doc content is full of `