mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 08:03:19 +00:00
perf(markdown): render preview math as SVG (#5048)
Typeset equations with MathJax before painting the Markdown preview. Load MathJax on demand, preserve accessible MathML, and fall back to KaTeX for unsupported equations.
This commit is contained in:
+1
-1
@@ -526,7 +526,7 @@ test("Markdown preview keeps following find and edits after scrolling the source
|
||||
await content.focus();
|
||||
await page.keyboard.press("Meta+a");
|
||||
await page.keyboard.insertText("- **$`v_0`$ Flat wings.**");
|
||||
await expect(preview.locator("strong .katex annotation")).toHaveText("v_0");
|
||||
await expect(preview.locator("strong [data-math-svg] > svg")).toHaveAttribute("aria-label", "v_0");
|
||||
});
|
||||
|
||||
test("Markdown preview aligns Mermaid diagrams to their container align attribute", async ({ workbench: page }) => {
|
||||
|
||||
@@ -70,6 +70,8 @@
|
||||
"@lezer/common": "^1.5.3",
|
||||
"@lezer/highlight": "^1.2.5",
|
||||
"@lezer/lr": "^1.4.11",
|
||||
"@mathjax/mathjax-tex-font": "4.1.3",
|
||||
"@mathjax/src": "4.1.3",
|
||||
"@plutojl/lang-julia": "^1.2.0",
|
||||
"@replit/codemirror-vim": "6.4.0",
|
||||
"@tanstack/react-virtual": "^3.14.21",
|
||||
|
||||
Generated
+140
@@ -84,6 +84,12 @@ importers:
|
||||
'@lezer/lr':
|
||||
specifier: ^1.4.11
|
||||
version: 1.4.11(patch_hash=1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8)
|
||||
'@mathjax/mathjax-tex-font':
|
||||
specifier: 4.1.3
|
||||
version: 4.1.3
|
||||
'@mathjax/src':
|
||||
specifier: 4.1.3
|
||||
version: 4.1.3
|
||||
'@plutojl/lang-julia':
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0
|
||||
@@ -454,6 +460,9 @@ packages:
|
||||
'@iconify/utils@3.1.7':
|
||||
resolution: {integrity: sha512-JZHlwdID+dy+lTgbYC8NEC4zeugqeYsc6jewvzb4c58kHauJn+X7rNwQjxz5p2qSjqaEeQoLkCIQ9v/H4PK0/w==}
|
||||
|
||||
'@isaacs/nonrecursive-glob-match@1.1.0':
|
||||
resolution: {integrity: sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==}
|
||||
|
||||
'@jridgewell/resolve-uri@3.1.2':
|
||||
resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==}
|
||||
engines: {node: '>=6.0.0'}
|
||||
@@ -522,6 +531,15 @@ packages:
|
||||
'@marijn/find-cluster-break@1.0.4':
|
||||
resolution: {integrity: sha512-Wy0V7+SGUjnF9/TkiM1hKVDPj7jKXduPNboMVtHTA8dySMURWqfg/JZ9E2Sq8JgSJmkl7k7Qe9FLeMSrSraWmQ==}
|
||||
|
||||
'@mathjax/mathjax-newcm-font@4.1.3':
|
||||
resolution: {integrity: sha512-gzAB3dFHilHX1l5x2xUqRL+1jDQt3Fyza1DkEMVXWC4E8SvsGdlgEza47HYi2WhVcgfkvf4zgUGzuhbq3Pjlew==}
|
||||
|
||||
'@mathjax/mathjax-tex-font@4.1.3':
|
||||
resolution: {integrity: sha512-9B78brBEmmAwyumaREIyM1gF2HgDamDIXA36UyeXWxX7XrpLdmoSB5NLIf/c6tEA4L6xNrIdMxfgY6YX/kcSNw==}
|
||||
|
||||
'@mathjax/src@4.1.3':
|
||||
resolution: {integrity: sha512-rIrWquuBSoJuoMBdC/1qD+AUHTorlccPicoVy6P2xbUgnuDBpCcpbHtOAsB8L3hdCHtNBg92lF8e3Fz+pkcQbw==}
|
||||
|
||||
'@mermaid-js/parser@2.0.1':
|
||||
resolution: {integrity: sha512-j37dj/h6p6pots1L7pLPPNuABEEu9WP4OYg9pW1g+nYG331j0+3canE9OagtYdytYvdSAMG+2fKU5cxep6LgjA==}
|
||||
engines: {node: '>=22.12.0'}
|
||||
@@ -605,6 +623,7 @@ packages:
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [riscv64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@oxc-parser/binding-linux-riscv64-musl@0.155.0':
|
||||
resolution: {integrity: sha512-JSlhgoK+/g1TGJI5NuADx2+6syhxnQNLCWLXyO5QLFyetomcr/vIxSdiNlmyAv963YXUzCuwAwRG6npZ5xyJ1A==}
|
||||
@@ -1082,6 +1101,7 @@ packages:
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
'@rolldown/binding-linux-ppc64-gnu@1.2.14':
|
||||
resolution: {integrity: sha512-4+Kl8daPV8NDHaD7mfCcc1pRM+Qg7ab8DyMm5FG5WoZgv4h2i3KFN1CybYBNbQqmuYm7ftJLvmMI1eHYJ22S/Q==}
|
||||
@@ -1095,12 +1115,14 @@ packages:
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [s390x]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@rolldown/binding-linux-x64-gnu@1.2.14':
|
||||
resolution: {integrity: sha512-WxalXzgrLVpKC93xfpaJ3gCXUWzeCr+FRCbDVD2mUAy4L6Vo3lNVz0epUEUpxPWJkLNYUwM4OSIikv36OJ9mLg==}
|
||||
engines: {node: ^20.19.0 || >=22.12.0}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
'@rolldown/binding-linux-x64-musl@1.2.14':
|
||||
resolution: {integrity: sha512-3G3tnAmTpdk9jO3GQtyHXqeFD2SlecfTws/Y3M2mmj9nMBwwuLT4kur8sZKeu7ENUHSpVO3cIsm5A52LEWWwlg==}
|
||||
@@ -1463,6 +1485,10 @@ packages:
|
||||
'@vitest/spy@5.0.5':
|
||||
resolution: {integrity: sha512-lwJRExuH417257Q5wv9QYugN9IMJkoxcrKrYxGPQkBzl7wlNpTUxD/5yNX4ESKVUIShKPgkGchYPFMWOOk0wzw==}
|
||||
|
||||
'@xmldom/xmldom@0.9.12':
|
||||
resolution: {integrity: sha512-5AXjrcMClTryPe9LgZrygpB1lj7s0S9E0+W+AHaVKAVyHanafK86iPSvG5xHVSp/jC+VH1UXu0TAEmY279xH7A==}
|
||||
engines: {node: '>=14.6'}
|
||||
|
||||
'@xterm/addon-fit@0.12.0-beta.334':
|
||||
resolution: {integrity: sha512-fIFQHJ15PER9KhAG24IhA5vF4ysHEKrJgImt/ZqRcahvNUGF1T3WnpJ6bLvlvnsft7bVT0ofBWySx6nxFNAXkA==}
|
||||
peerDependencies:
|
||||
@@ -1498,9 +1524,17 @@ packages:
|
||||
resolution: {integrity: sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==}
|
||||
engines: {node: '>=12'}
|
||||
|
||||
balanced-match@4.0.4:
|
||||
resolution: {integrity: sha512-BLrgEcRTwX2o6gGxGOCNyMvGSp35YofuYzw9h1IMTRmKqttAZZVU67bdb9Pr2vUHA8+j3i2tJfjO6C6+4myGTA==}
|
||||
engines: {node: 18 || 20 || >=22}
|
||||
|
||||
bidi-js@1.1.0:
|
||||
resolution: {integrity: sha512-fX1Onk0tdVPC7obPWB5EbJ1z7NVhLq4m2xZLq2YXBkxzMXIGRpNMU88n0EPgWseKl12J7zXs7qrDxPK4sRs2fg==}
|
||||
|
||||
brace-expansion@5.0.13:
|
||||
resolution: {integrity: sha512-Vh3dmFbc4wZeox7M9I/0L9GfFd83Su4+yCck/OF9Gi/P/dAHn0RT7X4K9R7gMNMhDck3DvhR6QXsnQdjjgwNvQ==}
|
||||
engines: {node: 20 || >=22}
|
||||
|
||||
chai@6.3.0:
|
||||
resolution: {integrity: sha512-XWAtwJ6OHO+tj0EKCs0Y2UamnyOxseZWltU4x2U2wh8g4AigdjwvtUjvLP2tqkA/avxHEtzxNaqGq/YGNwckKg==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -1513,6 +1547,10 @@ packages:
|
||||
resolution: {integrity: sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==}
|
||||
engines: {node: '>=6'}
|
||||
|
||||
commander@14.0.3:
|
||||
resolution: {integrity: sha512-H+y0Jo/T1RZ9qPP4Eh1pkcQcLRglraJaSLoyOtHxu6AapkjWVCy2Sit1QQ4x3Dng8qDlSsZEet7g5Pq06MvTgw==}
|
||||
engines: {node: '>=20'}
|
||||
|
||||
commander@15.1.0:
|
||||
resolution: {integrity: sha512-cgnQ88TRrWcC7pVq46RzJVRMktu3W2RcbnoidnfBsl1bmDCBwJS/udcIZpKoCrbAYYaCqsz1yZCVIgbIaU3ddQ==}
|
||||
engines: {node: '>=22.12.0'}
|
||||
@@ -1774,6 +1812,10 @@ packages:
|
||||
get-tsconfig@4.14.3:
|
||||
resolution: {integrity: sha512-++QEw4DIY7WGoukz+/+A/8dGYPT9l9yIadnmSgZ8Rjr3YVSVDipQSO9CdnJo9ePqFqUUqh+wk9uIaoiAwsiPkA==}
|
||||
|
||||
glob@14.0.6:
|
||||
resolution: {integrity: sha512-OwXjVP2svY5EyLY75Vek96C8qK43gqrt4xsZ+qSILdnaEiJPXkd62mcfUSNx/TQErQRdu5uM5kF67sfONragKw==}
|
||||
engines: {node: 18 || 20 || >=22}
|
||||
|
||||
hachure-fill@0.5.2:
|
||||
resolution: {integrity: sha512-3GKBOn+m2LX9iq+JC1064cSFprJY4jL1jCXTcpnfER5HYE2l/4EfWSGzkPa/ZDBmYI0ZOEj5VHV/eKnPGkHuOg==}
|
||||
|
||||
@@ -1878,6 +1920,7 @@ packages:
|
||||
engines: {node: '>= 12.0.0'}
|
||||
cpu: [arm64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
lightningcss-linux-arm64-musl@1.33.0:
|
||||
resolution: {integrity: sha512-yiO5ROMuYQgXbC60yjZU5CYSFZGKXL0HFATXt9mHJn1+zW55oCtMI9NfcVhYLMFDL7gV7oBPon/EmMMGg2OvtQ==}
|
||||
@@ -1891,12 +1934,14 @@ packages:
|
||||
engines: {node: '>= 12.0.0'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [glibc]
|
||||
|
||||
lightningcss-linux-x64-musl@1.33.0:
|
||||
resolution: {integrity: sha512-RYiYbkokw0trfKqqzfF55lginwEPrD3OJDfTuJzFs1MK6iFnDenaz1fqLLtX4ITG3OktJQXOeTaw1awrBAlZPw==}
|
||||
engines: {node: '>= 12.0.0'}
|
||||
cpu: [x64]
|
||||
os: [linux]
|
||||
libc: [musl]
|
||||
|
||||
lightningcss-win32-arm64-msvc@1.33.0:
|
||||
resolution: {integrity: sha512-1K+MPfLSFVpphzpdbfkhlWk6wBrTObBzS2T6db10PNOZgR9GoVsAWzwNyuhUYYbTp23j+4RrncfujZ4uAzXvwA==}
|
||||
@@ -1950,10 +1995,24 @@ packages:
|
||||
resolution: {integrity: sha512-wlVCp+8eTupfCeeFvoZNNiTuHrvag0P2jz/ILgb/f/6jkVokUefOcujefi8qUe/j2asHiSePncVsz/xzzA80LQ==}
|
||||
engines: {node: '>=22.12.0'}
|
||||
|
||||
mhchemparser@4.2.1:
|
||||
resolution: {integrity: sha512-kYmyrCirqJf3zZ9t/0wGgRZ4/ZJw//VwaRVGA75C4nhE60vtnIzhl9J9ndkX/h6hxSN7pjg/cE0VxbnNM+bnDQ==}
|
||||
|
||||
min-indent@1.0.1:
|
||||
resolution: {integrity: sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg==}
|
||||
engines: {node: '>=4'}
|
||||
|
||||
minimatch@11.0.9:
|
||||
resolution: {integrity: sha512-KCFkfyjqerNlSstjlhIGNXIKZGA/6O4V4RlhZ+Dsr621SPPw0mzlypE9D9ZOoPiVefHID+j7/XuMMlqfD/F60Q==}
|
||||
engines: {node: 20 || >=22}
|
||||
|
||||
minipass@7.1.3:
|
||||
resolution: {integrity: sha512-tEBHqDnIoM/1rXME1zgka9g6Q2lcoCkxHLuc7ODJ5BxbP5d4c2Z5cGgtXAku59200Cx7diuHTOYfSBD8n6mm8A==}
|
||||
engines: {node: '>=16 || 14 >=14.17'}
|
||||
|
||||
mj-context-menu@1.0.0:
|
||||
resolution: {integrity: sha512-OSgBFQRCVhrZwRa9lhqnKcJU92dd/YXgBjup0uyeuj9bOaVsf4myOyrjU4PfhYkdDk6AqVUTov7v5uFMvIbduA==}
|
||||
|
||||
nanoid@3.3.20:
|
||||
resolution: {integrity: sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==}
|
||||
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
|
||||
@@ -1999,6 +2058,9 @@ packages:
|
||||
vite-plus:
|
||||
optional: true
|
||||
|
||||
package-json-from-dist@1.0.1:
|
||||
resolution: {integrity: sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==}
|
||||
|
||||
package-manager-detector@1.9.0:
|
||||
resolution: {integrity: sha512-zAMfbta9nPA8AKkA4WdmNAT8R8s6Dk0/xwPsqNnRidMFcLo1YkLuPDTgs2f64XdzS8vbLNnoJ+uUIkgbz7oRHA==}
|
||||
|
||||
@@ -2008,6 +2070,10 @@ packages:
|
||||
path-data-parser@0.1.0:
|
||||
resolution: {integrity: sha512-NOnmBpt5Y2RWbuv0LMzsayp3lVylAHLPUTut412ZA3l+C4uw4ZVkQbjShYCQ8TCpUMdPapr4YjUqLYD6v68j+w==}
|
||||
|
||||
path-scurry@3.0.0:
|
||||
resolution: {integrity: sha512-1pTbQqH1wIwMi/eleQ5leFTTCkzFsPcgXNjwOA8YGGW/W4/kHT3dssE7Z6NH+zuqNLOzOB0uaD61yl7cAcVhgg==}
|
||||
engines: {node: 18 || 20 || >=22}
|
||||
|
||||
picocolors@1.1.1:
|
||||
resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==}
|
||||
|
||||
@@ -2078,6 +2144,11 @@ packages:
|
||||
resolve-pkg-maps@1.0.0:
|
||||
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
|
||||
|
||||
rimraf@6.1.4:
|
||||
resolution: {integrity: sha512-Fk3reQDVPZUMbEm7Zwxz03BWQMW3V5buSk9aU8OckTrO8A1nQtbqvYsAantGNermwsIsXcuOBqcoJ3HuMELctw==}
|
||||
engines: {node: 20 || >=22}
|
||||
hasBin: true
|
||||
|
||||
robust-predicates@3.0.3:
|
||||
resolution: {integrity: sha512-NS3levdsRIUOmiJ8FZWCP7LG3QpJyrs/TE0Zpf1yvZu8cAJJ6QMW92H1c7kWpdIHo8RvmLxN/o2JXTKHp74lUA==}
|
||||
|
||||
@@ -2114,6 +2185,10 @@ packages:
|
||||
resolution: {integrity: sha512-KGj/8Y43x35aZVDtt+J4mK1hoLGHULMYfSkODJNQjNDC3oW1PqPoxMwo0pLUsWM/UEGzON/NxeHywEfNXNP3Vw==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
speech-rule-engine@5.0.0-rc.4:
|
||||
resolution: {integrity: sha512-3dFcH2QtQNhtvUUc09TxoaEK4WG03B9Z57krFG9jocrKykKGu35BhIkWr0vgEAxZZomEWkeluff69y/EbYzP4Q==}
|
||||
hasBin: true
|
||||
|
||||
std-env@4.3.0:
|
||||
resolution: {integrity: sha512-OtU/EgQ1kIm5KwqQpBC6ZEMXrZRui11w8zgfTWp8cdO9B8OaPsbA8bTHO2P+HNo1VlUTGMVBwPhydu6poeXiag==}
|
||||
|
||||
@@ -2310,6 +2385,9 @@ packages:
|
||||
engines: {node: '>=20.11'}
|
||||
hasBin: true
|
||||
|
||||
wicked-good-xpath@1.3.0:
|
||||
resolution: {integrity: sha512-Gd9+TUn5nXdwj/hFsPVx5cuHHiF5Bwuc30jZ4+ronF1qHK5O7HD0sgmXWSEgwKquT3ClLoKPVbO6qGwVwLzvAw==}
|
||||
|
||||
xml-name-validator@5.0.0:
|
||||
resolution: {integrity: sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==}
|
||||
engines: {node: '>=18'}
|
||||
@@ -2743,6 +2821,8 @@ snapshots:
|
||||
'@iconify/types': 2.0.0
|
||||
import-meta-resolve: 4.2.0
|
||||
|
||||
'@isaacs/nonrecursive-glob-match@1.1.0': {}
|
||||
|
||||
'@jridgewell/resolve-uri@3.1.2': {}
|
||||
|
||||
'@jridgewell/sourcemap-codec@1.6.0': {}
|
||||
@@ -2852,6 +2932,17 @@ snapshots:
|
||||
|
||||
'@marijn/find-cluster-break@1.0.4': {}
|
||||
|
||||
'@mathjax/mathjax-newcm-font@4.1.3': {}
|
||||
|
||||
'@mathjax/mathjax-tex-font@4.1.3': {}
|
||||
|
||||
'@mathjax/src@4.1.3':
|
||||
dependencies:
|
||||
'@mathjax/mathjax-newcm-font': 4.1.3
|
||||
mhchemparser: 4.2.1
|
||||
mj-context-menu: 1.0.0
|
||||
speech-rule-engine: 5.0.0-rc.4
|
||||
|
||||
'@mermaid-js/parser@2.0.1':
|
||||
dependencies:
|
||||
'@chevrotain/types': 13.2.0
|
||||
@@ -3470,6 +3561,8 @@ snapshots:
|
||||
|
||||
'@vitest/spy@5.0.5': {}
|
||||
|
||||
'@xmldom/xmldom@0.9.12': {}
|
||||
|
||||
'@xterm/addon-fit@0.12.0-beta.334(@xterm/xterm@6.1.0-beta.338)':
|
||||
dependencies:
|
||||
'@xterm/xterm': 6.1.0-beta.338
|
||||
@@ -3494,10 +3587,16 @@ snapshots:
|
||||
|
||||
assertion-error@2.0.1: {}
|
||||
|
||||
balanced-match@4.0.4: {}
|
||||
|
||||
bidi-js@1.1.0:
|
||||
dependencies:
|
||||
require-from-string: 2.0.2
|
||||
|
||||
brace-expansion@5.0.13:
|
||||
dependencies:
|
||||
balanced-match: 4.0.4
|
||||
|
||||
chai@6.3.0: {}
|
||||
|
||||
chevrotain@13.2.0:
|
||||
@@ -3510,6 +3609,8 @@ snapshots:
|
||||
|
||||
clsx@2.1.1: {}
|
||||
|
||||
commander@14.0.3: {}
|
||||
|
||||
commander@15.1.0: {}
|
||||
|
||||
commander@7.2.0: {}
|
||||
@@ -3783,6 +3884,12 @@ snapshots:
|
||||
dependencies:
|
||||
resolve-pkg-maps: 1.0.0
|
||||
|
||||
glob@14.0.6:
|
||||
dependencies:
|
||||
minimatch: 11.0.9
|
||||
minipass: 7.1.3
|
||||
path-scurry: 3.0.0
|
||||
|
||||
hachure-fill@0.5.2: {}
|
||||
|
||||
html-encoding-sniffer@7.0.0(@noble/hashes@2.4.0):
|
||||
@@ -3964,8 +4071,21 @@ snapshots:
|
||||
ts-dedent: 2.3.0
|
||||
uuid: 14.0.3
|
||||
|
||||
mhchemparser@4.2.1: {}
|
||||
|
||||
min-indent@1.0.1: {}
|
||||
|
||||
minimatch@11.0.9:
|
||||
dependencies:
|
||||
'@isaacs/nonrecursive-glob-match': 1.1.0
|
||||
brace-expansion: 5.0.13
|
||||
|
||||
minipass@7.1.3: {}
|
||||
|
||||
mj-context-menu@1.0.0:
|
||||
dependencies:
|
||||
rimraf: 6.1.4
|
||||
|
||||
nanoid@3.3.20: {}
|
||||
|
||||
obug@3.0.0: {}
|
||||
@@ -4062,6 +4182,8 @@ snapshots:
|
||||
'@oxlint/binding-win32-ia32-msvc': 1.89.0
|
||||
'@oxlint/binding-win32-x64-msvc': 1.89.0
|
||||
|
||||
package-json-from-dist@1.0.1: {}
|
||||
|
||||
package-manager-detector@1.9.0: {}
|
||||
|
||||
parse5@8.0.1:
|
||||
@@ -4070,6 +4192,11 @@ snapshots:
|
||||
|
||||
path-data-parser@0.1.0: {}
|
||||
|
||||
path-scurry@3.0.0:
|
||||
dependencies:
|
||||
lru-cache: 11.5.3
|
||||
minipass: 7.1.3
|
||||
|
||||
picocolors@1.1.1: {}
|
||||
|
||||
picomatch@4.0.7: {}
|
||||
@@ -4129,6 +4256,11 @@ snapshots:
|
||||
|
||||
resolve-pkg-maps@1.0.0: {}
|
||||
|
||||
rimraf@6.1.4:
|
||||
dependencies:
|
||||
glob: 14.0.6
|
||||
package-json-from-dist: 1.0.1
|
||||
|
||||
robust-predicates@3.0.3: {}
|
||||
|
||||
rolldown@1.2.14:
|
||||
@@ -4175,6 +4307,12 @@ snapshots:
|
||||
|
||||
source-map-js@1.2.2: {}
|
||||
|
||||
speech-rule-engine@5.0.0-rc.4:
|
||||
dependencies:
|
||||
'@xmldom/xmldom': 0.9.12
|
||||
commander: 14.0.3
|
||||
wicked-good-xpath: 1.3.0
|
||||
|
||||
std-env@4.3.0: {}
|
||||
|
||||
string-argv@0.3.2: {}
|
||||
@@ -4296,6 +4434,8 @@ snapshots:
|
||||
|
||||
why-is-node-running@3.2.1: {}
|
||||
|
||||
wicked-good-xpath@1.3.0: {}
|
||||
|
||||
xml-name-validator@5.0.0: {}
|
||||
|
||||
xmlchars@2.2.0: {}
|
||||
|
||||
@@ -137,6 +137,23 @@
|
||||
color: var(--fg-editor, var(--fg-secondary));
|
||||
opacity: 0.8;
|
||||
}
|
||||
.preview :global([data-math-svg]) {
|
||||
position: relative;
|
||||
}
|
||||
.preview :global([data-math-svg="display"]) {
|
||||
display: block;
|
||||
margin: 1em 0;
|
||||
overflow: auto hidden;
|
||||
padding: 2px 0;
|
||||
text-align: center;
|
||||
}
|
||||
.preview :global(mjx-assistive-mml) {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
overflow: hidden;
|
||||
clip-path: inset(50%);
|
||||
user-select: none;
|
||||
}
|
||||
.preview :global(table) {
|
||||
display: block;
|
||||
width: max-content;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
* screen (Structure's Autoscroll from Source).
|
||||
*/
|
||||
import {
|
||||
Suspense,
|
||||
use,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
@@ -24,7 +26,7 @@ import { useMarkdownPreviewFontSize, useMarkdownPreviewLayout } from "@/platform
|
||||
import { maybeEditorService, registerFontZoomSurface } from "@/workbench/contributions";
|
||||
import { editorsFor, setShownLine } from "@/editor/api";
|
||||
import { highlightInto } from "@/editor/lsp/markdown";
|
||||
import { FloatingToolbar, SplitGroup, SplitHandle, SplitPanel, selectableText } from "@/ui";
|
||||
import { FloatingToolbar, Spinner, SplitGroup, SplitHandle, SplitPanel, selectableText } from "@/ui";
|
||||
import {
|
||||
FIND_CURRENT_HIGHLIGHT,
|
||||
FIND_HIGHLIGHT,
|
||||
@@ -42,6 +44,7 @@ import { publishPreviewSelection, publishPreviewTop, stepMarkdownPreviewFontZoom
|
||||
import { subscribeTheme, themeKey } from "@/platform/themeWatch";
|
||||
import { hasMermaid, MERMAID_SELECTOR, renderMermaidIn } from "./mermaid";
|
||||
import { renderMath } from "@/editor/lsp/markdownMath";
|
||||
import type { renderMathSvg } from "./mathSvg";
|
||||
import { modeOf, pinMarkdownMode, useMarkdownModes } from "./modes";
|
||||
import { MarkdownLayoutActions } from "./MarkdownLayoutActions";
|
||||
import {
|
||||
@@ -151,7 +154,15 @@ export function MarkdownEditor({
|
||||
{mode === "split" && <SplitHandle aria-label={tx("Resize Markdown preview")} />}
|
||||
{mode !== "editor" && (
|
||||
<SplitPanel id="preview" style={{ overflow: "hidden" }} {...splitBounds}>
|
||||
<MarkdownPreview path={path} sync={mode === "split"} />
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className={styles.preview}>
|
||||
<Spinner label={tx("Loading")} />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<MarkdownPreview path={path} sync={mode === "split"} />
|
||||
</Suspense>
|
||||
</SplitPanel>
|
||||
)}
|
||||
</SplitGroup>
|
||||
@@ -172,6 +183,15 @@ const blocksOf = (root: HTMLElement) =>
|
||||
},
|
||||
}));
|
||||
|
||||
let svgRenderer: Promise<typeof renderMathSvg | null> | undefined;
|
||||
|
||||
function loadSvgRenderer() {
|
||||
return (svgRenderer ??= import("./mathSvg").then(
|
||||
(module) => module.renderMathSvg,
|
||||
() => null,
|
||||
));
|
||||
}
|
||||
|
||||
function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
|
||||
const text = useLiveMarkdown((s) => s[path]?.text);
|
||||
const fontZoom = useLiveMarkdown((s) => s[path]?.fontZoom ?? 0);
|
||||
@@ -187,6 +207,7 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
|
||||
const deferred = useDeferredValue(text ?? "");
|
||||
const [render] = useState(createMarkdownRenderer);
|
||||
const html = useMemo(() => render(deferred), [render, deferred]);
|
||||
const renderSvg = html.includes(' data-math="') ? use(loadSvgRenderer()) : null;
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
const blocks = useRef<ReturnType<typeof blocksOf>>([]);
|
||||
const theme = useSyncExternalStore(subscribeTheme, themeKey, () => "");
|
||||
@@ -213,10 +234,11 @@ function MarkdownPreview({ path, sync }: { path: string; sync: boolean }) {
|
||||
// Math before the preview index: typesetting changes the blocks' heights.
|
||||
useLayoutEffect(() => {
|
||||
if (!ref.current) return;
|
||||
renderSvg?.(ref.current);
|
||||
renderMath(ref.current);
|
||||
blocks.current = blocksOf(ref.current);
|
||||
invalidatePreviewIndex(ref.current);
|
||||
}, [html]);
|
||||
}, [html, renderSvg]);
|
||||
|
||||
// Mermaid diagrams: before paint, so cached ones don't flash their source.
|
||||
useLayoutEffect(() => {
|
||||
|
||||
@@ -97,7 +97,7 @@ function collectRuns(root: Node): TextRun[] {
|
||||
const el = node as Element;
|
||||
const tag = el.tagName.toUpperCase();
|
||||
if (SKIP_TAGS.has(tag)) return;
|
||||
if (el.classList.contains("katex-mathml")) return;
|
||||
if (tag === "MJX-ASSISTIVE-MML" || el.classList.contains("katex-mathml")) return;
|
||||
if (tag === "PRE" && el.parentElement?.getAttribute("data-mermaid-state") === "ok") return;
|
||||
const isBlock = BLOCK_TAGS.has(tag);
|
||||
if (isBlock) flush();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { renderMath } from "@/editor/lsp/markdownMath";
|
||||
import { renderMathSvg } from "./mathSvg";
|
||||
import { renderMarkdown } from "./render";
|
||||
|
||||
it("renders inline and display equations as independent SVGs with accessible MathML", () => {
|
||||
const root = document.createElement("div");
|
||||
root.innerHTML = renderMarkdown("**$`v_0`$** and $v_0$.\n\n$$\nv_0\n$$");
|
||||
renderMathSvg(root);
|
||||
|
||||
const inline = root.querySelectorAll('[data-math-svg="inline"] > svg');
|
||||
const display = root.querySelectorAll('[data-math-svg="display"] > svg');
|
||||
expect(inline).toHaveLength(2);
|
||||
expect(display).toHaveLength(1);
|
||||
expect(root.querySelector("strong > [data-math-svg] > svg")?.getAttribute("aria-label")).toBe("v_0");
|
||||
expect(root.querySelectorAll("mjx-assistive-mml math")).toHaveLength(3);
|
||||
expect(
|
||||
[...root.querySelectorAll("svg use")].every((use) => {
|
||||
const href = use.getAttribute("xlink:href");
|
||||
return href?.startsWith("#") && use.closest("svg")?.querySelector(`[id="${href.slice(1)}"]`);
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("leaves unsupported formulas for KaTeX without enabling TeX links", () => {
|
||||
const root = document.createElement("div");
|
||||
root.innerHTML = renderMarkdown(String.raw`$\href{https://example.com}{x}$`);
|
||||
renderMathSvg(root);
|
||||
expect(root.querySelector('[data-math="inline"]')?.textContent).toBe(String.raw`\href{https://example.com}{x}`);
|
||||
renderMath(root);
|
||||
expect(root.querySelector(".katex")).not.toBeNull();
|
||||
expect(root.querySelector("a")).toBeNull();
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { MathJaxTexFont } from "@mathjax/mathjax-tex-font/js/svg.js";
|
||||
import { AssistiveMmlHandler } from "@mathjax/src/js/a11y/assistive-mml.js";
|
||||
import { browserAdaptor } from "@mathjax/src/js/adaptors/browserAdaptor.js";
|
||||
import { RegisterHTMLHandler } from "@mathjax/src/js/handlers/html.js";
|
||||
import { TeX } from "@mathjax/src/js/input/tex.js";
|
||||
import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
|
||||
import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
|
||||
import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
|
||||
import "@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js";
|
||||
import { mathjax } from "@mathjax/src/js/mathjax.js";
|
||||
import { SVG } from "@mathjax/src/js/output/svg.js";
|
||||
import { SafeHandler } from "@mathjax/src/js/ui/safe/SafeHandler.js";
|
||||
|
||||
function createSvgRenderer() {
|
||||
const handler = RegisterHTMLHandler(browserAdaptor());
|
||||
SafeHandler<HTMLElement, Text, Document>(handler);
|
||||
AssistiveMmlHandler<HTMLElement, Text, Document>(handler);
|
||||
const tex = new TeX<HTMLElement, Text, Document>({
|
||||
packages: ["base", "ams", "newcommand", "textmacros"],
|
||||
formatError: (_jax: unknown, error: unknown) => {
|
||||
throw error;
|
||||
},
|
||||
});
|
||||
const math = mathjax.document("", {
|
||||
InputJax: tex,
|
||||
OutputJax: new SVG({ fontData: MathJaxTexFont, fontCache: "local" }),
|
||||
safeOptions: { allow: { URLs: "none", classes: "none", cssIDs: "none", styles: "none" } },
|
||||
});
|
||||
return (source: string, display: boolean) => {
|
||||
tex.reset();
|
||||
return math.convert(source, { display, em: 16, ex: 8, containerWidth: 1280 }) as HTMLElement;
|
||||
};
|
||||
}
|
||||
|
||||
let convert: ReturnType<typeof createSvgRenderer> | undefined;
|
||||
|
||||
export function renderMathSvg(root: HTMLElement) {
|
||||
for (const element of root.querySelectorAll<HTMLElement>("[data-math]")) {
|
||||
const mode = element.getAttribute("data-math");
|
||||
const source = element.textContent?.trim();
|
||||
if (!source || (mode !== "inline" && mode !== "display")) continue;
|
||||
try {
|
||||
convert ??= createSvgRenderer();
|
||||
const output = convert(source, mode === "display");
|
||||
const svg = output.querySelector("svg");
|
||||
if (!svg) continue;
|
||||
svg.setAttribute("aria-label", source);
|
||||
element.setAttribute("data-math-svg", mode);
|
||||
element.removeAttribute("data-math");
|
||||
element.replaceChildren(...output.childNodes);
|
||||
} catch {
|
||||
// Keep unsupported TeX for the existing KaTeX renderer.
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user