From bfc9ce8e7be2970f5939aa66218d477f65541b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Mon, 9 Sep 2013 12:07:18 +0200 Subject: [PATCH] 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 --- Math.php | 1 - MathMathJax.php | 36 -------------------------- MathRenderer.php | 4 +-- modules/MathJax/extensions/wiki2jax.js | 32 +++++++++-------------- 4 files changed, 13 insertions(+), 60 deletions(-) delete mode 100644 MathMathJax.php diff --git a/Math.php b/Math.php index 9314cb7..d382a30 100644 --- a/Math.php +++ b/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'; diff --git a/MathMathJax.php b/MathMathJax.php deleted file mode 100644 index 2b21318..0000000 --- a/MathMathJax.php +++ /dev/null @@ -1,36 +0,0 @@ -getAttributes( - 'span', - array( - 'class' => 'tex', - 'dir' => 'ltr' - ) - ), - '$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $' - ); - } -} diff --git a/MathRenderer.php b/MathRenderer.php index 16a6cc0..1df4203 100644 --- a/MathRenderer.php +++ b/MathRenderer.php @@ -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; diff --git a/modules/MathJax/extensions/wiki2jax.js b/modules/MathJax/extensions/wiki2jax.js index 77f8baf..07734c9 100644 --- a/modules/MathJax/extensions/wiki2jax.js +++ b/modules/MathJax/extensions/wiki2jax.js @@ -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]);