1+ import type { Tokens } from 'marked' ;
12import { index , docs as _docs , examples } from '$lib/server/content' ;
23import { json } from '@sveltejs/kit' ;
34import { transform , slugify , clean } from '@sveltejs/site-kit/markdown' ;
@@ -97,7 +98,14 @@ async function content() {
9798}
9899
99100async function plaintext ( markdown : string ) {
100- const block = ( { text } : any ) => `${ text } \n` ;
101+ const block = ( token : Tokens . Blockquote | Tokens . ListItem | Tokens . TableRow ) => {
102+ if ( 'text' in token ) {
103+ return token . text ;
104+ }
105+ // this should never happen, but abort loudly if it does
106+ console . error ( token ) ;
107+ throw new Error ( 'Unexpected token while generating /content.json (see above)' ) ;
108+ } ;
101109
102110 const inline = ( { text } : any ) => text ;
103111
@@ -115,13 +123,21 @@ async function plaintext(markdown: string) {
115123 html : ( ) => '\n' ,
116124 heading : ( { text } ) => `${ text } \n` ,
117125 hr : ( ) => '' ,
118- list : block ,
126+ list ( { items } ) {
127+ return items . map ( this . listitem ! ) . join ( '\n' ) ;
128+ } ,
119129 listitem : block ,
120- checkbox : block ,
130+ checkbox : ( ) => '' ,
121131 paragraph ( { tokens } ) {
122132 return this . parser ! . parseInline ( tokens ) ;
123133 } ,
124- table : block ,
134+ table ( { header, rows } ) {
135+ const outHeader = this . tablerow ! ( { text : header . map ( this . tablecell ! ) . join ( ) } ) ;
136+ const body = this . tablerow ! ( {
137+ text : rows . map ( ( row ) => row . map ( this . tablecell ! ) . join ( ) ) . join ( )
138+ } ) ;
139+ return `${ outHeader } \n${ body } ` ;
140+ } ,
125141 tablerow : block ,
126142 tablecell : ( { text } ) => {
127143 return text + ' ' ;
0 commit comments