diff --git a/apps/client/src/widgets/sidebar/HighlightsList.spec.ts b/apps/client/src/widgets/sidebar/HighlightsList.spec.ts new file mode 100644 index 0000000000..8cfa4ee0c5 --- /dev/null +++ b/apps/client/src/widgets/sidebar/HighlightsList.spec.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "vitest"; +import { extractHighlightsFromStaticHtml } from "./HighlightsList.js"; + +describe("extractHighlightsFromStaticHtml", () => { + it("extracts highlighted text with math equations", () => { + const container = document.createElement("div"); + container.innerHTML = `
+ + Highlighted + + \\(e=mc^2\\) + + math + +
`; + document.body.appendChild(container); + + const highlights = extractHighlightsFromStaticHtml(container); + + // Should extract 3 highlights: "Highlighted ", the math element, and " math" + expect(highlights.length).toBe(3); + + // The math highlight should preserve the .math-tex wrapper + const mathHighlight = highlights.find(h => h.text.includes("math-tex")); + expect(mathHighlight).toBeDefined(); + expect(mathHighlight?.text).toContain('class="math-tex"'); + expect(mathHighlight?.text).toContain("e=mc^2"); + expect(mathHighlight?.attrs.background).toBeTruthy(); + + document.body.removeChild(container); + }); +}); diff --git a/apps/client/src/widgets/sidebar/HighlightsList.tsx b/apps/client/src/widgets/sidebar/HighlightsList.tsx index 1cd874a457..4720d0cd14 100644 --- a/apps/client/src/widgets/sidebar/HighlightsList.tsx +++ b/apps/client/src/widgets/sidebar/HighlightsList.tsx @@ -267,7 +267,7 @@ function ReadOnlyTextHighlightsList() { />; } -function extractHighlightsFromStaticHtml(el: HTMLElement | null) { +export function extractHighlightsFromStaticHtml(el: HTMLElement | null) { if (!el) return []; const { color: defaultColor, backgroundColor: defaultBackgroundColor } = getComputedStyle(el); @@ -279,6 +279,7 @@ function extractHighlightsFromStaticHtml(el: HTMLElement | null) { ); const highlights: DomHighlight[] = []; + const processedMathElements = new Set