Skip to content

Commit f78753c

Browse files
committed
fix: container indentation relative to parent, not lists
1 parent 727e304 commit f78753c

File tree

7 files changed

+1311
-64
lines changed

7 files changed

+1311
-64
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"devDependencies": {
5353
"@nuxt/eslint-config": "^1.10.0",
5454
"@nuxt/kit": "^4.2.1",
55-
"@nuxt/ui": "4.2.0",
55+
"@nuxt/ui": "4.2.1",
5656
"@nuxthub/core": "^0.9.0",
5757
"@nuxtjs/eslint-config-typescript": "latest",
5858
"@types/flat": "^5.0.5",

pnpm-lock.yaml

Lines changed: 7 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/from-markdown.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ export default (opts: RemarkMDCOptions = {}) => {
168168
return child
169169
})
170170

171+
// Fix container nesting in lists
172+
detectInvalidNesting(container)
173+
171174
this.exit(token)
172175
}
173176

@@ -342,3 +345,44 @@ export default (opts: RemarkMDCOptions = {}) => {
342345
exit,
343346
}
344347
}
348+
349+
/**
350+
* Fix container nesting in lists: move containers from list items to parent level
351+
* when they should be direct children of the parent container
352+
*
353+
* @param container - The container to detect invalid nesting in
354+
*/
355+
function detectInvalidNesting(container: Container) {
356+
const extractedContainers: any[] = []
357+
for (const child of container.children) {
358+
if (child.type !== 'list' || !child.children) {
359+
continue
360+
}
361+
362+
for (const listItem of child.children) {
363+
if (listItem.type !== 'listItem' || !listItem.children) {
364+
continue
365+
}
366+
367+
const remainingChildren: any[] = []
368+
for (const itemChild of listItem.children) {
369+
if (
370+
(itemChild.type as string) === 'containerComponent'
371+
&& (itemChild.position?.start?.column || 0) - 4 < (listItem.position?.start?.column || 0)
372+
) {
373+
// Extract container from list item to parent level
374+
extractedContainers.push(itemChild)
375+
}
376+
else {
377+
remainingChildren.push(itemChild)
378+
}
379+
}
380+
listItem.children = remainingChildren
381+
}
382+
}
383+
384+
// Add extracted containers as siblings of the list
385+
if (extractedContainers.length > 0) {
386+
container.children = [...container.children, ...extractedContainers]
387+
}
388+
}

src/to-markdown.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ export default (opts: RemarkMDCOptions = {}) => {
135135
const prefix = ':'.repeat(baseFence + nest)
136136
nest += 1
137137
const exit = context.enter(node.type)
138+
// Reset bullet marker for lists nested containers
139+
context.bulletLastUsed = undefined
138140
let value = prefix + (node.name || '') + label(node, context)
139141

140142
// Move default slot's children to the beginning of the content

0 commit comments

Comments
 (0)