Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,26 @@ jobs:
env:
GH_TOKEN: ${{ github.token }}
TAG: v${{ steps.version.outputs.current }}
VERSION: ${{ steps.version.outputs.current }}
run: |
if gh release view "$TAG" >/dev/null 2>&1; then
echo "Release $TAG already exists, skipping."
exit 0
fi
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes

# GitHub's own "Source code" archives are generated straight from
# the tag and don't include submodule content, so
# resources/MathJax comes out empty in them. Attach a second
# archive with the MathJax submodule checked out, so local-mode
# users ($wgSmjCdnEnabled = false) have a one-download option
# that doesn't require git.
git submodule update --init --recursive

asset_root="SimpleMathJax-$VERSION"
asset="$asset_root-with-mathjax.tar.gz"
git archive --format=tar --prefix="$asset_root/" HEAD -o base.tar
( cd resources/MathJax && git archive --format=tar --prefix="$asset_root/resources/MathJax/" HEAD -o ../mathjax.tar )
tar -Af base.tar mathjax.tar
gzip -c base.tar > "$asset"

gh release create "$TAG" "$asset" --target "$GITHUB_SHA" --title "$TAG" --generate-notes
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ checks: test phpcs ## Everything CI runs before merging (needs `composer install
test: ## Run the pure-PHP test suites
php tests/QuotesTest.php
php tests/RevisionOverridesTest.php
php tests/IgnoreHtmlClassTest.php

