@@ -281,34 +281,33 @@ export async function render_content_markdown(
281
281
snippets . save ( token . text , html ) ;
282
282
}
283
283
284
- // ensure that `foo`/`bar` is transformed to `foo` / `bar`
285
- // https://github.com/sveltejs/svelte.dev/pull/577
286
- const slash_index =
287
- // @ts -expect-error
288
- token . tokens ?. findIndex ( ( token ) => token . type === 'text' && token . text === '/' ) ?? - 1 ;
289
-
290
- if ( slash_index !== - 1 ) {
291
- // @ts -expect-error
292
- const before = token . tokens [ slash_index - 1 ] ;
293
- // @ts -expect-error
294
- const after = token . tokens [ slash_index + 1 ] ;
295
-
296
- if ( before ?. type === 'codespan' && after ?. type === 'codespan' ) {
297
- // @ts -expect-error
298
- token . tokens [ slash_index ] . raw = token . tokens [ slash_index ] . text = ' / ' ;
284
+ const tokens = 'tokens' in token ? token . tokens : undefined ;
285
+
286
+ if ( tokens ) {
287
+ // ensure that `foo`/`bar` is transformed to `foo` / `bar`
288
+ // https://github.com/sveltejs/svelte.dev/pull/577
289
+ const slash_index =
290
+ tokens . findIndex ( ( token ) => token . type === 'text' && token . text === '/' ) ?? - 1 ;
291
+
292
+ if ( slash_index !== - 1 ) {
293
+ const before = tokens [ slash_index - 1 ] ;
294
+ const after = tokens [ slash_index + 1 ] ;
295
+
296
+ if ( before ?. type === 'codespan' && after ?. type === 'codespan' ) {
297
+ // @ts -expect-error
298
+ tokens [ slash_index ] . raw = tokens [ slash_index ] . text = ' / ' ;
299
+ }
299
300
}
300
- }
301
- } ,
302
- text ( token ) {
303
- // @ts -expect-error I think this is a bug in marked — some text tokens have children,
304
- // but that's not reflected in the types. In these cases we can't just use `token.tokens`
305
- // because that will result in e.g. `<code>` elements not being generated
306
- if ( token . tokens ) {
307
- // @ts -expect-error
308
- return this . parser ! . parseInline ( token . tokens ) ;
309
- }
310
301
311
- return smart_quotes ( token . text , true ) ;
302
+ // smart quotes
303
+ for ( let i = 0 ; i < tokens . length ; i += 1 ) {
304
+ const token = tokens [ i ] ;
305
+
306
+ if ( token . type === 'text' ) {
307
+ token . text = smart_quotes ( token . text , { first : i === 0 , html : true } ) ;
308
+ }
309
+ }
310
+ }
312
311
} ,
313
312
heading ( { tokens, depth } ) {
314
313
const text = this . parser ! . parseInline ( tokens ) ;
0 commit comments