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
version: 0.1.0
description: Use `__double underscore__` to create `<u>` tags.
icon: plug
version: 1.0.0
description: |
Override the HTML tags generated by inline `*`, `**`, `_` and `__`.
The plugin defaults `__` to `u` for example to yield underlined text.
icon: underline
author:
name: Shady Oryx
name: Antoine Goutenoir
email: antoine@goutenoir.com
homepage: https://github.com/Goutte/grav-plugin-markdown-underline
demo: https://courses.m3p2.ljbac.com
keywords: grav, plugin, markdown, underline, underscores
bugs: https://github.com/goutte/grav-plugin-markdown-underline/issues
docs: https://github.com/goutte/grav-plugin-markdown-underline/blob/develop/README.md
keywords: grav, plugin, markdown, underline, override, inline, block
bugs: https://github.com/Goutte/grav-plugin-markdown-underline/issues
docs: https://github.com/Goutte/grav-plugin-markdown-underline/blob/develop/README.md
license: MIT
form:
......@@ -25,3 +27,27 @@ form:
0: PLUGIN_ADMIN.DISABLED
validate:
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
namespace Grav\Plugin;
use Grav\Common\Plugin;
......@@ -56,37 +57,53 @@ class MarkdownUnderlinePlugin extends Plugin
{
$markdown = $event['markdown'];
$mu_config = $this->config->get('plugins.markdown-underline');
// Add our parser right before the Emphasis one.
// See vendor/erusev/parsedown/Parsedown.php#L977
$markdown->addInlineType('_', 'Underline', 0);
$markdown->addInlineType('_', 'PluginUnderline', 0);
$markdown->addInlineType('*', 'PluginUnderline', 0);
$inlineUnderline = function($Excerpt)
{
if (strlen($Excerpt['text']) < 5) {
$inlineUnderline = function ($Excerpt) use ($mu_config) {
// if (strlen($Excerpt['text']) < 2) {
// return;
// }
if ( ! isset($Excerpt['text'][1])) {
return;
}
$marker = $Excerpt['text'][0];
if ($marker !== '_') {
return;
if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) {
if ($marker === '_') {
$tag = $mu_config['__'];
} else {
$tag = $mu_config['**'];
}
if ( ! preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) {
} elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) {
if ($marker === '_') {
$tag = $mu_config['_'];
} else {
$tag = $mu_config['*'];
}
} else {
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'u',
'name' => $tag,
'handler' => 'line',
'text' => $matches[1],
),
);
};
$markdown->inlineUnderline = $inlineUnderline->bindTo($markdown, $markdown);
$markdown->inlinePluginUnderline = $inlineUnderline->bindTo($markdown, $markdown);
}
}
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