Merge "Improvements to prepare a MathJax+PNG option"
This commit is contained in:
commit
ffa865cc31
1
Math.php
1
Math.php
|
@ -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';
|
||||
|
||||
|
|
|
@ -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() ) . ' $'
|
||||
);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/ /g," ");
|
||||
if (node.nodeName == 'STRONG') {
|
||||
tex = $(node).text().replace(/^[^:]*: (.*)$/,"$1");
|
||||
} else {
|
||||
tex = $(node).text().replace(/^\$/,"").replace(/\$$/,"");
|
||||
}
|
||||
tex = tex.replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&").replace(/ /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]);
|
||||
|
|
Loading…
Reference in New Issue