22
33import type { AstroConfig , AstroIntegration , AstroUserConfig } from 'astro' ;
44import { h as _h , s as _s , type Properties } from 'hastscript' ;
5- import type { Node , Paragraph as P , Parent , Root } from 'mdast' ;
5+ import type { Node , Paragraph as P , Parent , PhrasingContent , Root } from 'mdast' ;
66import {
77 type Directives ,
88 directiveToMarkdown ,
99 type TextDirective ,
1010 type LeafDirective ,
1111} from 'mdast-util-directive' ;
1212import { toMarkdown } from 'mdast-util-to-markdown' ;
13+ import { toString } from 'mdast-util-to-string' ;
1314import remarkDirective from 'remark-directive' ;
1415import type { Plugin , Transformer } from 'unified' ;
1516import { visit } from 'unist-util-visit' ;
@@ -156,16 +157,16 @@ function remarkAsides(options: AsidesOptions): Plugin<[], Root> {
156157 // prop to <Aside>, so when we find a directive label, we store it for the title prop and
157158 // remove the paragraph from the container’s children.
158159 let title = t ( `aside.${ variant } ` ) ;
160+ let titleNode : PhrasingContent [ ] = [ { type : 'text' , value : title } ] ;
159161 const firstChild = node . children [ 0 ] ;
160162 if (
161163 firstChild ?. type === 'paragraph' &&
162164 firstChild . data &&
163- 'directiveLabel' in firstChild . data
165+ 'directiveLabel' in firstChild . data &&
166+ firstChild . children . length > 0
164167 ) {
165- const firstGrandChild = firstChild . children [ 0 ] ;
166- if ( firstGrandChild ?. type === 'text' ) {
167- title = firstGrandChild . value ;
168- }
168+ titleNode = firstChild . children ;
169+ title = toString ( firstChild . children ) ;
169170 // The first paragraph contains a directive label, we can safely remove it.
170171 node . children . splice ( 0 , 1 ) ;
171172 }
@@ -189,7 +190,7 @@ function remarkAsides(options: AsidesOptions): Plugin<[], Root> {
189190 } ,
190191 iconPaths [ variant ]
191192 ) ,
192- { type : 'text' , value : title } ,
193+ ... titleNode ,
193194 ] ) ,
194195 h ( 'section' , { class : 'starlight-aside__content' } , node . children ) ,
195196 ]
0 commit comments