File tree Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Expand file tree Collapse file tree 3 files changed +19
-10
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @openstax/highlighter" ,
3- "version" : " 1.16.2 " ,
3+ "version" : " 1.16.3 " ,
44 "main" : " dist/index.js" ,
55 "license" : " MIT" ,
66 "files" : [
Original file line number Diff line number Diff line change @@ -277,11 +277,21 @@ function refineRangeBoundaries(range: Range) {
277277 return mathjax ;
278278 }
279279
280+ // MathJax 4: <mjx-assistive-mml> is inside <mjx-container>
281+ const assistiveMml = dom ( node ) . farthest ( 'mjx-assistive-mml' ) ;
282+ if ( assistiveMml ) {
283+ const container = dom ( assistiveMml ) . farthest ( 'mjx-container' ) ;
284+ if ( container ) {
285+ return container ;
286+ }
287+ }
288+
289+ // Legacy: <script type="math/mml"> after the MathJax container
280290 const mml = dom ( node ) . farthest ( 'script[type="math/mml"]' ) ;
281- if ( mml && mml . previousSibling . matches ( '.MathJax,mjx-container ' ) ) {
291+ if ( mml && mml . previousSibling && mml . previousSibling . matches ( '.MathJax' ) ) {
282292 return mml . previousSibling ;
283293 }
284- if ( mml && mml . previousSibling . matches ( '.MathJax_Display' ) ) {
294+ if ( mml && mml . previousSibling && mml . previousSibling . matches ( '.MathJax_Display' ) ) {
285295 return mml . previousSibling . querySelector ( '.MathJax' ) ;
286296 }
287297
Original file line number Diff line number Diff line change @@ -7,18 +7,17 @@ export const rangeContentsString = (range: Range): string => {
77 const removeAll = ( nodes : NodeListOf < Element > ) => nodes . forEach ( ( element : Element ) => element . remove ( ) ) ;
88
99 container . appendChild ( fragment ) ;
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.
10+
11+ // handle mml math nodes from mathjax 4
1312 const mjxContainers = container . querySelectorAll ( 'mjx-container' ) ;
1413 mjxContainers . forEach ( ( mjxContainer : Element ) => {
15- const scriptTag = mjxContainer . querySelector ( 'script[type="math/ mml"] ' ) ;
16- if ( scriptTag && mjxContainer . parentElement ) {
17- mjxContainer . parentElement . insertBefore ( scriptTag , mjxContainer ) ;
14+ const mathTag = mjxContainer . querySelector ( 'mjx-assistive- mml math ' ) ;
15+ if ( mathTag && mjxContainer . parentElement ) {
16+ mjxContainer . parentElement . insertBefore ( mathTag , mjxContainer ) ;
1817 }
1918 } ) ;
2019
21- removeAll ( container . querySelectorAll ( '.MathJax' ) ) ;
20+ removeAll ( container . querySelectorAll ( '.MathJax,mjx-container ' ) ) ;
2221 removeAll ( container . querySelectorAll ( '.MathJax_Display' ) ) ;
2322 removeAll ( container . querySelectorAll ( '.MathJax_Preview' ) ) ;
2423 removeAll ( container . querySelectorAll ( '.MJX_Assistive_MathML' ) ) ;
You can’t perform that action at this time.
0 commit comments