@@ -24,6 +24,44 @@ import { cn, formatDate } from '@/lib/utils';
2424import Filter from '../datasets/components/FIlter/Filter' ;
2525import Styles from '../datasets/dataset.module.scss' ;
2626
27+ // Helper function to strip markdown and HTML tags for card preview
28+ const stripMarkdown = ( markdown : string ) : string => {
29+ if ( ! markdown ) return '' ;
30+ return markdown
31+ // Remove code blocks first (before other replacements)
32+ . replace ( / ` ` ` [ \s \S ] * ?` ` ` / g, '' )
33+ // Remove inline code
34+ . replace ( / ` ( [ ^ ` ] + ) ` / g, '$1' )
35+ // Remove images
36+ . replace ( / ! \[ ( [ ^ \] ] * ) \] \( [ ^ \) ] + \) / g, '$1' )
37+ // Remove links
38+ . replace ( / \[ ( [ ^ \] ] + ) \] \( [ ^ \) ] + \) / g, '$1' )
39+ // Remove headers
40+ . replace ( / ^ # { 1 , 6 } \s + / gm, '' )
41+ // Remove bold
42+ . replace ( / \* \* ( [ ^ * ] + ) \* \* / g, '$1' )
43+ . replace ( / _ _ ( [ ^ _ ] + ) _ _ / g, '$1' )
44+ // Remove italic
45+ . replace ( / \* ( [ ^ * ] + ) \* / g, '$1' )
46+ . replace ( / _ ( [ ^ _ ] + ) _ / g, '$1' )
47+ // Remove strikethrough
48+ . replace ( / ~ ~ ( [ ^ ~ ] + ) ~ ~ / g, '$1' )
49+ // Remove blockquotes
50+ . replace ( / ^ \s * > \s + / gm, '' )
51+ // Remove horizontal rules
52+ . replace ( / ^ ( - { 3 , } | _ { 3 , } | \* { 3 , } ) $ / gm, '' )
53+ // Remove list markers
54+ . replace ( / ^ \s * [ - * + ] \s + / gm, '' )
55+ . replace ( / ^ \s * \d + \. \s + / gm, '' )
56+ // Remove HTML tags
57+ . replace ( / < [ ^ > ] * > / g, '' )
58+ // Remove extra whitespace and newlines
59+ . replace ( / \n \s * \n / g, '\n' )
60+ . replace ( / \n / g, ' ' )
61+ . replace ( / \s + / g, ' ' )
62+ . trim ( ) ;
63+ } ;
64+
2765// Interfaces
2866interface Bucket {
2967 key : string ;
@@ -554,7 +592,7 @@ const ListingComponent: React.FC<ListingProps> = ({
554592
555593 const commonProps = {
556594 title : item . title ,
557- description : item . description ,
595+ description : stripMarkdown ( item . description || '' ) ,
558596 metadataContent : MetadataContent ,
559597 tag : item . tags ,
560598 formats : item . formats ,
0 commit comments