Skip to content

Commit

Permalink
fix: filter real markdown headings
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Jan 30, 2024
1 parent 5915e47 commit 3baf262
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/components/modules/toc/TocAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ export const TocAside = forwardRef<
if (!$article) {
return []
}
return [
...$article.querySelectorAll('h1,h2,h3,h4,h5,h6'),
] as HTMLHeadingElement[]
return [...$article.querySelectorAll('h1,h2,h3,h4,h5,h6')].filter(
($heading) => {
if (($heading as HTMLElement).dataset['markdownHeading'] === 'true')
return true
return false
},
) as HTMLHeadingElement[]
}, [$article, updated])

useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/components/modules/toc/TocFAB.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export const TocFAB = () => {
...$mainMarkdownRender.querySelectorAll('h1,h2,h3,h4,h5,h6'),
] as HTMLHeadingElement[]

return $headings
return $headings.filter(($heading) => {
if ($heading.dataset['markdownHeading'] === 'true') return true
return false
})
}, [])
const presentToc = useCallback(() => {
const dispose = present({
Expand Down
2 changes: 2 additions & 0 deletions src/components/ui/markdown/renderers/heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const MHeader = (props: HeadingProps) => {
{
id: nextId,
className: 'group flex items-center',

'data-markdown-heading': true,
} as any,
null,
<>
Expand Down

0 comments on commit 3baf262

Please sign in to comment.