File tree Expand file tree Collapse file tree 1 file changed +20
-4
lines changed
apps/svelte.dev/src/routes/content.json Expand file tree Collapse file tree 1 file changed +20
-4
lines changed Original file line number Diff line number Diff line change 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 tHeader = this . tablerow ! ( { text : header . map ( this . tablecell ! ) . join ( ) } ) ;
136+ const tBody = rows
137+ . map ( ( row ) => this . tablerow ! ( { text : row . map ( this . tablecell ! ) . join ( ) } ) )
138+ . join ( '\n' ) ;
139+ return `${ tHeader } \n${ tBody } ` ;
140+ } ,
125141 tablerow : block ,
126142 tablecell : ( { text } ) => {
127143 return text + ' ' ;
You can’t perform that action at this time.
0 commit comments