From ef5de943c670284b3ccd50ae3570e476883f758f Mon Sep 17 00:00:00 2001 From: "Mark A. Hershberger" Date: Sun, 15 Nov 2020 19:05:04 -0500 Subject: [PATCH] Update hook name and add documentation --- README.md | 13 +++++++++++++ SimpleMathJaxHooks.php | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c0d86ed..6d1fdc70 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,16 @@ If you want to disable MathJax context menu, set `$wgSmjEnableMenu`. wfLoadExtension( 'SimpleMathJax' ); $wgSmjEnableMenu = false; ``` + +# Hooks +The hook `SimpleMathJaxAttributes` is available to add attributes to the span around the math. This hook provides you with the opportunity to ensure that your own code does not interfere with MathJax's rendering of math. + +For instance, if Lingo's JS functions are called before MathJax is invoked, then it is possible that Lingo will change the text so that MathJax could no longer render the math. + +Lingo understands that [it should not touch anything inside an element with the class `noglossary`](https://www.mediawiki.org/wiki/Extension:Lingo#Excluding_text_from_markup) so the following code can be used to keep Lingo from ruining math: +```PHP +$wfHook['SimpleMathJaxAttributes'] + = function ( array &attributes, string $tex ) { + $attributes['class'] = 'noglossary'; + } +``` diff --git a/SimpleMathJaxHooks.php b/SimpleMathJaxHooks.php index 0dbda5cd..71cc9488 100644 --- a/SimpleMathJaxHooks.php +++ b/SimpleMathJaxHooks.php @@ -34,7 +34,7 @@ class SimpleMathJaxHooks { $parser->getOutput()->addModules( 'ext.SimpleMathJax' ); $parser->getOutput()->addModules( 'ext.SimpleMathJax.mobile' ); // For MobileFrontend $attributes = [ "style" => "opacity:.5" ]; - Hooks::run( "SimpleMathJaxAttr", [ &$attributes, $tex ] ); + Hooks::run( "SimpleMathJaxAttributes", [ &$attributes, $tex ] ); $element = Html::Element( "span", $attributes, "[math]{$tex}[/math]" ); return [$element, 'markerType'=>'nowiki']; }