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 {
.heading-anchor {
user-select: none;
font-size: 0.75em;
margin-top: 0.25em;
opacity: 0.3;

View file

@ -14,9 +14,7 @@ import { useCallback, useEffect, useMemo, useRef } from 'react'
* @return the plain text content
*/
const extractInnerText = (node: ChildNode | null): string => {
if (!node) {
return ''
} else if (isKatexMathMlElement(node)) {
if (!node || isKatexMathMlElement(node) || isHeadlineLinkElement(node)) {
return ''
} else if (node.childNodes && node.childNodes.length > 0) {
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')
/**
* 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}.
* @param node The node whose children should be processed. The content of the node itself won't be included.