mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05:00
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:
parent
3db6bcf892
commit
9330adf564
2 changed files with 17 additions and 2 deletions
|
@ -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}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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') {
|
||||
|
|
Loading…
Reference in a new issue