diff --git a/src/app/state/index.tsx b/src/app/state/index.tsx index abc8b88f..64632a50 100644 --- a/src/app/state/index.tsx +++ b/src/app/state/index.tsx @@ -2,7 +2,6 @@ import { createContext, PropsWithChildren, ReactPortal, useContext, useEffect, u import { Container } from 'react-dom/client' import useHistory from './history' -import useMap, { MapHookHandle } from '../hooks/use-map' import MathEditor, { MathEditorHandle, Props as MathEditorProps } from '../components/math-editor' import { createMathStub } from '../utils/create-math-stub' diff --git a/src/app/utility.ts b/src/app/utility.ts index 29e76f4f..efffe3cb 100644 --- a/src/app/utility.ts +++ b/src/app/utility.ts @@ -1,5 +1,6 @@ import { Attributes } from 'sanitize-html' import { sanitize } from './utils/sanitization' +import { MATH_EDITOR_CLASS } from './utils/create-math-stub' export const eventHandlerWithoutFocusLoss = (fn?: () => void) => (e: React.MouseEvent) => { if (fn) { @@ -89,7 +90,7 @@ export const getAnswer = (html: string) => { img: (tagName: string, attribs: Attributes) => attribs.src ? { tagName, attribs } : { tagName: '', attribs: {} }, span: (tagName: string, attribs: Attributes) => - attribs.class !== 'math-editor-wrapper' ? { tagName, attribs } : { tagName: '', attribs: {} }, + attribs.class !== MATH_EDITOR_CLASS ? { tagName, attribs } : { tagName: '', attribs: {} }, }, }) const answer = new DOMParser().parseFromString(answerHtml, 'text/html').body @@ -100,16 +101,15 @@ export const getAnswer = (html: string) => { }) .join('') - const screenshots = answer.querySelectorAll(':scope > img:not([src*="/math.svg?"])') + const screenshotCount = answer.querySelectorAll(':scope > img:not([src*="/math.svg?"])').length + const equationCount = answer.querySelectorAll(':scope > img[src*="/math.svg?"]').length - const equationCount = answer.querySelectorAll('span.math-editor-wrapper').length - - const isEmpty = answerText?.trim().length === 0 && screenshots.length === 0 && equationCount > 0 + const isEmpty = answerText?.trim().length === 0 && screenshotCount === 0 && equationCount === 0 return { answerHtml: isEmpty ? '' : stripBrsAndTrimFromEnd(answerHtml), answerText: stripNewLinesFromStartAndWhiteSpacesFromEnd(answerText ?? ''), - imageCount: screenshots.length, + imageCount: screenshotCount, } }