@@ -2,6 +2,8 @@ const { join, resolve } = require('node:path');
22
33const clsx = require ( 'clsx' ) ;
44const { createApiPageMD, createInfoPageMD } = require ( 'docusaurus-plugin-openapi-docs/lib/markdown' ) ;
5+ const remark = require ( 'remark' ) ;
6+ const strip = require ( 'strip-markdown' ) ;
57
68const { config } = require ( './apify-docs-theme' ) ;
79const { collectSlugs } = require ( './tools/utils/collectSlugs' ) ;
@@ -362,13 +364,9 @@ module.exports = {
362364 ogImageURL . searchParams . set ( 'title' , result . frontMatter . title ) ;
363365 result . frontMatter . image ??= ogImageURL . toString ( ) ;
364366
365- // Remove import statements and JSX/MDX tags from content
366- const contentText = result . content
367- . replace ( / i m p o r t \s + [ ^ ; ] + ; ? / g, '' ) // Remove import statements
368- . replace ( / < [ ^ > ] + > / g, '' ) // Remove all tags (JSX/MDX)
369- . replace ( / \n + / g, ' ' ) // Replace newlines with space
370- . replace ( / \s + / g, ' ' ) // Collapse whitespace
371- . trim ( ) ;
367+ // Use remark to strip markdown and get plain text
368+ const processed = await remark ( ) . use ( strip ) . process ( result . content ) ;
369+ const contentText = String ( processed ) . replace ( / \s + / g, ' ' ) . trim ( ) ;
372370 // Extract the first sentence (ending with . ! or ?) even if it spans multiple lines
373371 const sentenceMatch = contentText . match ( / ^ ( .* ?[ . ! ? ] ) \s / ) ;
374372 result . frontMatter . description = sentenceMatch ? sentenceMatch [ 1 ] . trim ( ) : contentText ;
0 commit comments