Merge "Separating MediaWiki specific files from MathJax module"

This commit is contained in:
jenkins-bot 2014-08-29 19:33:19 +00:00 committed by Gerrit Code Review
commit b6b70ae3fa
4 changed files with 41 additions and 32 deletions

View File

@ -314,7 +314,13 @@ $wgResourceModules += array(
'ext.math.mathjax.extensions.TeX' => array( 'ext.math.mathjax.extensions.TeX' => array(
'localBasePath' => __DIR__ . '/modules/MathJax/unpacked/extensions', 'localBasePath' => __DIR__ . '/modules/MathJax/unpacked/extensions',
'remoteExtPath' => 'Math/modules/MathJax/unpacked/extensions', 'remoteExtPath' => 'Math/modules/MathJax/unpacked/extensions',
'scripts' => array( 'wiki2jax.js', 'TeX/noUndefined.js', 'TeX/AMSmath.js', 'TeX/AMSsymbols.js', 'TeX/boldsymbol.js', 'TeX/color.js', 'TeX/cancel.js', 'TeX/mathchoice.js', 'TeX/texvc.js' ), 'scripts' => array( 'TeX/noUndefined.js', 'TeX/AMSmath.js', 'TeX/AMSsymbols.js', 'TeX/boldsymbol.js', 'TeX/color.js', 'TeX/cancel.js', 'TeX/mathchoice.js' ),
'dependencies' => array( 'ext.math.mathjax.mathjax' )
),
'ext.math.mathjax.extensions.mediawiki' => array(
'localBasePath' => __DIR__ . '/modules/mediawiki-extensions',
'remoteExtPath' => 'Math/modules/mediawiki-extensions',
'scripts' => array( 'wiki2jax.js', 'texvc.js' ),
'dependencies' => array( 'ext.math.mathjax.mathjax' ) 'dependencies' => array( 'ext.math.mathjax.mathjax' )
), ),
'ext.math.mathjax.extensions.mml2jax' => array( 'ext.math.mathjax.extensions.mml2jax' => array(
@ -324,7 +330,7 @@ $wgResourceModules += array(
'dependencies' => 'ext.math.mathjax.mathjax' 'dependencies' => 'ext.math.mathjax.mathjax'
), ),
'ext.math.mathjax.extensions' => array( 'ext.math.mathjax.extensions' => array(
'dependencies' => array( 'ext.math.mathjax.extensions.ui', 'ext.math.mathjax.extensions.TeX', 'ext.math.mathjax.extensions.mml2jax' ) 'dependencies' => array( 'ext.math.mathjax.extensions.ui', 'ext.math.mathjax.extensions.TeX', 'ext.math.mathjax.extensions.mediawiki', 'ext.math.mathjax.extensions.mml2jax' )
), ),
// MathJax module for representing MathML elements // MathJax module for representing MathML elements

View File

@ -104,7 +104,8 @@
// Configure MathJax // Configure MathJax
MathJax.Hub.Config( mathJax.config ); MathJax.Hub.Config( mathJax.config );
MathJax.OutputJax.fontDir = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/modules/MathJax/fonts'; MathJax.OutputJax.fontDir = mw.config.get( 'wgExtensionAssetsPath' ) + '/Math/modules/MathJax/fonts';
MathJax.Ajax.config.path = {};
MathJax.Ajax.config.path.MediaWiki = mw.config.get( 'wgServer' ) + mw.config.get( 'wgExtensionAssetsPath' ) + 'Math/modules/mediawiki-extensions';
// Redefine MathJax.Hub.Startup.Jax // Redefine MathJax.Hub.Startup.Jax
MathJax.Hub.Startup.Jax = function () { MathJax.Hub.Startup.Jax = function () {
var config, jax, i, k, name, queue, callback; var config, jax, i, k, name, queue, callback;

View File

@ -1,9 +1,9 @@
/** /**
* From https://en.wikipedia.org/wiki/User:Nageh/mathJax/config/TeX-AMS-texvc_HTML.js * From https://en.wikipedia.org/wiki/User:Nageh/mathJax/config/TeX-AMS-texvc_HTML.js
*/ */
/* global MathJax:true */
MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () { MathJax.Hub.Register.StartupHook('TeX Jax Ready',function () {
var VERSION = "1.0";
var MML = MathJax.ElementJax.mml; var MML = MathJax.ElementJax.mml;
@ -131,6 +131,6 @@ MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
}); });
}); });
MathJax.Hub.Startup.signal.Post("TeX texvc Ready"); MathJax.Hub.Startup.signal.Post('TeX texvc Ready');
MathJax.Ajax.loadComplete("[MathJax]/extensions/TeX/texvc.js"); MathJax.Ajax.loadComplete(MathJax.Ajax.config.path.MediaWiki + '/texvc.js');

