Skip to content

Commit

Permalink
Merge branch 'release/4.1.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Sep 5, 2019
2 parents d0ae495 + 0c05a1d commit 095c2a2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v4.1.5
## 09/05/2019

1. [](#improved)
* Run `onContentProcessed()` event after all other plugins [#75](https://github.com/getgrav/grav-plugin-shortcode-core/issues/75)

# v4.1.4
## 08/11/2019

Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,17 @@ You can now use shortcodes in Twig templates and process them with the `|shortco
{{ twig_text|shortcodes }}
```

## Developing Shortcode Plugins
## Custom Shortcodes

The **Shortcode Core** plugin is developed on the back of the [Thunderer Advanced Shortcode Engine](https://github.com/thunderer/Shortcode) and as such loads the libraries and classes required to build third party shortcode plugins.
### Simple Way

First, configure a directory from which custom shortcodes are loaded. Edit `user/config/plugins/shortcode-core.yaml` like follows (create it if it does not exist):

```yaml
custom_shortcodes: '/user/custom/shortcodes'
```

The simplest way to add your own custom shortcodes, it to simply create a new shortcode in a directory (e.g. `user/custom/shortcodes`) such as this simple one to allow for strike-through text:
To add a custom shortcode, create a PHP file that defines a new shortcode class. For example, to create a shortcode for ~~strikethrough~~ text, save the following code as `user/custom/shortcodes/StrikeShortcode.php`:

```php
<?php
Expand All @@ -445,13 +451,15 @@ class StrikeShortcode extends Shortcode
}
```

Then simply set the plugin to look in this directory for custom shortcodes by editing the `user/config/plugins/shortcode-core.yaml` file (create it if missing):
Note that the class name (`StrikeShortcode`) must match the file name for the shortcode to work.

```yaml
custom_shortcodes: '/user/custom/shortcodes'
```
`[strike]text[/strike]` should now produce strikethrough text.

The more flexible approach is to create a custom plugin to do provide a tidy package for your shotdcodes.
### As a Custom Plugin

The more flexible approach is to create a custom plugin.

The **Shortcode Core** plugin is developed on the back of the [Thunderer Advanced Shortcode Engine](https://github.com/thunderer/Shortcode) and as such loads the libraries and classes required to build third party shortcode plugins.

We introduced a new event called `onShortcodeHandlers()` that allows a 3rd party plugin to create and add their own custom handlers. These are then all processed by the core plugin in one shot.

Expand Down Expand Up @@ -524,4 +532,4 @@ However, there are situations when you need to process the shortcode **before**
$this->shortcode->getRawHandlers()->add('prism', function(ProcessedShortcode $sc) { ... }
```

The difference here is it uses `getRawHandlers()` to ensure the handler is processed to the content in the _raw_ state.
The difference here is it uses `getRawHandlers()` to ensure the handler is processed to the content in the _raw_ state.
2 changes: 1 addition & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Shortcode Core
version: 4.1.4
version: 4.1.5
description: "This plugin provides the core functionality for shortcode plugins"
icon: code
author:
Expand Down
2 changes: 1 addition & 1 deletion shortcode-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function onPluginsInitialized()
'onMarkdownInitialized' => ['onMarkdownInitialized', 0],
'onShortcodeHandlers' => ['onShortcodeHandlers', 0],
'onPageContentRaw' => ['onPageContentRaw', 0],
'onPageContentProcessed' => ['onPageContentProcessed', 0],
'onPageContentProcessed' => ['onPageContentProcessed', -10],
'onPageContent' => ['onPageContent', 0],
'onTwigInitialized' => ['onTwigInitialized', 0]
]);
Expand Down

0 comments on commit 095c2a2

Please sign in to comment.