Commit 528fa9cb authored by Administrator's avatar Administrator 💬

Prepare support for per-page override.

parent e9ae9816
...@@ -6,12 +6,20 @@ use Grav\Common\Plugin; ...@@ -6,12 +6,20 @@ use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event; use RocketTheme\Toolbox\Event\Event;
/** /**
* Customize the HTML tags to use with the usual inline emphasis and strong blocks.
*
* - *
* - **
* - _
* - __
*
*
* __some text__ => <u>some text</u> * __some text__ => <u>some text</u>
* *
* Use with caution, as underlining makes text harder to read. * Use with caution, as underlining makes text harder to read.
* If you don't think so, please be thankful for your great sight and ortholexia. * If you don't think so, please be thankful for your great sight and ortholexia.
* *
* Not sure how this will fare with multibyte strings. Probably badly. * Not sure how this will fare with multibyte strings. Possibly badly.
* Try mb_strlen ? * Try mb_strlen ?
* *
* Class MarkdownUnderlinePlugin * Class MarkdownUnderlinePlugin
...@@ -41,13 +49,14 @@ class MarkdownUnderlinePlugin extends Plugin ...@@ -41,13 +49,14 @@ class MarkdownUnderlinePlugin extends Plugin
*/ */
public function onPluginsInitialized() public function onPluginsInitialized()
{ {
// Don't proceed if we are in the admin plugin // Don't proceed if we are in the admin plugin.
// This check is legacy, and is perhaps not useful? // Since we don't sanitize the configuration options, this is paramount.
// This way, if the plugin breaks pages somehow, admin will still be available.
if ($this->isAdmin()) { if ($this->isAdmin()) {
return; return;
} }
// Enable the main event we are interested in // *Subscribe* to the main event we are interested in.
$this->enable([ $this->enable([
'onMarkdownInitialized' => ['onMarkdownInitialized', 0], 'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
]); ]);
...@@ -56,8 +65,21 @@ class MarkdownUnderlinePlugin extends Plugin ...@@ -56,8 +65,21 @@ class MarkdownUnderlinePlugin extends Plugin
public function onMarkdownInitialized(Event $event) public function onMarkdownInitialized(Event $event)
{ {
$markdown = $event['markdown']; $markdown = $event['markdown'];
$config = $this->config;
$mu_config = $this->config->get('plugins.markdown-underline'); $mu_config = $config->get('plugins.markdown-underline');
// This feature depends on the page being provided in onMarkdownInitialized event.
// There may be a PR for this in the future. Not sure about the implications.
if (isset($event['page'])) {
$config = $this->mergeConfig($event['page']);
// Merging works but changes paths
$mu_config = array(
'*' => $config->get('*'),
'**' => $config->get('**'),
'_' => $config->get('_'),
'__' => $config->get('__'),
);
}
// Add our parser right before the Emphasis one. // Add our parser right before the Emphasis one.
// See vendor/erusev/parsedown/Parsedown.php#L977 // See vendor/erusev/parsedown/Parsedown.php#L977
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment