Fix empty extracted paragraphs in remark-structure

This commit is contained in:
SonMooSans
2023-11-26 11:32:50 +08:00
parent 7c50221421
commit a883009fdd
3 changed files with 16 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'next-docs-zeta': patch
---
Fix empty extracted paragraphs in `remark-structure`
@@ -116,7 +116,7 @@ const CommandItem = React.forwardRef<
<CommandPrimitive.Item
ref={ref}
className={cn(
'nd-cursor-pointer nd-select-none nd-rounded-lg nd-text-sm aria-selected:nd-bg-accent data-[disabled]:nd-pointer-events-none data-[disabled]:nd-opacity-50 [&_svg]:nd-h-4 [&_svg]:nd-w-4',
'nd-select-none nd-rounded-lg nd-text-sm aria-selected:nd-bg-accent aria-selected:nd-text-accent-foreground data-[disabled]:nd-pointer-events-none data-[disabled]:nd-opacity-50 [&_svg]:nd-h-4 [&_svg]:nd-w-4',
className
)}
{...props}
@@ -27,9 +27,7 @@ export type StructuredData = {
type Options = {
/**
* Types to be scanned
*
* @default ["heading", "blockquote", "paragraph"]
* Types to be scanned, default: `["heading", "blockquote", "paragraph"]`
*/
types?: string[]
}
@@ -48,23 +46,25 @@ export function remarkStructure({
let lastHeading: string | undefined = ''
visit(node, types, (element: MdastContent) => {
const content = flattenNode(element).trim()
if (element.type === 'heading') {
const heading = flattenNode(element)
const slug = slugger.slug(heading)
const slug = slugger.slug(content)
data.headings.push({
id: slug,
content: heading
content
})
lastHeading = slug
return 'skip'
}
data.contents.push({
heading: lastHeading,
content: flattenNode(element)
})
if (content.length > 0) {
data.contents.push({
heading: lastHeading,
content
})
}
return 'skip'
})