Improvements to prepare a MathJax+PNG option

- Remove MathMathJax.php, which uses exactly the same output as MathSource.php.
- Make wiki2jax able to handle texvc output as a preview before MathJax rendering.

Change-Id: I1199cb34d555d2a1e57da98857f41a22cfe81df4
This commit is contained in:
Frédéric Wang 2013-09-09 12:07:18 +02:00
parent 04cf73f1d3
commit bfc9ce8e7b
4 changed files with 13 additions and 60 deletions

View File

@ -145,7 +145,6 @@ $wgAutoloadClasses['MathHooks'] = $dir . 'Math.hooks.php';
$wgAutoloadClasses['MathRenderer'] = $dir . 'MathRenderer.php';
$wgAutoloadClasses['MathTexvc'] = $dir . 'MathTexvc.php';
$wgAutoloadClasses['MathSource'] = $dir . 'MathSource.php';
$wgAutoloadClasses['MathMathJax'] = $dir . 'MathMathJax.php';
$wgAutoloadClasses['MathLaTeXML'] = $dir . 'MathLaTeXML.php';
$wgExtensionMessagesFiles['Math'] = $dir . 'Math.i18n.php';

View File

@ -1,36 +0,0 @@
<?php
/**
* MediaWiki math extension
*
* (c) 2002-2012 Tomasz Wegrzanowski, Brion Vibber, Moritz Schubotz and other MediaWiki contributors
* GPLv2 license; info in main package.
*
* Renderer for MathJax
* @file
*/
/**
* Takes LaTeX fragments and outputs the source directly to the browser
*
* @author Tomasz Wegrzanowski
* @author Brion Vibber
* @author Moritz Schubotz
* @ingroup Parser
*/
class MathMathJax extends MathRenderer {
function render() {
# No need to render or parse anything more!
# New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
return Xml::element( 'span',
$this->getAttributes(
'span',
array(
'class' => 'tex',
'dir' => 'ltr'
)
),
'$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
);
}
}

View File

@ -82,12 +82,10 @@ abstract class MathRenderer {
if ( !in_array( $mode, $validModes ) )
$mode = $wgDefaultUserOptions['math'];
switch ( $mode ) {
case MW_MATH_MATHJAX:
case MW_MATH_SOURCE:
$renderer = new MathSource( $tex, $params );
break;
case MW_MATH_MATHJAX:
$renderer = new MathMathJax( $tex, $params );
break;
case MW_MATH_LATEXML:
$renderer = new MathLaTeXML( $tex, $params );
break;

View File

@ -8,10 +8,6 @@ MathJax.Extension.wiki2jax = {
config: {
element: null, // The ID of the element to be processed
// (defaults to full document)
preview: "TeX" // Set to "none" to prevent preview strings from being inserted
// or to an array that specifies an HTML snippet to use for
// the preview.
},
PreProcess: function (element) {
@ -24,7 +20,7 @@ MathJax.Extension.wiki2jax = {
this.configured = true;
}
var that = this;
$('span.tex, img.tex', element || document).each(function(i, span) {
$('span.tex, img.tex, strong.error', element || document).each(function(i, span) {
that.ConvertMath(span);
});
},
@ -46,8 +42,12 @@ MathJax.Extension.wiki2jax = {
if (node.nodeName == 'IMG') {
tex = node.alt;
} else {
tex = $(node).text().replace(/^\$/,"").replace(/\$$/,"");
tex = tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g," ");
if (node.nodeName == 'STRONG') {
tex = $(node).text().replace(/^[^:]*: (.*)$/,"$1");
} else {
tex = $(node).text().replace(/^\$/,"").replace(/\$$/,"");
}
tex = tex.replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/&amp;/g,"&").replace(/&nbsp;/g," ");
}
// We don't allow comments (%) in texvc and escape all literal % by default.
@ -63,22 +63,14 @@ MathJax.Extension.wiki2jax = {
if (node.nextSibling) {parent.insertBefore(script,node.nextSibling)}
else {parent.appendChild(script)}
if (this.config.preview !== "none") {this.createPreview(node)}
parent.removeChild(node);
},
createPreview: function (node) {
var preview;
if (this.config.preview === "TeX") {preview = [this.filterPreview($(node).text())]}
else if (this.config.preview instanceof Array) {preview = this.config.preview}
if (preview) {
preview = MathJax.HTML.Element("span",{className: MathJax.Hub.config.preRemoveClass},preview);
node.parentNode.insertBefore(preview,node);
}
var preview = MathJax.HTML.Element("span", {
className: MathJax.Hub.config.preRemoveClass
});
preview.appendChild(parent.removeChild(node));
parent.insertBefore(preview, script);
},
filterPreview: function (tex) {return tex}
};
MathJax.Hub.Register.PreProcessor(["PreProcess",MathJax.Extension.wiki2jax]);