View File

@ -1,9 +1,10 @@
/** /**
* From https://en.wikipedia.org/wiki/User:Nageh/mathJax/config/TeX-AMS-texvc_HTML.js * From https://en.wikipedia.org/wiki/User:Nageh/mathJax/config/TeX-AMS-texvc_HTML.js
*/ */
/* global MathJax:true, $:true */
MathJax.Extension.wiki2jax = { MathJax.Extension.wiki2jax = {
version: "1.0", version: '1.0',
config: { config: {
element: null // The ID of the element to be processed element: null // The ID of the element to be processed
@ -12,8 +13,8 @@ MathJax.Extension.wiki2jax = {
PreProcess: function (element) { PreProcess: function (element) {
if (!this.configured) { if (!this.configured) {
this.config = MathJax.Hub.CombineConfig("wiki2jax", this.config); this.config = MathJax.Hub.CombineConfig('wiki2jax', this.config);
if (this.config.Augment) {MathJax.Hub.Insert(this,this.config.Augment)} if (this.config.Augment) {MathJax.Hub.Insert(this,this.config.Augment);}
this.previewClass = MathJax.Hub.config.preRemoveClass; this.previewClass = MathJax.Hub.config.preRemoveClass;
this.setupPrefilter(); this.setupPrefilter();
@ -27,47 +28,48 @@ MathJax.Extension.wiki2jax = {
}, },
setupPrefilter: function() { // used to fix a number of common wiki math hacks setupPrefilter: function() { // used to fix a number of common wiki math hacks
MathJax.Hub.Register.StartupHook("TeX Jax Ready", function() { MathJax.Hub.Register.StartupHook('TeX Jax Ready', function() {
MathJax.InputJax.TeX.prefilterHooks.Add( function(data) { MathJax.InputJax.TeX.prefilterHooks.Add( function(data) {
data.math = data.math.replace(/^\s*\\scriptstyle(\W)/,"\\textstyle$1").replace(/^\s*\\scriptscriptstyle(\W)/,"\\scriptstyle$1"); data.math = data.math.replace(/^\s*\\scriptstyle(\W)/,'\\textstyle$1').replace(/^\s*\\scriptscriptstyle(\W)/,'\\scriptstyle$1');
if (data.script.type.match(/(;|\s|\n)mode\s*=\s*display-nobreak(;|\s|\n|$)/) != null) if (data.script.type.match(/(;|\s|\n)mode\s*=\s*display-nobreak(;|\s|\n|$)/) !== null) {
data.math = "\\displaystyle " + data.math; data.math = '\\displaystyle ' + data.math;
}
}); });
}); });
}, },
ConvertMath: function (node) { ConvertMath: function (node) {
var parent = node.parentNode, var parent = node.parentNode,
mode = "", //Bug 61051 (heuristic unwanted by the community) mode = '', //Bug 61051 (heuristic unwanted by the community)
tex; tex;
if (node.nodeName == 'IMG') { if (node.nodeName === 'IMG') {
tex = node.alt; tex = node.alt;
} else { } else {
if (node.nodeName == 'STRONG') { if (node.nodeName === 'STRONG') {
tex = $(node).text().replace(/^[^:]*: (.*)$/,"$1"); tex = $(node).text().replace(/^[^:]*: (.*)$/,'$1');
} else { } else {
tex = $(node).text().replace(/^\$/,"").replace(/\$$/,""); tex = $(node).text().replace(/^\$/,'').replace(/\$$/,'');
} }
tex = tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g," "); tex = tex.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&').replace(/&nbsp;/g,' ');
} }
if ( $( node ).hasClass( "mwe-math-fallback-png-display") || $( node ).hasClass( "mwe-math-fallback-source-display") ){ if ( $( node ).hasClass( 'mwe-math-fallback-png-display') || $( node ).hasClass( 'mwe-math-fallback-source-display') ){
mode = "; mode=display"; mode = '; mode=display';
} }
// We don't allow comments (%) in texvc and escape all literal % by default. // We don't allow comments (%) in texvc and escape all literal % by default.
tex = tex.replace(/([^\\])%/g, "$1\\%" ); tex = tex.replace(/([^\\])%/g, '$1\\%' );
tex = tex.replace(/\\iiint([^!]*)!\\!\\!\\!\\!.*\\subset\\!\\supset/g,"\\iiint$1mkern-2.5em\\subset\\!\\supset").replace(/\\iint([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\subset\\!\\supset/g,"\\iint$1mkern-1.65em$2\\subset\\!\\!\\supset").replace(/\\int\\!\\!\\!(\\!)+\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!.*\\bigcirc(\\,)*/g,"\\iiint$3mkern-2.5em\\subset\\!\\supset").replace(/\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\bigcirc(\\,)*/g,"\\iint$2mkern-1.65em$3\\subset\\!\\!\\supset"); tex = tex.replace(/\\iiint([^!]*)!\\!\\!\\!\\!.*\\subset\\!\\supset/g,'\\iiint$1mkern-2.5em\\subset\\!\\supset').replace(/\\iint([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\subset\\!\\supset/g,'\\iint$1mkern-1.65em$2\\subset\\!\\!\\supset').replace(/\\int\\!\\!\\!(\\!)+\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!.*\\bigcirc(\\,)*/g,'\\iiint$3mkern-2.5em\\subset\\!\\supset').replace(/\\int\\!\\!\\!(\\!)+\\int([^!]*)!\\!\\!\\!\\!\\!\\!\\!\\!(.*)\\bigcirc(\\,)*/g,'\\iint$2mkern-1.65em$3\\subset\\!\\!\\supset');
if (mode === "" && parent.firstChild === node) mode = "; mode=display-nobreak"; if (mode === '' && parent.firstChild === node) {mode = '; mode=display-nobreak';}
var script = document.createElement("script"); var script = document.createElement('script');
script.type = "math/tex" + mode; script.type = 'math/tex' + mode;
MathJax.HTML.setScript(script, tex); MathJax.HTML.setScript(script, tex);
if (node.nextSibling) {parent.insertBefore(script,node.nextSibling)} if (node.nextSibling) {parent.insertBefore(script,node.nextSibling);}
else {parent.appendChild(script)} else {parent.appendChild(script);}
var preview = MathJax.HTML.Element("span", { var preview = MathJax.HTML.Element('span', {
className: MathJax.Hub.config.preRemoveClass className: MathJax.Hub.config.preRemoveClass
}); });
preview.appendChild(parent.removeChild(node)); preview.appendChild(parent.removeChild(node));
@ -76,5 +78,5 @@ MathJax.Extension.wiki2jax = {
}; };
MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.wiki2jax]); MathJax.Hub.Register.PreProcessor(['PreProcess',MathJax.Extension.wiki2jax]);
MathJax.Ajax.loadComplete("[MathJax]/extensions/wiki2jax.js"); MathJax.Ajax.loadComplete(MathJax.Ajax.config.path.MediaWiki + '/wiki2jax.js');