fixed title extraction to exclude latex code, but include rendered latex (#946)

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-01-12 18:18:56 +01:00 committed by GitHub
parent 3db6bcf892
commit 9330adf564
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -9,6 +9,11 @@ import React, { useCallback, useEffect } from 'react'
export const useExtractFirstHeadline = (documentElement: React.RefObject<HTMLDivElement>, content: string, onFirstHeadingChange?: (firstHeading: string | undefined) => void): void => {
const extractInnerText = useCallback((node: ChildNode): string => {
let innerText = ''
if ((node as HTMLElement).classList?.contains("katex-mathml")) {
return ''
}
if (node.childNodes && node.childNodes.length > 0) {
node.childNodes.forEach((child) => { innerText += extractInnerText(child) })
} else if (node.nodeName === 'IMG') {