From 3baf26273c7ccadbaf458553712634bc3d250584 Mon Sep 17 00:00:00 2001 From: Innei Date: Tue, 30 Jan 2024 16:29:55 +0800 Subject: [PATCH] fix: filter real markdown headings Signed-off-by: Innei --- src/components/modules/toc/TocAside.tsx | 10 +++++++--- src/components/modules/toc/TocFAB.tsx | 5 ++++- src/components/ui/markdown/renderers/heading.tsx | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/components/modules/toc/TocAside.tsx b/src/components/modules/toc/TocAside.tsx index 9962d5085c..1422cd3caa 100644 --- a/src/components/modules/toc/TocAside.tsx +++ b/src/components/modules/toc/TocAside.tsx @@ -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(() => { diff --git a/src/components/modules/toc/TocFAB.tsx b/src/components/modules/toc/TocFAB.tsx index 570c59c4bd..1d0f4c9d45 100644 --- a/src/components/modules/toc/TocFAB.tsx +++ b/src/components/modules/toc/TocFAB.tsx @@ -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({ diff --git a/src/components/ui/markdown/renderers/heading.tsx b/src/components/ui/markdown/renderers/heading.tsx index bf9fa443cb..9fa3feb110 100644 --- a/src/components/ui/markdown/renderers/heading.tsx +++ b/src/components/ui/markdown/renderers/heading.tsx @@ -21,6 +21,8 @@ export const MHeader = (props: HeadingProps) => { { id: nextId, className: 'group flex items-center', + + 'data-markdown-heading': true, } as any, null, <>