Skip to content

Commit

Permalink
Merge branch 'release/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sommerregen committed Sep 9, 2015
2 parents 5ac257e + ca6df27 commit 1f84792
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 60 deletions.
14 changes: 10 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v1.3.1
## 09/09/2015

2. [](#improved)
* Added blueprints for Grav Admin plugin

# v1.3.0
## 08/08/2015

Expand All @@ -16,15 +22,15 @@
1. [](#new)
* Added usage example in [README.md](https://github.com/Sommerregen/grav-plugin-mathjax/blob/master/README.md)
2. [](#improved)
* Add assets (CSS and JS) dynamical to page now
* Changed default value `process: false` to `process: true` in [mathjax.yaml](https://github.com/Sommerregen/grav-plugin-mathjax/blob/master/mathjax.yaml)
* Add assets (CSS and JS) dynamical to page now
* Changed default value `process: false` to `process: true` in [mathjax.yaml](https://github.com/Sommerregen/grav-plugin-mathjax/blob/master/mathjax.yaml)

# v1.1.1
## 05/10/2015

1. [](#new)
* Support modular pages
* Added CSS stylesheet and `built_in_css` option
* Support modular pages
* Added CSS stylesheet and `built_in_css` option
2. [](#improved)
* PSR fixes

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [![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>
[![Release](https://img.shields.io/github/release/sommerregen/grav-plugin-mathjax.svg)][project] [![Issues](https://img.shields.io/github/issues/sommerregen/grav-plugin-mathjax.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.
Expand Down Expand Up @@ -29,7 +29,7 @@ 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 (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
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 mathjax`) manual install or update method by downloading [this plugin](https://github.com/sommerregen/grav-plugin-mathjax) and extracting all plugin files to

user/plugins/mathjax

Expand Down
48 changes: 24 additions & 24 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: MathJax
version: 1.3.0
version: 1.3.1
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 @@ -16,90 +16,90 @@ form:
fields:
global:
type: section
title: "Global plugin configurations"
title: PLUGINS.MATHJAX.GLOBAL_CONFIG
underline: 1

fields:
enabled:
type: toggle
label: "Plugin Status"
label: PLUGINS.MATHJAX.PLUGIN_STATUS
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool

built_in_css:
type: toggle
label: "Use built in CSS"
label: PLUGINS.MATHJAX.BUILTIN_CSS
highlight: 1
default: 1
options:
1: "Yes"
0: "No"
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

built_in_js:
type: toggle
label: "Use built in JS"
label: PLUGINS.MATHJAX.BUILTIN_JS
highlight: 1
default: 1
options:
1: "Yes"
0: "No"
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

weight:
type: text
size: x-small
label: "Order execution"
label: PLUGINS.MATHJAX.WEIGHT
default: -5
help: "To process the page content right after *SmartyPants* use negative values."
help: PLUGINS.MATHJAX.WEIGHT_HELP
validate:
type: int
min: -100
max: 100

default:
type: section
title: "Default values for MathJax configuration"
title: PLUGINS.MATHJAX.DEFAULT_CONFIG
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."
label: PLUGINS.MATHJAX.CDN.ENABLED
help: PLUGINS.MATHJAX.CDN.ENABLED_HELP
default: 1
options:
1: "Yes"
0: "No"
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool

CDN.url:
type: text
label: "MathJax CDN URL"
label: PLUGINS.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"
help: PLUGINS.MATHJAX.CDN.URL_HELP

specific:
type: section
title: "Global and page specific configurations"
title: PLUGINS.MATHJAX.SPECIFIC_CONFIG
underline: 1

fields:
process:
type: toggle
label: "Activate <code>MathJax</code> filter per page"
label: PLUGINS.MATHJAX.PROCESS
default: 0
options:
1: "Yes"
0: "No"
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
18 changes: 9 additions & 9 deletions classes/MathJax.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MathJax
/**
* @var MathJax
*/
use GravTrait;
use GravTrait;

/** ---------------------------
* Private/protected properties
Expand All @@ -36,14 +36,14 @@ class MathJax
*
* @var string
*/
protected $id;
protected $id;

/**
* A key-valued array used for hashing math formulas of a page
*
* @var array
*/
protected $hashes;
protected $hashes;

/** -------------
* Public methods
Expand Down Expand Up @@ -87,10 +87,10 @@ public function mathjaxShortcode(Event $event)
*
* @return string The processed content
*/
public function process($content, $id = null)
public function process($content, $id = null)
{
// Set unique identifier based on page content
$this->id($id ?: time().md5($content));
// Set unique identifier based on page content
$this->id($id ?: time().md5($content));

// Reset class hashes before processing
// $this->reset();
Expand All @@ -100,7 +100,7 @@ public function process($content, $id = null)
$regex['latex-block'] = '~(?<!\\\\)(\$\$)(.+?)\1~msx';
$regex['latex-inline'] = '~(?<!\\\\)(\$)(.+?)\1~msx';

// Wrap any text between \[ and \] in display math tags.
// Wrap any text between \[ and \] in display math tags.
$regex['block'] = '~
^\\\\ # line starts with a single backslash (double escaping)
\[ # followed by a square bracket
Expand All @@ -126,7 +126,7 @@ public function process($content, $id = null)
}, $content);
}

return $content;
return $content;
}

/**
Expand Down Expand Up @@ -205,7 +205,7 @@ protected function reset()
*/
protected function hash($text, $type = '')
{
static $counter = 0;
static $counter = 0;

// Swap back any tag hash found in $text so we do not have to `unhash`
// multiple times at the end.
Expand Down
40 changes: 40 additions & 0 deletions languages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# German
de:
PLUGINS:
MATHJAX:
GLOBAL_CONFIG: "Globale Einstellungen"
DEFAULT_CONFIG: "Standardeinstellungen für External Links"
SPECIFIC_CONFIG: "Globale und seitenspezifische Einstellungen"
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."
URL: "MathJax CDN URL"
URL_HELP: "Gebe hier die MathJax CDN URL ein oder lasse es frei um MathJax direkt von wwww.mathjax.org zu laden."

PROCESS: "Aktiviere <code>MathJax</code> auf Seite"

# English
en:
PLUGINS:
MATHJAX:
GLOBAL_CONFIG: "Global plugin configurations"
DEFAULT_CONFIG: "Default values for External Links configuration"
SPECIFIC_CONFIG: "Global and page specific configurations"
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"
37 changes: 16 additions & 21 deletions mathjax.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* MathJax v1.3.0
* MathJax v1.3.1
*
* This plugin allows you to include math formulas in your web pages,
* either using TeX and LaTeX notation, and/or as MathML.
Expand All @@ -9,7 +9,7 @@
* http://benjamin-regler.de/license/
*
* @package MathJax
* @version 1.3.0
* @version 1.3.1
* @link <https://github.com/sommerregen/grav-plugin-mathjax>
* @author Benjamin Regler <[email protected]>
* @copyright 2015, Benjamin Regler
Expand Down Expand Up @@ -45,7 +45,7 @@ class MathJaxPlugin extends Plugin
*
* @var object
*/
protected $backend;
protected $mathjax;

/** -------------
* Public methods
Expand All @@ -61,31 +61,30 @@ class MathJaxPlugin extends Plugin
public static function getSubscribedEvents()
{
return [
'onPageInitialized' => ['onPageInitialized', 0],
'onTwigInitialized' => ['onTwigInitialized', 0],
'onBuildPagesInitialized' => ['onBuildPagesInitialized', 0],
'onShortcodesInitialized' => ['onShortcodesInitialized', 0]
];
}

/**
* Initialize configuration when building pages.
* Initialize configuration
*/
public function onBuildPagesInitialized() {
public function onPageInitialized() {
if ($this->isAdmin()) {
$this->active = false;
return;
}

if ($this->config->get('plugins.mathjax.enabled')) {
$this->init();

$weight = $this->config->get('plugins.mathjax.weight', -5);
// Process contents order according to weight option
// (default: -5): to process page content right after SmartyPants

$this->enable([
'onPageContentRaw' => ['onPageContentRaw', 0],
'onPageContentProcessed' => ['onPageContentProcessed', $weight]
'onPageContentProcessed' => ['onPageContentProcessed', $weight],
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]);
}
}
Expand All @@ -108,7 +107,7 @@ public function onPageContentRaw(Event $event)

// Save modified page content with tokens as placeholders
$page->setRawContent(
$this->backend->process($raw, $page->id())
$this->init()->process($raw, $page->id())
);
}
}
Expand All @@ -125,11 +124,11 @@ public function onPageContentProcessed(Event $event)
$page = $event['page'];

// Normalize page content, if modified
if ($this->backend->modified()) {
if ($this->mathjax->modified()) {
// Get modified content, replace all tokens with their
// respective formula and write content back to page
$content = $page->getRawContent();
$page->setRawContent($this->backend->normalize($content));
$page->setRawContent($this->mathjax->normalize($content));

// Set X-UA-Compatible meta tag for Internet Explorer
$metadata = $page->metadata();
Expand Down Expand Up @@ -217,7 +216,7 @@ public function externalLinksFunction($content, $params = [])
*/
public function onShortcodesInitialized(Event $event)
{
$backend = $this->init();
$mathjax = $this->init();
// Register {{% mathjax %}} shortcode
$event['shortcodes']->register(
new BlockShortcode('mathjax', function($event) {
Expand All @@ -231,7 +230,7 @@ public function onShortcodesInitialized(Event $event)
$event['page']->header()->mathjax->process = true;
}

return $this->backend->mathjaxShortcode($event);
return $this->mathjax->mathjaxShortcode($event);
})
);
}
Expand All @@ -248,16 +247,12 @@ public function onShortcodesInitialized(Event $event)
*/
protected function init()
{
if (!$this->backend) {
if (!$this->mathjax) {
// Initialize MathJax class
require_once(__DIR__ . '/classes/MathJax.php');
$this->backend = new MathJax();

$this->enable([
'onTwigSiteVariables' => ['onTwigSiteVariables', 0]
]);
$this->mathjax = new MathJax();
}

return $this->backend;
return $this->mathjax;
}
}

0 comments on commit 1f84792

Please sign in to comment.