Commit d397bf89 authored by Administrator's avatar Administrator 💬

Make the markdown-underline plugin awesome. 🎶

(now I need to give it its own repository)
(and to translate it into french)
parent fdd64909
enabled: true
'*': b
'**': strong
_: em
__: u
name: Markdown Underline name: Markdown Underline
version: 0.1.0 version: 1.0.0
description: Use `__double underscore__` to create `<u>` tags. description: |
icon: plug Override the HTML tags generated by inline `*`, `**`, `_` and `__`.
The plugin defaults `__` to `u` for example to yield underlined text.
icon: underline
author: author:
name: Shady Oryx name: Antoine Goutenoir
email: antoine@goutenoir.com email: antoine@goutenoir.com
homepage: https://github.com/Goutte/grav-plugin-markdown-underline homepage: https://github.com/Goutte/grav-plugin-markdown-underline
demo: https://courses.m3p2.ljbac.com demo: https://courses.m3p2.ljbac.com
keywords: grav, plugin, markdown, underline, underscores keywords: grav, plugin, markdown, underline, override, inline, block
bugs: https://github.com/goutte/grav-plugin-markdown-underline/issues bugs: https://github.com/Goutte/grav-plugin-markdown-underline/issues
docs: https://github.com/goutte/grav-plugin-markdown-underline/blob/develop/README.md docs: https://github.com/Goutte/grav-plugin-markdown-underline/blob/develop/README.md
license: MIT license: MIT
form: form:
...@@ -25,3 +27,27 @@ form: ...@@ -25,3 +27,27 @@ form:
0: PLUGIN_ADMIN.DISABLED 0: PLUGIN_ADMIN.DISABLED
validate: validate:
type: bool type: bool
"*":
type: text
label: PLUGINS.MARKDOWN_UNDERLINE.*
default: 'em'
validate:
type: text
"**":
type: text
label: PLUGINS.MARKDOWN_UNDERLINE.**
default: 'strong'
validate:
type: text
"_":
type: text
label: PLUGINS.MARKDOWN_UNDERLINE._
default: 'em'
validate:
type: text
"__":
type: text
label: PLUGINS.MARKDOWN_UNDERLINE.__
default: 'u'
validate:
type: text
en:
PLUGINS:
MARKDOWN_UNDERLINE:
"*": HTML tag to replace <code>*</code>
"**": HTML tag to replace <code>**</code>
"_": HTML tag to replace <code>_</code>
"__": HTML tag to replace <code>__</code>
<?php <?php
namespace Grav\Plugin; namespace Grav\Plugin;
use Grav\Common\Plugin; use Grav\Common\Plugin;
...@@ -56,37 +57,53 @@ class MarkdownUnderlinePlugin extends Plugin ...@@ -56,37 +57,53 @@ class MarkdownUnderlinePlugin extends Plugin
{ {
$markdown = $event['markdown']; $markdown = $event['markdown'];
$mu_config = $this->config->get('plugins.markdown-underline');
// 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->addInlineType('_', 'Underline', 0); $markdown->addInlineType('_', 'PluginUnderline', 0);
$markdown->addInlineType('*', 'PluginUnderline', 0);
$inlineUnderline = function($Excerpt) $inlineUnderline = function ($Excerpt) use ($mu_config) {
{
if (strlen($Excerpt['text']) < 5) { // if (strlen($Excerpt['text']) < 2) {
// return;
// }
if ( ! isset($Excerpt['text'][1])) {
return; return;
} }
$marker = $Excerpt['text'][0]; $marker = $Excerpt['text'][0];
if ($marker !== '_') { if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) {
return; if ($marker === '_') {
} $tag = $mu_config['__'];
} else {
if ( ! preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) { $tag = $mu_config['**'];
}
} elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) {
if ($marker === '_') {
$tag = $mu_config['_'];
} else {
$tag = $mu_config['*'];
}
} else {
return; return;
} }
return array( return array(
'extent' => strlen($matches[0]), 'extent' => strlen($matches[0]),
'element' => array( 'element' => array(
'name' => 'u', 'name' => $tag,
'handler' => 'line', 'handler' => 'line',
'text' => $matches[1], 'text' => $matches[1],
), ),
); );
}; };
$markdown->inlineUnderline = $inlineUnderline->bindTo($markdown, $markdown); $markdown->inlinePluginUnderline = $inlineUnderline->bindTo($markdown, $markdown);
} }
} }
enabled: true enabled: true
"*": em
"**": strong
"_": em
"__": u
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