Commit fdd64909 authored by Administrator's avatar Administrator 💬

Add the made-for-the-occasion markdown-underline plugin.

parent 32d28a24
Pipeline #38 passed with stage
in 44 seconds
# v0.1.0
## 03/20/2019
1. [](#new)
* Convert double underscore inline blocks to underline.
The MIT License (MIT)
Copyright (c) 2019 Shady Oryx
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# Markdown Underline Plugin
Overrides the default behavior to convert double underscore `__` inline blocks to underline `<u>` instead of `<strong>`.
**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.
Anyways, it's just another tag for your CSS to tinker with, you don't have to underline.
The **Markdown Underline** Plugin is for [Grav CMS](http://github.com/getgrav/grav). Use __double underscore__ create `<u>` tags.
## Installation
Installing the Markdown Underline plugin can be done in one of two ways. The GPM (Grav Package Manager) installation method enables you to quickly and easily install the plugin with a simple terminal command, while the manual method enables you to do so via a zip file.
### GPM Installation (Preferred)
!! NOT SUBMITTED YET
The simplest way to install this plugin is via the [Grav Package Manager (GPM)](http://learn.getgrav.org/advanced/grav-gpm) through your system's terminal (also called the command line). From the root of your Grav install type:
bin/gpm install markdown-underline
This will install the Markdown Underline plugin into your `/user/plugins` directory within Grav. Its files can be found under `/your/site/grav/user/plugins/markdown-underline`.
### Manual Installation
To install this plugin, just download the zip version of this repository and unzip it under `/your/site/grav/user/plugins`. Then, rename the folder to `markdown-underline`. You can find these files on [GitHub](https://github.com/goutte/grav-plugin-markdown-underline) or via [GetGrav.org](http://getgrav.org/downloads/plugins#extras).
You should now have all the plugin files under
/your/site/grav/user/plugins/markdown-underline
> NOTE: This plugin is a modular component for Grav which requires [Grav](http://github.com/getgrav/grav) and the [Error](https://github.com/getgrav/grav-plugin-error) and [Problems](https://github.com/getgrav/grav-plugin-problems) to operate.
### Admin Plugin
If you use the admin plugin, you can install directly through the admin plugin by browsing the `Plugins` tab and clicking on the `Add` button.
## Configuration
Before configuring this plugin, you should copy the `user/plugins/markdown-underline/markdown-underline.yaml` to `user/config/plugins/markdown-underline.yaml` and only edit that copy.
Here is the default configuration and an explanation of available options:
```yaml
enabled: true
```
Note that if you use the admin plugin, a file with your configuration, and named markdown-underline.yaml will be saved in the `user/config/plugins/` folder once the configuration is saved in the admin.
## Usage
This will be __underlined text__.
yields
This will be <u>underlined text</u>.
## Future
- Perhaps evolve into a plugin that allows individual overriding of `*`, `**`, `_`, `__` etc.
\ No newline at end of file
name: Markdown Underline
version: 0.1.0
description: Use `__double underscore__` to create `<u>` tags.
icon: plug
author:
name: Shady Oryx
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
license: MIT
form:
validation: strict
fields:
enabled:
type: toggle
label: PLUGIN_ADMIN.PLUGIN_STATUS
highlight: 1
default: 0
options:
1: PLUGIN_ADMIN.ENABLED
0: PLUGIN_ADMIN.DISABLED
validate:
type: bool
<?php
namespace Grav\Plugin;
use Grav\Common\Plugin;
use RocketTheme\Toolbox\Event\Event;
/**
* __some text__ => <u>some text</u>
*
* 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.
*
* Not sure how this will fare with multibyte strings. Probably badly.
* Try mb_strlen ?
*
* Class MarkdownUnderlinePlugin
* @package Grav\Plugin
*/
class MarkdownUnderlinePlugin extends Plugin
{
/**
* @return array
*
* The getSubscribedEvents() gives the core a list of events
* that the plugin wants to listen to. The key of each
* array section is the event that the plugin listens to
* and the value (in the form of an array) contains the
* callable (or function) as well as the priority. The
* higher the number the higher the priority.
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0]
];
}
/**
* Initialize the plugin
*/
public function onPluginsInitialized()
{
// Don't proceed if we are in the admin plugin
// This check is legacy, and is perhaps not useful?
if ($this->isAdmin()) {
return;
}
// Enable the main event we are interested in
$this->enable([
'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
]);
}
public function onMarkdownInitialized(Event $event)
{
$markdown = $event['markdown'];
// Add our parser right before the Emphasis one.
// See vendor/erusev/parsedown/Parsedown.php#L977
$markdown->addInlineType('_', 'Underline', 0);
$inlineUnderline = function($Excerpt)
{
if (strlen($Excerpt['text']) < 5) {
return;
}
$marker = $Excerpt['text'][0];
if ($marker !== '_') {
return;
}
if ( ! preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) {
return;
}
return array(
'extent' => strlen($matches[0]),
'element' => array(
'name' => 'u',
'handler' => 'line',
'text' => $matches[1],
),
);
};
$markdown->inlineUnderline = $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