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

@ -95,11 +95,21 @@ describe('Document Title', () => {
})
it('markdown syntax removed third', () => {
cy.get('a')
.get('@codeinput')
cy.get('@codeinput')
.fill(`# ${title} _asd_`)
cy.title()
.should('eq', `${title} asd - HedgeDoc @ ${branding.name}`)
})
it('katex code looks right', () => {
cy.get('@codeinput')
.fill(`# $\\alpha$-foo`)
cy.get('.markdown-body > h1')
.should('contain', 'α')
cy.get('@codeinput')
.type('\n\ntest\n')
cy.title()
.should('eq', `α-foo - HedgeDoc @ ${branding.name}`)
})
})
})

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') {