| 1 |
( function () { |
| 2 |
'use strict'; |
| 3 |
const extensionAssetsPath = mw.config.get( 'wgExtensionAssetsPath' ); |
| 4 |
window.MathJax = { |
| 5 |
loader: { |
| 6 |
|
| 7 |
load: [ '[mml]/mml3' ], |
| 8 |
|
| 9 |
paths: { |
| 10 |
mathjax: extensionAssetsPath + '/Math/modules/mathjax/es5' |
| 11 |
} |
| 12 |
}, |
| 13 |
|
| 14 |
|
| 15 |
remapChars( v1, v2, base, map, font ) { |
| 16 |
const c1 = v1.chars; |
| 17 |
const c2 = v2.chars; |
| 18 |
for ( let i = 0; i < 26; i++ ) { |
| 19 |
const data1 = c1[ map[ i ] || base + i ] || []; |
| 20 |
const data2 = c2[ 0x41 + i ]; |
| 21 |
if ( data1.length === 0 ) { |
| 22 |
c1[ base + i ] = data1; |
| 23 |
} |
| 24 |
[ 0, 1, 2 ].forEach( ( j ) => data1[ j ] = data2[ j ] ); |
| 25 |
data1[ 3 ] = Object.assign( {}, data2[ 3 ], { f: font, c: String.fromCharCode( 0x41 + i ) } ); |
| 26 |
} |
| 27 |
}, |
| 28 |
|
| 29 |
startup: { |
| 30 |
ready() { |
| 31 |
window.MathJax.startup.defaultReady(); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
const variant = window.MathJax.startup.document.outputJax.font.variant; |
| 39 |
const map = { 1: 0x212C, 4: 0x2130, 5: 0x2131, 7: 0x210B, 8: 0x2110, 11: 0x2112, 12: 0x2133, 17: 0x211B }; |
| 40 |
window.MathJax.config.remapChars( variant.normal, variant[ '-tex-calligraphic' ], 0x1D49C, map, 'C' ); |
| 41 |
window.MathJax.config.remapChars( variant.normal, variant[ '-tex-bold-calligraphic' ], 0x1D4D0, {}, 'CB' ); |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
const { Mml3 } = window.MathJax._.input.mathml.mml3.mml3; |
| 47 |
const mml3 = new Mml3( window.MathJax.startup.document ); |
| 48 |
const adaptor = window.MathJax.startup.document.adaptor; |
| 49 |
const processor = new XSLTProcessor(); |
| 50 |
const parsed = adaptor.parse( Mml3.XSLT, 'text/xml' ); |
| 51 |
processor.importStylesheet( parsed ); |
| 52 |
mml3.transform = ( node ) => { |
| 53 |
const div = adaptor.node( 'div', {}, [ adaptor.clone( node ) ] ); |
| 54 |
const dom = adaptor.parse( adaptor.serializeXML( div ), 'text/xml' ); |
| 55 |
const mml = processor.transformToDocument( dom ); |
| 56 |
return ( mml ? adaptor.tags( mml, 'math' )[ 0 ] : node ); |
| 57 |
}; |
| 58 |
|
| 59 |
const MML = window.MathJax.startup.document.inputJax[ 1 ]; |
| 60 |
MML.mmlFilters.items.pop(); |
| 61 |
MML.mmlFilters.add( mml3.mmlFilter.bind( mml3 ) ); |
| 62 |
} |
| 63 |
} |
| 64 |
}; |
| 65 |
}() ); |