@@ -12,18 +12,37 @@ import { NON_UNWRAPPABLE_TYPES } from './utils'
12
12
export default ( opts : RemarkMDCOptions = { } ) => {
13
13
const canContainEols = [ 'textComponent' ]
14
14
15
+ const experimentalCodeBlockYamlProps = ( node : Container ) => {
16
+ if (
17
+ node . children ?. length &&
18
+ node . children [ 0 ] . type === 'code' &&
19
+ node . children [ 0 ] . lang === 'yaml' &&
20
+ node . children [ 0 ] . meta === '[props]'
21
+ ) {
22
+ node . rawData = node . children [ 0 ] . value as string
23
+ node . mdc = node . mdc || { }
24
+ node . mdc . codeBlockProps = true
25
+ node . children ! . splice ( 0 , 1 )
26
+ }
27
+ }
15
28
const experimentalAutoUnwrap = ( node : Container ) => {
16
29
if ( opts . experimental ?. autoUnwrap && NON_UNWRAPPABLE_TYPES . includes ( node . type ) ) {
17
30
const nonSlotChildren = ( node . children ) . filter ( ( child : any ) => child . type !== 'componentContainerSection' )
18
31
if ( nonSlotChildren . length === 1 && ! NON_UNWRAPPABLE_TYPES . includes ( nonSlotChildren [ 0 ] . type ) ) {
19
32
const nonSlotChildIndex = node . children . indexOf ( nonSlotChildren [ 0 ] )
20
33
21
- node . children . splice ( nonSlotChildIndex , 1 , ...( nonSlotChildren [ 0 ] as Container ) . children )
34
+ node . children . splice ( nonSlotChildIndex , 1 , ...( ( nonSlotChildren [ 0 ] as Container ) ? .children || [ ] ) )
22
35
node . mdc = node . mdc || { }
23
36
node . mdc . unwrapped = nonSlotChildren [ 0 ] . type
24
37
}
25
38
}
26
39
}
40
+ const processNode = ( node : Container ) => {
41
+ if ( opts . experimental ?. componentCodeBlockYamlProps ) {
42
+ experimentalCodeBlockYamlProps ( node )
43
+ }
44
+ experimentalAutoUnwrap ( node )
45
+ }
27
46
const enter = {
28
47
componentContainer : enterContainer ,
29
48
componentContainerSection : enterContainerSection ,
@@ -109,7 +128,7 @@ export default (opts: RemarkMDCOptions = {}) => {
109
128
container . rawData = dataSection ?. rawData
110
129
}
111
130
112
- experimentalAutoUnwrap ( container )
131
+ processNode ( container )
113
132
114
133
container . children = container . children . flatMap ( ( child : any ) => {
115
134
if ( child . rawData ) {
@@ -153,7 +172,7 @@ export default (opts: RemarkMDCOptions = {}) => {
153
172
*/
154
173
attemptClosingOpenListSection . call ( this , section )
155
174
156
- experimentalAutoUnwrap ( section )
175
+ processNode ( section )
157
176
158
177
this . exit ( token )
159
178
}
0 commit comments