MCPcopy
hub / github.com/marktext/marktext / readSourceState

Function readSourceState

packages/desktop/test/e2e/source-math.spec.ts:26–50  ·  view source on GitHub ↗
(page: Page)

Source from the content-addressed store, hash-verified

24}
25
26const readSourceState = async(page: Page) => {
27 await page.waitForFunction(
28 () => {
29 const root = document.querySelector('.source-code .CodeMirror') as
30 | (Element & { CodeMirror?: CMInstance })
31 | null
32 if (!root || !root.CodeMirror) return false
33 const cm = root.CodeMirror
34 const last = cm.lastLine()
35 cm.getTokenAt({ line: last, ch: cm.getLine(last).length }, true)
36 return true
37 },
38 null,
39 { timeout: 5000 }
40 )
41
42 return page.evaluate(() => {
43 const emTexts = Array.from(document.querySelectorAll('.source-code .CodeMirror .cm-em')).map(
44 (s) => s.textContent
45 )
46 const mathInline = document.querySelectorAll('.source-code .CodeMirror .cm-math-inline').length
47 const mathBlock = document.querySelectorAll('.source-code .CodeMirror .cm-math-block').length
48 return { emTexts, mathInline, mathBlock }
49 })
50}
51
52test.describe('Source view: math tokenization (#4121)', () => {
53 let app: ElectronApplication

Callers 1

Calls 4

lastLineMethod · 0.80
getTokenAtMethod · 0.80
getLineMethod · 0.80
mapMethod · 0.45

Tested by

no test coverage detected