Skip to content
Merged
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
24 changes: 20 additions & 4 deletions apps/svelte.dev/src/routes/content.json/+server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Tokens } from 'marked';
import { index, docs as _docs, examples } from '$lib/server/content';
import { json } from '@sveltejs/kit';
import { transform, slugify, clean } from '@sveltejs/site-kit/markdown';
Expand Down Expand Up @@ -97,7 +98,14 @@ async function content() {
}

async function plaintext(markdown: string) {
const block = ({ text }: any) => `${text}\n`;
const block = (token: Tokens.Blockquote | Tokens.ListItem | Tokens.TableRow) => {
if ('text' in token) {
return token.text;
}
// this should never happen, but abort loudly if it does
console.error(token);
throw new Error('Unexpected token while generating /content.json (see above)');
};

const inline = ({ text }: any) => text;

Expand All @@ -115,13 +123,21 @@ async function plaintext(markdown: string) {
html: () => '\n',
heading: ({ text }) => `${text}\n`,
hr: () => '',
list: block,
list({ items }) {
return items.map(this.listitem!).join('\n');
},
listitem: block,
checkbox: block,
checkbox: () => '',
paragraph({ tokens }) {
return this.parser!.parseInline(tokens);
},
table: block,
table({ header, rows }) {
const tHeader = this.tablerow!({ text: header.map(this.tablecell!).join() });
const tBody = rows
.map((row) => this.tablerow!({ text: row.map(this.tablecell!).join() }))
.join('\n');
return `${tHeader}\n${tBody}`;
},
tablerow: block,
tablecell: ({ text }) => {
return text + ' ';
Expand Down