Hook ParserFirstCallInit
这个提交包含在:
父节点
03b6eadef3
当前提交
c4bd866a63
|
@ -1,24 +1,16 @@
|
|||
<?php
|
||||
class SimpleMathJax {
|
||||
public static function onRegistration() {
|
||||
Hooks::register( 'ParserFirstCallInit', __CLASS__ . '::setup' );
|
||||
}
|
||||
|
||||
public static function setup( Parser $parser ) {
|
||||
global $wgOut, $wgSmjUseCdn, $wgSmjScale, $wgSmjUseChem, $wgSmjShowMathMenu, $wgSmjExtraInlineMath, $wgSmjDisplayMath;
|
||||
#trace( $wgSmjUseCdn );
|
||||
#exit;
|
||||
$wgOut->addModules( 'ext.SimpleMathJax' );
|
||||
// MobileFrontend requires explicit cloned modules targeting mobile
|
||||
$wgOut->addModules( 'ext.SimpleMathJax.mobile' );
|
||||
public static function onParserFirstCallInit( &$parser ) {
|
||||
global $wgOut, $wgSmjUseCdn, $wgSmjUseChem, $wgSmjEnableMenu, $wgSmjDisplayMath, $wgSmjExtraInlineMath, $wgSmjScale;
|
||||
|
||||
$wgOut->addJsConfigVars( 'wgSmjUseCdn', $wgSmjUseCdn );
|
||||
$wgOut->addJsConfigVars( 'wgSmjScale', $wgSmjScale );
|
||||
$wgOut->addJsConfigVars( 'wgSmjUseChem', $wgSmjUseChem );
|
||||
$wgOut->addJsConfigVars( 'wgSmjShowMathMenu', $wgSmjShowMathMenu );
|
||||
$wgOut->addJsConfigVars( 'wgSmjExtraInlineMath', $wgSmjExtraInlineMath );
|
||||
$wgOut->addJsConfigVars( 'wgSmjEnableMenu', $wgSmjEnableMenu );
|
||||
$wgOut->addJsConfigVars( 'wgSmjDisplayMath', $wgSmjDisplayMath );
|
||||
|
||||
$wgOut->addJsConfigVars( 'wgSmjExtraInlineMath', $wgSmjExtraInlineMath );
|
||||
$wgOut->addJsConfigVars( 'wgSmjScale', $wgSmjScale );
|
||||
|
||||
$parser->setHook( 'math', __CLASS__ . '::renderMath' );
|
||||
if( $wgSmjUseChem ) $parser->setHook( 'chem', __CLASS__ . '::renderChem' );
|
||||
}
|
||||
|
@ -35,6 +27,8 @@ class SimpleMathJax {
|
|||
}
|
||||
|
||||
private static function renderTex($tex, $parser) {
|
||||
$parser->getOutput()->addModules( 'ext.SimpleMathJax' );
|
||||
$parser->getOutput()->addModules( 'ext.SimpleMathJax.mobile' ); // For MobileFrontend
|
||||
return ["<span style='opacity:.5'>[math]${tex}[/math]</span>", 'markerType'=>'nowiki'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
"AutoloadClasses": {
|
||||
"SimpleMathJax": "SimpleMathJax_body.php"
|
||||
},
|
||||
"callback": "SimpleMathJax::onRegistration",
|
||||
"config": {
|
||||
"SmjUseCdn": {"value":true, "description":"true to load mathjax from CDN"},
|
||||
"SmjUseChem": {"value":true, "description":"true to enabled chem tag"},
|
||||
|
@ -18,6 +17,9 @@
|
|||
"SmjExtraInlineMath": {"value":[], "description":"MathJax.tex.inlineMath"},
|
||||
"SmjScale": {"value":1, "description":"MathJax.chtml.scale"}
|
||||
},
|
||||
"Hooks": {
|
||||
"ParserFirstCallInit": "SimpleMathJax::onParserFirstCallInit"
|
||||
},
|
||||
"ResourceModules": {
|
||||
"ext.SimpleMathJax": {
|
||||
"scripts": ["resources/ext.SimpleMathJax.js"]
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
console.log( 'SmjExtraInlineMath', mw.config.get('SmjExtraInlineMath') );
|
||||
window.MathJax = {
|
||||
tex: {
|
||||
inlineMath: mw.config.get('wgSmjExtraInlineMath').concat([['[math]','[/math]']]),
|
||||
|
@ -19,7 +20,6 @@ window.MathJax = {
|
|||
}
|
||||
};
|
||||
(function () {
|
||||
console.log( window.MathJax );
|
||||
var script = document.createElement('script');
|
||||
script.src = mw.config.get('wgSmjUseCdn') ? 'https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js'
|
||||
: mw.config.get('wgExtensionAssetsPath') + '/SimpleMathJax/resources/MathJax/es5/tex-chtml.js';
|
||||
|
|
正在加载...
在新工单中引用