Skip to content

Commit 9ff9e3f

Browse files
authored
move embedded script tags to match mathjax 2 location (#87)
* use updated math/mml script tag location for mathjax 4 * version bump
1 parent 9f50d24 commit 9ff9e3f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@openstax/highlighter",
3-
"version": "1.16.1",
3+
"version": "1.16.2",
44
"main": "dist/index.js",
55
"license": "MIT",
66
"files": [

src/rangeContents.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ export const rangeContentsString = (range: Range): string => {
77
const removeAll = (nodes: NodeListOf<Element>) => nodes.forEach((element: Element) => element.remove());
88

99
container.appendChild(fragment);
10-
// MathJax 2
10+
// REX creates math/mml script tags inside mjx-container elements for MathJax 4.
11+
// Timing issues prevent placing them outside like MathJax 2 used to do,
12+
// so we need to move them to match the MathJax 2 location.
13+
const mjxContainers = container.querySelectorAll('mjx-container');
14+
mjxContainers.forEach((mjxContainer: Element) => {
15+
const scriptTag = mjxContainer.querySelector('script[type="math/mml"]');
16+
if (scriptTag && mjxContainer.parentElement) {
17+
mjxContainer.parentElement.insertBefore(scriptTag, mjxContainer);
18+
}
19+
});
20+
1121
removeAll(container.querySelectorAll('.MathJax'));
1222
removeAll(container.querySelectorAll('.MathJax_Display'));
1323
removeAll(container.querySelectorAll('.MathJax_Preview'));
1424
removeAll(container.querySelectorAll('.MJX_Assistive_MathML'));
15-
// MathJax 4
16-
removeAll(container.querySelectorAll('mjx-container'));
17-
1825
removeAllHighlights(container);
1926

2027
container.querySelectorAll('script[type="math/mml"]').forEach((element: Element) => {

0 commit comments

Comments
 (0)