Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sommerregen committed Nov 18, 2015
2 parents f4ccf52 + cd7523e commit f979607
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 50 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
assets/logo.svg
*.xcf
.idea
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# v1.4.0
## 11/18/2015

1. [](#new)
* Added [#3](https://github.com/Sommerregen/grav-plugin-mathjax/pull/3) ("MathJax Process" toggle to page options tab)
2. [](#improved)
* Added Twig filter documentation to `README.md`
* Improved code
3. [](#bugfix)
* Fixed `mathjax` Twig filter

# v1.3.2
## 09/09/2015

Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
* [Example](#example)
* [CSS Stylesheet Override](#css-stylesheet-override)
* [JavaScript Override](#javascript-override)
* [Twig Filter](#twig-filter)
* [Contributing](#contributing)
* [Licencse](#license)
* [License](#license)

## About

`MathJax` is a plugin for [**Grav**](http://getgrav.org) and integrates the [MathJax library](http://www.mathjax.org/), a modern JavaScript-based LaTeX rendering solution for the Internet, into the site.

By default, MathJax source is loaded automatically from the Internet using the
MathJax Content Delivery Network (CDN). This is a light-weight, "out-of-the-box" LaTeX rendering solution and you can still use a custom configuration if you need.
By default, MathJax source is loaded automatically from the Internet using the MathJax Content Delivery Network (CDN). This is a light-weight, "out-of-the-box" LaTeX rendering solution and you can still use a custom configuration if you need.

Alternatively, you can host the MathJax library (approximately _150MB_) on your server located in your `user/data/mathjax` folder.

MathJax then renders mathematics inside the default delimiters. The
default math delimiters are `$$...$$` and `\\[...\\]` for displayed mathematics, and `$...$` and `\\(...\\)` for inline mathematics. An example can be seen below:
MathJax then renders mathematics inside the default delimiters. The default math delimiters are `$$...$$` and `\\[...\\]` for displayed mathematics, and `$...$` and `\\(...\\)` for inline mathematics. An example can be seen below:

![Screenshot MathJax Plugin](assets/screenshot.png "MathJax Preview")

Expand Down Expand Up @@ -118,7 +117,7 @@ The `MathJax` plugin allows you to either use the MathJax CDN (recommended) or t

1. Download the latest MathJax release from https://github.com/mathjax/mathjax.
2. Extract the contents to your Grav `user/data/mathjax` folder and make sure that the file `mathjax.js` is present in the above folder (and not in any sub-folders).
3. Copy the [mathjax.yaml](mathjax.yaml) file into your `users/config/plugins/` folder (create it if it doesn't exist), and finally set `CDN: enabled: false`.
3. Copy the [mathjax.yaml](mathjax.yaml) file into your `users/config/plugins/` folder (create it if it doesn't exist), and finally set `CDN.enabled: false`.

### CSS Stylesheet Override

Expand Down Expand Up @@ -156,6 +155,14 @@ window.MathJax = {
```

### Twig Filter

`MathJax` provides a Twig filter to process MathJax inside contents. To do that, place the following line of code in the theme file you wish to add the `MathJax` plugin for:

```
{{ page.content|mathjax }}
```

## Contributing

You can contribute at any time! Before opening any issue, please search for existing issues and review the [guidelines for contributing](docs/CONTRIBUTING.md).
Expand Down
10 changes: 6 additions & 4 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MathJax
version: 1.3.2
version: 1.4.0
description: "This plugin allows you to include math formulas in your web pages, either using TeX and LaTeX notation, and/or as MathML."
icon: subscript
author:
Expand All @@ -13,7 +13,9 @@ license: MIT/GPL

form:
validation: strict

fields:
# Global plugin configurations
global:
type: section
title: PLUGINS.MATHJAX.GLOBAL_CONFIG
Expand All @@ -34,7 +36,6 @@ form:
built_in_css:
type: toggle
label: PLUGINS.MATHJAX.BUILTIN_CSS
highlight: 1
default: 1
options:
1: PLUGIN_ADMIN.YES
Expand All @@ -45,7 +46,6 @@ form:
built_in_js:
type: toggle
label: PLUGINS.MATHJAX.BUILTIN_JS
highlight: 1
default: 1
options:
1: PLUGIN_ADMIN.YES
Expand All @@ -64,6 +64,7 @@ form:
min: -100
max: 100

# Default options for MathJax configuration
default:
type: section
title: PLUGINS.MATHJAX.DEFAULT_CONFIG
Expand All @@ -88,6 +89,7 @@ form:
placeholder: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
help: PLUGINS.MATHJAX.CDN.URL_HELP

# Global and page specific configurations
specific:
type: section
title: PLUGINS.MATHJAX.SPECIFIC_CONFIG
Expand All @@ -97,7 +99,7 @@ form:
process:
type: toggle
label: PLUGINS.MATHJAX.PROCESS
default: 0
default: 1
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
Expand Down
29 changes: 29 additions & 0 deletions blueprints/mathjax.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
form:
validation: loose

fields:
tabs:
type: tabs
active: 1

fields:
options:
type: tab

fields:
mathjax:
type: section
title: PLUGINS.MATHJAX.MATHJAX
underline: true

fields:
header.mathjax.process:
type: toggle
label: PLUGINS.MATHJAX.PROCESS
highlight: 1
'@config-default': plugins.mathjax.process
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
19 changes: 10 additions & 9 deletions classes/MathJax.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,25 @@ public function mathjaxShortcode(Event $event)
if (isset($tags[$type])) {
// Wrap text in display math tags
list($pre, $post) = $tags[$type];
$body = $pre.$body.$post;
$body = $pre . $body . $post;

return $this->process($body);
return $this->render($body, $event['options'], $event['page']);
}
}

/**
* Process contents i.e. replace all math formulas by a (unique) hash
* Process contents i.e. apply filer to the content.
*
* @param string $content The content to be processed
* @param string $id An id to be incorporated into all replacements.
* @param string $content The content to render.
* @param array $options Options to be passed to the renderer.
* @param null|Page $page Null or an instance of \Grav\Common\Page.
*
* @return string The processed content
* @return string The rendered contents.
*/
public function process($content, $id = null)
public function render($content, $options = [], $page = null)
{
// Set unique identifier based on page content
$this->id($id ?: time().md5($content));
$this->id($page->id() ?: time() . md5($content));

// Reset class hashes before processing
// $this->reset();
Expand Down Expand Up @@ -234,7 +235,7 @@ protected function hash($text, $type = '')
protected function unhash($text)
{
$pattern = '~mathjax::(.+)::([0-9a-z]+)::([0-9]+)::M~i';
$text = preg_replace_callback($pattern, function($atches) {
$text = preg_replace_callback($pattern, function($matches) {
return $this->hashes[$matches[0]];
}, $text);

Expand Down
9 changes: 9 additions & 0 deletions languages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ de:
GLOBAL_CONFIG: "Globale Einstellungen"
DEFAULT_CONFIG: "Standardeinstellungen für External Links"
SPECIFIC_CONFIG: "Globale und seitenspezifische Einstellungen"

MATHJAX: "MathJax"
PLUGIN_STATUS: "Plugin Status"

BUILTIN_CSS: "Verwende mitgeliefertes CSS"
BUILTIN_JS: "Verwende mitgeliefertes JS"

WEIGHT: "Ausführungsreihenfolge"
WEIGHT_HELP: "Setze negative Werte um MathJax direkt nach *SmartyPants* ausführen zu lassen."

CDN:
ENABLED: "Verwende das MathJax Content Delivery Network (CDN)"
ENABLED_HELP: "Aktivierung dieser Option bewrikt das Laden von MathJax über den MathJax Server (empfohlen) or von dem unten stehenden Link."
Expand All @@ -26,15 +30,20 @@ en:
GLOBAL_CONFIG: "Global plugin configurations"
DEFAULT_CONFIG: "Default values for External Links configuration"
SPECIFIC_CONFIG: "Global and page specific configurations"

MATHJAX: "MathJax"
PLUGIN_STATUS: "Plugin status"

BUILTIN_CSS: "Use built in CSS"
BUILTIN_JS: "Use built in JS"

WEIGHT: "Order of execution"
WEIGHT_HELP: "To process the page contents right after *SmartyPants* use negative values."

CDN:
ENABLED: "Use MathJax Content Delivery Network (CDN)"
ENABLED_HELP: "Check this box to load MathJax source from MathJax servers (recommended) or from the link you can provide below."
URL: "MathJax CDN URL"
URL_HELP: "Enter the Mathjax CDN URL here or leave it unchanged to use the one provided by wwww.mathjax.org"

PROCESS: "Activate <code>MathJax</code> filter on the page"
Loading

0 comments on commit f979607

Please sign in to comment.