fix: exclude the link icon from the first heading extraction text

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-03-20 10:02:54 +01:00
parent 229d4a4a1d
commit c37cafb635
2 changed files with 8 additions and 3 deletions

View file

@ -37,6 +37,7 @@
h1, h2, h3, h4, h5, h6 { h1, h2, h3, h4, h5, h6 {
.heading-anchor { .heading-anchor {
user-select: none;
font-size: 0.75em; font-size: 0.75em;
margin-top: 0.25em; margin-top: 0.25em;
opacity: 0.3; opacity: 0.3;

View file

@ -14,9 +14,7 @@ import { useCallback, useEffect, useMemo, useRef } from 'react'
* @return the plain text content * @return the plain text content
*/ */
const extractInnerText = (node: ChildNode | null): string => { const extractInnerText = (node: ChildNode | null): string => {
if (!node) { if (!node || isKatexMathMlElement(node) || isHeadlineLinkElement(node)) {
return ''
} else if (isKatexMathMlElement(node)) {
return '' return ''
} else if (node.childNodes && node.childNodes.length > 0) { } else if (node.childNodes && node.childNodes.length > 0) {
return extractInnerTextFromChildren(node) return extractInnerTextFromChildren(node)
@ -33,6 +31,12 @@ const extractInnerText = (node: ChildNode | null): string => {
*/ */
const isKatexMathMlElement = (node: ChildNode): boolean => (node as HTMLElement).classList?.contains('katex-mathml') const isKatexMathMlElement = (node: ChildNode): boolean => (node as HTMLElement).classList?.contains('katex-mathml')
/**
* Determines if the given {@link ChildNode node} is the link icon of a heading.
* @param node The node to check
*/
const isHeadlineLinkElement = (node: ChildNode): boolean => (node as HTMLElement).classList?.contains('heading-anchor')
/** /**
* Extracts the text content of the children of the given {@link ChildNode node}. * Extracts the text content of the children of the given {@link ChildNode node}.
* @param node The node whose children should be processed. The content of the node itself won't be included. * @param node The node whose children should be processed. The content of the node itself won't be included.