Merge pull request #27 from hexmode/span-hook

Make span around [math] block marker configurable
这个提交包含在:
Jmnote 2020-11-16 13:18:10 +09:00 提交者 GitHub
当前提交 387be32103
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 17 次插入1 次删除

查看文件

@ -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';
}
```

查看文件

@ -33,6 +33,9 @@ class SimpleMathJaxHooks {
private static function renderTex($tex, $parser) {
$parser->getOutput()->addModules( 'ext.SimpleMathJax' );
$parser->getOutput()->addModules( 'ext.SimpleMathJax.mobile' ); // For MobileFrontend
return ["<span style='opacity:.5'>[math]${tex}[/math]</span>", 'markerType'=>'nowiki'];
$attributes = [ "style" => "opacity:.5" ];
Hooks::run( "SimpleMathJaxAttributes", [ &$attributes, $tex ] );
$element = Html::Element( "span", $attributes, "[math]{$tex}[/math]" );
return [$element, 'markerType'=>'nowiki'];
}
}