Skip to content

Commit 9157af7

Browse files
committedMar 20, 2025·
fix(stringify): stringify iframe
1 parent 6b47e1d commit 9157af7

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed
 

‎src/runtime/stringify/mdc-remark.ts

+15-36
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,7 @@ const mdcRemarkHandlers: Record<string, (state: State, node: Parents) => unknown
196196
meta
197197
}
198198
},
199-
binding: (state: State, node: Parents) => {
200-
return {
201-
type: 'textComponent',
202-
name: 'binding',
203-
attributes: node.properties,
204-
children: state.toFlow(state.all(node))
205-
}
206-
},
199+
207200
span: (state: State, node: Parents) => {
208201
const result = {
209202
type: 'textComponent',
@@ -216,30 +209,12 @@ const mdcRemarkHandlers: Record<string, (state: State, node: Parents) => unknown
216209

217210
return result
218211
},
219-
video: (state: State, node: Parents) => {
220-
return {
221-
type: 'textComponent',
222-
name: 'video',
223-
attributes: node.properties,
224-
children: state.toFlow(state.all(node))
225-
}
226-
},
227-
'nuxt-img': (state: State, node: Parents) => {
228-
return {
229-
type: 'textComponent',
230-
name: 'nuxt-img',
231-
attributes: node.properties,
232-
children: state.toFlow(state.all(node))
233-
}
234-
},
235-
'nuxt-picture': (state: State, node: Parents) => {
236-
return {
237-
type: 'textComponent',
238-
name: 'nuxt-picture',
239-
attributes: node.properties,
240-
children: state.toFlow(state.all(node))
241-
}
242-
},
212+
binding: createTextComponent('binding'),
213+
iframe: createTextComponent('iframe'),
214+
video: createTextComponent('video'),
215+
'nuxt-img': createTextComponent('nuxt-img'),
216+
'nuxt-picture': createTextComponent('nuxt-picture'),
217+
br: createTextComponent('br'),
243218
table: (state: State, node: Parents) => {
244219
visit(node, (node) => {
245220
// @ts-expect-error: custom type
@@ -303,12 +278,16 @@ const mdcRemarkHandlers: Record<string, (state: State, node: Parents) => unknown
303278

304279
state.patch(node, result)
305280
return result
306-
},
307-
br(state: State, node: Parents) {
281+
}
282+
}
283+
284+
function createTextComponent(name: string) {
285+
return (state: State, node: Parents) => {
308286
return {
309287
type: 'textComponent',
310-
name: 'br',
311-
attributes: node.properties
288+
name,
289+
attributes: node.properties,
290+
children: node.children ? state.toFlow(state.all(node)) : undefined
312291
}
313292
}
314293
}

0 commit comments

Comments
 (0)
Please sign in to comment.