Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions kit/preprocessors/mdsvex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ function renderCode(code) {
);
}

/**
* Svelte 5 raises a compile error (`node_invalid_placement`) when `<tr>` is a
* direct child of `<table>`, because browsers auto-insert `<tbody>` during
* parsing, which would break hydration. Raw-HTML tables in doc markdown
* commonly omit `<tbody>` (e.g. `<table><tr>...`), 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(/(<table\b[^>]*>)(\s*)(<tr\b)/g, "$1$2<tbody>$3")
.replace(/(<\/tr>)(\s*)(<\/table>)/g, "$1</tbody>$2$3");
}

function addFullWidthClassToTables(code) {
return code.replace(/<table\b([^>]*)>/g, (match, attrs) => {
if (attrs.includes('class="')) {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion kit/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<video ... />` style self-closing tags
warning.code === "element_invalid_self_closing_tag"
) {
/// Too noisy
return;
Expand Down