-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
101 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
@@ -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 | ||
|
@@ -45,7 +45,7 @@ class MathJaxPlugin extends Plugin | |
* | ||
* @var object | ||
*/ | ||
protected $backend; | ||
protected $mathjax; | ||
|
||
/** ------------- | ||
* Public methods | ||
|
@@ -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] | ||
]); | ||
} | ||
} | ||
|
@@ -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()) | ||
); | ||
} | ||
} | ||
|
@@ -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(); | ||
|
@@ -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) { | ||
|
@@ -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); | ||
}) | ||
); | ||
} | ||
|
@@ -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; | ||
} | ||
} |