Skip to content

Commit

Permalink
Merge branch 'release/1.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sommerregen committed Aug 8, 2015
2 parents 0391dcf + dda35b8 commit 5ac257e
Show file tree
Hide file tree
Showing 10 changed files with 980 additions and 128 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assets/logo.svg
*.xcf
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# v1.3.0
## 08/08/2015

1. [](#new)
* Added admin configurations **(requires Grav 0.9.34+)**
* Added `{{% mathjax type='block|inline' %}}` shortcode
2. [](#improved)
* Switched to `onBuildPagesInitialized` event **(requires Grav 0.9.29+)**
* Updated `README.md`
3. [](#bugfix)
* Fixed [#2](https://github.com/Sommerregen/grav-plugin-mathjax/issues/2) (JS script not added to page)

# v1.2.0
## 05/14/2015

Expand Down
708 changes: 706 additions & 2 deletions LICENSE

Large diffs are not rendered by default.

42 changes: 27 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# [Grav MathJax Plugin][project]
# [![Grav MathJax Plugin](assets/logo.png)][project]

[![Release](https://img.shields.io/github/release/sommerregen/grav-plugin-mahtjax.svg)][project] [![Issues](https://img.shields.io/github/issues/sommerregen/grav-plugin-mahtjax.svg)][issues] [![Dual license](https://img.shields.io/badge/dual%20license-MIT%2FGPL-blue.svg)](LICENSE "License") <span style="float:right;">[![Flattr](https://api.flattr.com/button/flattr-badge-large.png)][flattr] [![PayPal](https://www.paypal.com/en_US/i/btn/btn_donate_SM.gif)][paypal]</span>

> This plugin allows you to include math formulas in your web pages, either using TeX and LaTeX notation, and/or as MathML.
* [About](#about)
* [Installation and Updates](#installation-and-updates)
* [Usage](#usage)
* [Example](#example)
* [CSS Stylesheet Override](#css-stylesheet-override)
* [JavaScript Override](#javascript-override)
* [Contributing](#contributing)
* [Licencse](#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.
Expand All @@ -18,9 +29,9 @@ default math delimiters are `$$...$$` and `\\[...\\]` for displayed mathematics,

## Installation and Updates

Installing or updating the `MathJax` plugin can be done in one of two ways. Using the GPM (Grav Package Manager) installation method or manual install or update method by downloading [this plugin](https://github.com/sommerregen/grav-plugin-mathjax) and extracting all plugin files to
Installing or updating the `MathJax` plugin can be done in one of two ways. Using the GPM (Grav Package Manager) installation method or (i.e. `bin/gpm install mathjay`) manual install or update method by downloading [this plugin](https://github.com/sommerregen/grav-plugin-mathjax) and extracting all plugin files to

/your/site/grav/user/plugins/mathjax
user/plugins/mathjax

For more informations, please check the [Installation and update guide](docs/INSTALL.md).

Expand All @@ -34,7 +45,7 @@ To produce the formula shown in the above screenshot, create a new Markdown docu

The code to copy and paste is as follows:

```
```markdown
---
title: Einstein Field Equations
---
Expand Down Expand Up @@ -96,8 +107,7 @@ If you need to change any value, then the best process is to copy the [mathjax.y
If you want to alter the settings for one or only few pages, you can do so by adding page specific configurations into your page headers, e.g.

```yaml
mathjax:
process: false
mathjax: false
```

to deactivate `MathJax` filter just for this page.
Expand All @@ -116,9 +126,7 @@ Something you might want to do is to override the look and feel of the math form

Copy the stylesheet [assets/css/mathjax.css](assets/css/mathjax.css) into the `css` folder of your custom theme, and add it to the list of CSS files.

```
/your/site/grav/user/themes/custom-theme/css/mathjax.css
```
user/themes/custom-theme/css/mathjax.css

After that set the `built_in_css` option of the `MathJax` plugin to `false`. That's it.

Expand All @@ -128,9 +136,7 @@ Something you might want to do is to override the behavior of how MathJax will p

Copy the javascript [assets/js/mathjax.js](assets/js/mathjax.js) into the `js` folder of your custom theme, and add it to the list of JS files

```
/your/site/grav/user/themes/custom-theme/js/mathjax.js
```
user/themes/custom-theme/js/mathjax.js

via `{% do assets.addJs('theme://js/mathjax.js') %}` i.e. in your **base.html.twig** file located in **antimatter/templates/partials/**.

Expand All @@ -156,26 +162,32 @@ You can contribute at any time! Before opening any issue, please search for exis

After that please note:

* If you find a bug or would like to make a feature request or suggest an improvement, [please open a new issue][issues]. If you have any interesting ideas for additions to the syntax please do suggest them as well!
* If you find a bug, would like to make a feature request or suggest an improvement, [please open a new issue][issues]. If you have any interesting ideas for additions to the syntax please do suggest them as well!
* Feature requests are more likely to get attention if you include a clearly described use case.
* If you wish to submit a pull request, please make again sure that your request match the [guidelines for contributing](docs/CONTRIBUTING.md) and that you keep track of adding unit tests for any new or changed functionality.

### Support and donations

If you like my project, feel free to support me, since donations will keep this project alive. You can [![Flattr me](https://api.flattr.com/button/flattr-badge-large.png)][flattr] or send me some bitcoins to **1HQdy5aBzNKNvqspiLvcmzigCq7doGfLM4** whenever you want.
If you like my project, feel free to support me via [![Flattr](https://api.flattr.com/button/flattr-badge-large.png)][flattr] or by sending me some bitcoins to [**1HQdy5aBzNKNvqspiLvcmzigCq7doGfLM4**][bitcoin].

Thanks!

## License

Copyright (c) 2015 [Benjamin Regler][github]. See also the list of [contributors] who participated in this project.

[Licensed](LICENSE) for use under the terms of the [MIT license][mit-license].
[Dual-licensed](LICENSE) for use under the terms of the [MIT][mit-license] or [GPLv3][gpl-license] licenses.

![GNU license - Some rights reserved][gnu]

[github]: https://github.com/sommerregen/ "GitHub account from Benjamin Regler"
[gpl-license]: http://opensource.org/licenses/GPL-3.0 "GPLv3 license"
[mit-license]: http://www.opensource.org/licenses/mit-license.php "MIT license"

[flattr]: https://flattr.com/submit/auto?user_id=Sommerregen&url=https://github.com/sommerregen/grav-plugin-mathjax "Flatter my GitHub project"
[paypal]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SYFNP82USG3RN "Donate for my GitHub project using PayPal"
[bitcoin]: bitcoin:1HQdy5aBzNKNvqspiLvcmzigCq7doGfLM4?label=GitHub%20project "Donate for my GitHub project using BitCoin"
[gnu]: https://upload.wikimedia.org/wikipedia/commons/thumb/3/33/License_icon-gpl-88x31.svg/88px-License_icon-gpl-88x31.svg.png "GNU license - Some rights reserved"

[project]: https://github.com/sommerregen/grav-plugin-mathjax
[issues]: https://github.com/sommerregen/grav-plugin-mathjax/issues "GitHub Issues for Grav MathJax Plugin"
Expand Down
Binary file added assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
144 changes: 86 additions & 58 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MathJax
version: 1.2.0
version: 1.3.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 @@ -9,69 +9,97 @@ homepage: https://github.com/sommerregen/grav-plugin-mathjax
docs: https://github.com/sommerregen/grav-plugin-mathjax/blob/master/README.md
keywords: [mathjax, filter, javascript, plugin]
bugs: https://github.com/sommerregen/grav-plugin-mathjax/issues
license: MIT
license: MIT/GPL

form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin Status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
global:
type: section
title: "Global plugin configurations"
underline: 1

built_in_css:
type: toggle
label: Use built in CSS
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
fields:
enabled:
type: toggle
label: "Plugin Status"
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool

weight:
type: text
label: Set the weight (order of execution)
default: -5
help: "To process the page content right after *SmartyPants* use negative values."
validate:
type: int
min: -100
max: 100
built_in_css:
type: toggle
label: "Use built in CSS"
highlight: 1
default: 1
options:
1: "Yes"
0: "No"
validate:
type: bool

CDN.enabled:
type: toggle
label: Use MathJax Content Delivery Network (CDN)
help: "Check this box to load MathJax source from MathJax servers (recommended) or from the link you can provide below."
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
built_in_js:
type: toggle
label: "Use built in JS"
highlight: 1
default: 1
options:
1: "Yes"
0: "No"
validate:
type: bool

CDN.url:
type: text
label: MathJax CDN URL
default: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
placeholder: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
help: "Enter the Mathjax CDN url here or leave it unchanged to use the one provided by wwww.mathjax.org"
weight:
type: text
size: x-small
label: "Order execution"
default: -5
help: "To process the page content right after *SmartyPants* use negative values."
validate:
type: int
min: -100
max: 100

process:
type: toggle
label: Activate `MathJax` filter
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
default:
type: section
title: "Default values for MathJax configuration"
underline: 1

fields:
CDN.enabled:
type: toggle
label: "Use MathJax Content Delivery Network (CDN)"
help: "Check this box to load MathJax source from MathJax servers (recommended) or from the link you can provide below."
default: 1
options:
1: "Yes"
0: "No"
validate:
type: bool

CDN.url:
type: text
label: "MathJax CDN URL"
default: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
placeholder: https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML
help: "Enter the Mathjax CDN url here or leave it unchanged to use the one provided by wwww.mathjax.org"

specific:
type: section
title: "Global and page specific configurations"
underline: 1

fields:
process:
type: toggle
label: "Activate <code>MathJax</code> filter per page"
default: 0
options:
1: "Yes"
0: "No"
validate:
type: bool
44 changes: 37 additions & 7 deletions classes/MathJax.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
/**
* MathJax
*
* Helper class to include math formulas in your web pages, either using
* TeX and LaTeX notation, and/or as MathML.
* This file is part of Grav MathJax plugin.
*
* Licensed under MIT, see LICENSE.
* Dual licensed under the MIT or GPL Version 3 licenses, see LICENSE.
* http://benjamin-regler.de/license/
*/

namespace Grav\Plugin;

use Grav\Common\Grav;
use Grav\Common\GravTrait;
use RocketTheme\Toolbox\Event\Event;

/**
* MathJax
Expand Down Expand Up @@ -50,20 +50,50 @@ class MathJax
* --------------
*/

/**
* MathJax shortcode
*
* @param Event $event An event object.
* @return string The parsed shortcode.
*/
public function mathjaxShortcode(Event $event)
{
/* @var \Grav\Common\Data\Data $options */
$options = $event['options'];

$body = trim($event['body']);
$type = $options->get('type', 'block');

// Setup tags to parse
$tags = [
'block' => ['\[', '\]'],
'inline' => ['\(', '\)']
];

if (isset($tags[$type])) {
// Wrap text in display math tags
list($pre, $post) = $tags[$type];
$body = $pre.$body.$post;

return $this->process($body);
}
}

/**
* Process contents i.e. replace all math formulas by a (unique) hash
*
* @param string $content The content to be processed
* @param string $id An id to be incorporated into all replacements.
*
* @return string The processed content
*/
public function process($content)
public function process($content, $id = null)
{
// Set unique identifier based on page content
$this->id(time().md5($content));
$this->id($id ?: time().md5($content));

// Reset class hashes before processing
$this->reset();
// $this->reset();

$regex = [];
// Wrap any text between $ ... $ or $$ ... $$ in display math tags.
Expand Down
Loading

0 comments on commit 5ac257e

Please sign in to comment.