diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b8f14530..302351a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/Makefile b/Makefile index 20b14d3d..2821285d 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/docs/configuration.md b/docs/configuration.md index 3cfa48d6..ec06761d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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--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` diff --git a/docs/screenshots/screenshot-custom01-diff.png b/docs/screenshots/screenshot-custom01-diff.png index 13f90f99..1bfd34bb 100644 Binary files a/docs/screenshots/screenshot-custom01-diff.png and b/docs/screenshots/screenshot-custom01-diff.png differ diff --git a/docs/screenshots/screenshot-custom01-rightclick.png b/docs/screenshots/screenshot-custom01-rightclick.png index cb55bc82..5e0da8b0 100644 Binary files a/docs/screenshots/screenshot-custom01-rightclick.png and b/docs/screenshots/screenshot-custom01-rightclick.png differ diff --git a/docs/screenshots/screenshot-custom01.png b/docs/screenshots/screenshot-custom01.png index b92913e6..e1a27a40 100644 Binary files a/docs/screenshots/screenshot-custom01.png and b/docs/screenshots/screenshot-custom01.png differ diff --git a/extension.json b/extension.json index 5f6a5378..4d4025d8 100644 --- a/extension.json +++ b/extension.json @@ -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 and ", diff --git a/hack/demo/demos.yaml b/hack/demo/demos.yaml index 93575529..3492d3a9 100644 --- a/hack/demo/demos.yaml +++ b/hack/demo/demos.yaml @@ -38,6 +38,12 @@ - '$$e^{i\pi} + 1 = 0$$' - 'e^{i\pi} + 1 = 0' - 'E=mc^2' + # The default ignore pattern contains "comment": this exact class is + # intentionally ignored, while "commentary" must still be typeset. + - 'E=mc^2' + - 'E=mc^2' + # Ignoring MathJax must not discard an independently allowed style. + - 'E=mc^2' - "E=mc^2" - 'e^{i\pi} + 1 = 0' - name: custom02 diff --git a/includes/Hooks.php b/includes/Hooks.php index 6b810f74..91c0687e 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -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; } @@ -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"] ) ) { diff --git a/tests/IgnoreHtmlClassTest.php b/tests/IgnoreHtmlClassTest.php new file mode 100644 index 00000000..d707c443 --- /dev/null +++ b/tests/IgnoreHtmlClassTest.php @@ -0,0 +1,59 @@ +