phpcs: vendor/autoload.php ## parallel-lint + minus-x + phpcs against the MediaWiki coding standard
composer test
Expand Down
19 changes: 17 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,23 @@ $wgSmjCdnEnabled = false;
When working from the Git repository, initialize or update the bundled
MathJax submodule with `make local-mathjax` — see
[Updating MathJax](development.md#updating-mathjax) for version
selection. Normal extension packages already include the bundled MathJax
resources and do not require Git commands.
selection. The `resources/MathJax` directory is a Git submodule, and
GitHub's automatically generated release source archives (the "Source
code (zip/tar.gz)" links on a release page) do not include submodule
contents — only an empty `resources/MathJax` directory. If you set
`$wgSmjCdnEnabled = false`, use one of these instead:

- Download the `SimpleMathJax-<version>-with-mathjax.tar.gz` asset
attached to the corresponding [release](https://github.com/jmnote/SimpleMathJax/releases),
which already has the MathJax submodule's contents included.
- Or clone the repository (`git clone --recurse-submodules`, or run
`git submodule update --init` in an existing checkout) so
`resources/MathJax/tex-chtml.js` and the other bundled files are
actually present.

Otherwise local rendering will fail. This doesn't apply when using the
CDN (the default), which fetches MathJax from jsDelivr instead of the
bundled files.

### `$wgSmjScale`

Expand Down
Binary file modified docs/screenshots/screenshot-custom01-diff.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/screenshot-custom01-rightclick.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/screenshots/screenshot-custom01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SimpleMathJax",
"version": "1.0.0",
"version": "1.0.1",
"author": "jmnote",
"url": "https://www.mediawiki.org/wiki/Extension:SimpleMathJax",
"description": "render TeX between <code><nowiki><math></nowiki></code> and <code><nowiki></math></nowiki></code>",
Expand Down
6 changes: 6 additions & 0 deletions hack/demo/demos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
- '$$e^{i\pi} + 1 = 0$$'
- '<math style="color: red">e^{i\pi} + 1 = 0</math>'
- '<math class="mathjax_ignore">E=mc^2</math>'
# The default ignore pattern contains "comment": this exact class is
# intentionally ignored, while "commentary" must still be typeset.
- '<math class="comment">E=mc^2</math>'
- '<math class="commentary">E=mc^2</math>'
# Ignoring MathJax must not discard an independently allowed style.
- '<math class="mathjax_ignore" style="color: red">E=mc^2</math>'
- "<nowiki><math>E=mc^2</math></nowiki>"
- '<math display="block">e^{i\pi} + 1 = 0</math>'
- name: custom02
Expand Down
22 changes: 18 additions & 4 deletions includes/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ public static function onParserFirstCallInit( Parser $parser ) {
}

// $pattern is an admin-supplied regex fragment with no delimiter of its
// own, so avoid one that could occur inside it.
private static function matchesIgnoreHtmlClass( string $pattern, string $class ): bool {
// own, so avoid one that could occur inside it. The pattern is anchored
// to whole space-delimited class tokens, mirroring the
// "(?:^| )(?:pattern)(?: |$)" boundary MathJax itself applies to its
// own ignoreHtmlClass option (see resources/MathJax/core.js), so e.g.
// "comment" matches class="comment" but not class="commentary".
// Public (like applyRevisionOverrides below) so it's unit-testable
// without a MediaWiki bootstrap.
public static function matchesIgnoreHtmlClass( string $pattern, string $class ): bool {
$delimiter = strpos( $pattern, '~' ) === false ? '~' : "\x01";
$result = preg_match( $delimiter . $pattern . $delimiter, $class );
$anchored = '(?:^| )(?:' . $pattern . ')(?: |$)';
$result = preg_match( $delimiter . $anchored . $delimiter, $class );
return $result === 1;
}

Expand Down Expand Up @@ -146,7 +153,14 @@ private static function renderTex(
$isIgnored = self::$ignoreHtmlClass !== ''
&& self::matchesIgnoreHtmlClass( self::$ignoreHtmlClass, $attributes["class"] );
if ( $isIgnored ) {
unset( $attributes["style"] );
// Strip only the placeholder opacity this method defaults to
// while MathJax hasn't run yet; an editor-supplied "style" (via
// $wgSmjAllowedAttributes) already replaced that default above
// and must be kept, since an ignored element is never typeset
// and so never gets its opacity reset to 1 either.
if ( !isset( $validatedAttribs["style"] ) ) {
unset( $attributes["style"] );
}
$element = Html::Element( "span", $attributes, $tex );
} else {
if ( !isset( $attributes["smj-debug"] ) && !isset( $args["smj-debug"] ) ) {
Expand Down
59 changes: 59 additions & 0 deletions tests/IgnoreHtmlClassTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
use MediaWiki\Extension\SimpleMathJax\Hooks;

require __DIR__ . '/../includes/Hooks.php';

$failures = 0;

function assert_same( $name, $expected, $actual ) {
global $failures;
if ( $expected === $actual ) {
echo "ok $name\n";
return;
}
$failures++;
echo "FAIL $name\n";
echo ' expected: ' . var_export( $expected, true ) . "\n";
echo ' actual: ' . var_export( $actual, true ) . "\n";
}

$pattern = 'mathjax_ignore|comment|diff-(context|addedline|deletedline)';

assert_same(
'matchesIgnoreHtmlClass matches an exact single class',
true,
Hooks::matchesIgnoreHtmlClass( $pattern, 'comment' )
);
assert_same(
'matchesIgnoreHtmlClass matches one token among several classes',
true,
Hooks::matchesIgnoreHtmlClass( $pattern, 'foo comment bar' )
);
assert_same(
'matchesIgnoreHtmlClass does not match a class that merely contains the pattern as a substring',
false,
Hooks::matchesIgnoreHtmlClass( $pattern, 'commentary' )
);
assert_same(
'matchesIgnoreHtmlClass does not match a class with the pattern as a prefix of a longer token',
false,
Hooks::matchesIgnoreHtmlClass( $pattern, 'diff-contextual' )
);
assert_same(
'matchesIgnoreHtmlClass does not match a class with the pattern as a suffix of a longer token',
false,
Hooks::matchesIgnoreHtmlClass( $pattern, 'notmathjax_ignoreable' )
);
assert_same(
'matchesIgnoreHtmlClass does not match an unrelated class list',
false,
Hooks::matchesIgnoreHtmlClass( $pattern, 'foo bar' )
);
assert_same(
'matchesIgnoreHtmlClass does not match an empty class',
false,
Hooks::matchesIgnoreHtmlClass( $pattern, '' )
);

echo $failures === 0 ? "\nAll tests passed.\n" : "\n$failures test(s) FAILED.\n";
exit( $failures === 0 ? 0 : 1 );
Loading