File tree Expand file tree Collapse file tree
packages/slidev/node/commands Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -102,12 +102,26 @@ function firstParagraph(content: string): string {
102102 . slice ( 0 , 300 )
103103}
104104
105+ // Strip markdown link syntax from a heading title — slidev passes the raw
106+ // heading source as `slide.title`, so `# Demo: [foo.bar](https://foo.bar)`
107+ // arrives as `Demo: [foo.bar](https://foo.bar)`. Keep the anchor text, drop
108+ // the URL. Also collapse leftover `**bold**` / `*italic*` / `` `code` ``
109+ // markers so the title reads naturally in social cards.
110+ function stripMd ( s : string ) : string {
111+ return s
112+ . replace ( / \[ ( [ ^ \] ] + ) \] \( [ ^ ) ] + \) / g, '$1' )
113+ . replace ( / \* \* ? ( [ ^ * ] + ) \* \* ? / g, '$1' )
114+ . replace ( / ` ( [ ^ ` ] + ) ` / g, '$1' )
115+ . replace ( / \s + / g, ' ' )
116+ . trim ( )
117+ }
118+
105119function pickTitle ( slide : SlideInfo , deckTitle : string , no : number ) : string {
106120 const fm = slide . frontmatter ?? { }
107121 if ( typeof fm . title === 'string' && fm . title . trim ( ) )
108- return fm . title . trim ( )
122+ return stripMd ( fm . title )
109123 if ( typeof slide . title === 'string' && slide . title . trim ( ) )
110- return slide . title . trim ( )
124+ return stripMd ( slide . title )
111125 return `${ deckTitle } — Slide ${ no } `
112126}
113127
You can’t perform that action at this time.
0 commit comments