Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 7bc6b1a

Browse files
authored
Merge pull request #3 from S1SYPHOS/settings
All PEP settings are now available through kirby-pep!
2 parents fb2f6f7 + 35bba20 commit 7bc6b1a

File tree

5 files changed

+164
-21
lines changed

5 files changed

+164
-21
lines changed

README.md

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,44 @@ In order to enable features of [ParsedownExtraPlugin](https://github.com/tovic/p
3636
## Configuration
3737
Change `kirby-pep` [options](https://github.com/tovic/parsedown-extra-plugin#features) to suit your needs:
3838

39-
| Option | Type | Default | Description |
40-
| --- | --- | --- | --- |
41-
| `plugin.kirby-pep.code_class` | String | `language-%s` | Defines the classes used by `<code>` elements (`%s` outputs the language specified at the beginning of your code block). |
42-
| `plugin.kirby-pep.code_block_attr_on_parent` | Boolean | `false` | Moves (inner) `<code>` element attributes on (outer) `<pre>` element. |
39+
- Element prefix (HTML / XHTML)
40+
- `'element_suffix' => '>' // HTML5`
41+
- Predefined abbreviations
42+
- `'abbreviations' => []`
43+
- Predefined links
44+
- `'links' => null`
45+
- Custom attributes for (external) links / images
46+
- `'links_attr' => []`
47+
- `'links_external_attr' => ['rel' => 'nofollow', 'target' => '_blank']`
48+
- `'images_attr' => null`
49+
- `'images_external_attr' => null`
50+
- Custom code class / (block) text
51+
- `'code_class' => 'language-%s'`
52+
- `'code_text' => null`
53+
- `'code_block_text' => null`
54+
- Putting `<code>` attributes on `<pre>` element
55+
- `'code_block_attr_on_parent' => false`
56+
- Custom table (alignment) class
57+
- `'table_class' => null`
58+
- `'table_align_class' => null`
59+
- Custom footnote class
60+
- `'footnote_class' => 'footnotes'`
61+
- Custom footnote link id / class / text
62+
- `'footnote_link_id' => 'fnref:%s'`
63+
- `'footnote_link_class' => 'footnote-ref'`
64+
- `'footnote_link_text' => '[%s]'`
65+
- Custom footnote back link id / class / text
66+
- `'footnote_back_link_id' => 'fnref:%s-%s'`
67+
- `'footnote_back_link_class' => 'footnote-backref'`
68+
- `'footnote_back_link_text' => '↩'`
69+
70+
If you'd like to change them, just prefix each option with `plugin.kirby-pep.` in your `config.php` and you're set! With the following option in place, this plugin integrates seemlessly with `kirby-highlight`, generating themeable [server-side syntax highlighting](https://github.com/S1SYPHOS/kirby-highlight) for Kirby:
4371

44-
**Currently only these two options are available.** In the future, more options will be supported - feel free to [open a PR](https://github.com/S1SYPHOS/kirby-pep/compare)!
72+
```text
73+
c::set('plugin.kirby-pep.code_class', 'language-%s hljs');
74+
```
75+
76+
These [examples](https://github.com/tovic/parsedown-extra-plugin#features) are a **good starting point**, too.
4577

4678
## Credits / License
4779
`kirby-pep` is based on Taufik Nurrohman's `parsedown-extra-plugin` library (an extension to [ParsedownExtra](https://github.com/erusev/parsedown-extra)). It is licensed under the [MIT License](LICENSE), but **using Kirby in production** requires you to [buy a license](https://getkirby.com/buy). Are you ready for the [next step](https://getkirby.com/next)?

core/markdown.php

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Markdown extends \Kirby\Component\Markdown {
2121

2222
/**
2323
* Returns the default options for the component
24-
*
24+
*
2525
* @return array
2626
*/
2727

@@ -34,9 +34,9 @@ public function defaults() {
3434
}
3535

3636
/**
37-
* Initializes the Parsedown parser and
37+
* Initializes the Parsedown parser and
3838
* transforms the given markdown to HTML
39-
*
39+
*
4040
* @param string $markdown
4141
* @return string
4242
*/
@@ -46,20 +46,60 @@ public function parse($markdown) {
4646
if(!$this->kirby->options['markdown']) {
4747
return $markdown;
4848
} else {
49-
// Instantiating ParsedownExtraPlugin
49+
// Instantiating ParsedownExtraPlugin
5050
$parsedown = new ParsedownExtraPlugin();
5151

52-
// Configuring options - see https://github.com/tovic/parsedown-extra-plugin#features
53-
$parsedown->code_class = c::get('plugin.kirby-pep.code_class') ? c::get('plugin.kirby-pep.code_class') : 'language-%s';
54-
$parsedown->code_block_attr_on_parent = c::get('plugin.kirby-pep.code_block_attr_on_parent') ? true : false;
55-
5652
// set markdown auto-breaks
5753
$parsedown->setBreaksEnabled($this->kirby->options['markdown.breaks']);
5854

55+
/**
56+
* Configuring ParsedownExtraPlugin options
57+
*
58+
* See https://github.com/tovic/parsedown-extra-plugin#features
59+
*/
60+
61+
// HTML or XHTML
62+
$parsedown->element_suffix = settings::element_suffix();
63+
64+
// Predefined abbreviations
65+
$parsedown->abbreviations = settings::abbreviations();
66+
67+
// Predefined links
68+
$parsedown->links = settings::links();
69+
70+
// Custom attributes for (external) links / images
71+
$parsedown->links_attr = settings::links_attr();
72+
$parsedown->links_external_attr = settings::links_external_attr();
73+
$parsedown->images_attr = settings::images_attr();
74+
$parsedown->images_external_attr = settings::images_external_attr();
75+
76+
// Custom code class / (block) text
77+
$parsedown->code_class = settings::code_class();
78+
$parsedown->code_text = settings::code_text();
79+
$parsedown->code_block_text = settings::code_block_text();
80+
81+
// Putting <code> attributes on <pre> element
82+
$parsedown->code_block_attr_on_parent = settings::code_block_attr_on_parent();
83+
84+
// Custom table (alignment) class
85+
$parsedown->table_class = settings::table_class();
86+
$parsedown->table_align_class = settings::table_align_class();
87+
88+
// Custom footnote class
89+
$parsedown->footnote_class = settings::footnote_class();
90+
91+
// Custom footnote link id / class / text
92+
$parsedown->footnote_link_id = settings::footnote_link_id();
93+
$parsedown->footnote_link_class = settings::footnote_link_class();
94+
$parsedown->footnote_link_text = settings::footnote_link_text();
95+
96+
// Custom footnote back link id / class / text
97+
$parsedown->footnote_back_link_id = settings::footnote_back_link_id();
98+
$parsedown->footnote_back_link_class = settings::footnote_back_link_class();
99+
$parsedown->footnote_back_link_text = settings::footnote_back_link_text();
100+
59101
// Parse it!
60102
return $parsedown->text($markdown);
61103
}
62-
63104
}
64-
65105
}

core/settings.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace S1SYPHOS\PEP;
4+
5+
use c;
6+
7+
class Settings {
8+
9+
/**
10+
* Returns the default options for `kirby-pep`
11+
*
12+
* @return array
13+
*/
14+
15+
public static function __callStatic($name, $args) {
16+
17+
// Set prefix
18+
$prefix = 'plugin.kirby-pep.';
19+
20+
// Set config names and fallbacks as settings
21+
$settings = [
22+
23+
// HTML or XHTML
24+
'element_suffix' => '>', // HTML5
25+
26+
// Predefined abbreviations
27+
'abbreviations' => null,
28+
29+
// Predefined links
30+
'links' => null,
31+
32+
// Custom attributes for (external) links / images
33+
'links_attr' => [],
34+
'links_external_attr' => ['rel' => 'nofollow', 'target' => '_blank'],
35+
'images_attr' => null,
36+
'images_external_attr' => null,
37+
38+
// Custom code class / (block) text
39+
'code_class' => 'language-%s',
40+
'code_text' => null,
41+
'code_block_text' => null,
42+
43+
// Putting <code> attributes on <pre> element
44+
'code_block_attr_on_parent' => false,
45+
46+
// Custom table (alignment) class
47+
'table_class' => null,
48+
'table_align_class' => null,
49+
50+
// Custom footnote class
51+
'footnote_class' => null,
52+
53+
// Custom footnote link id / class / text
54+
'footnote_link_id' => 'fnref:%s',
55+
'footnote_link_class' => 'footnote-ref',
56+
'footnote_link_text' => '[%s]',
57+
58+
// Custom footnote back link id / class / text
59+
'footnote_back_link_id' => 'fnref:%s-%s',
60+
'footnote_back_link_class' => 'footnote-backref',
61+
'footnote_back_link_text' => '',
62+
];
63+
64+
// If config settings exist, return the config with fallback
65+
if(isset($settings) && array_key_exists($name, $settings)) {
66+
return c::get($prefix . $name, $settings[$name]);
67+
}
68+
}
69+
}

kirby-pep.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
* @package Kirby CMS
77
* @author S1SYPHOS <hello@twobrain.io>
88
* @link http://twobrain.io
9-
* @version 0.1.0-beta
9+
* @version 0.2.0-beta
1010
* @license MIT
1111
*/
1212

1313
if(!c::get('plugin.kirby-pep')) return;
1414

15-
// Loading ParsedownExtraPlugin & core
15+
// Loading ParsedownExtraPlugin
16+
require_once __DIR__ . DS . 'vendor' . DS . 'ParsedownExtraPlugin.php';
17+
18+
// Loading settings & core
1619
load([
17-
'parsedownextraplugin' => __DIR__ . DS . 'vendor' . DS . 'ParsedownExtraPlugin.php',
18-
's1syphos\\pep\\markdown' => __DIR__ . DS . 'core' . DS . 'markdown.php'
20+
's1syphos\\pep\\settings' => __DIR__ . DS . 'core' . DS . 'settings.php',
21+
's1syphos\\pep\\markdown' => __DIR__ . DS . 'core' . DS . 'markdown.php'
1922
]);
2023

2124
// Registering with Kirby's extension registry
2225
kirby()->set('component', 'markdown', 'S1SYPHOS\\PEP\\MARKDOWN');
23-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "kirby-pep",
33
"description": " Supercharging Parsedown with ParsedownExtraPlugin for Kirby",
44
"author": "S1SYPHOS <hello@twobrain.io>",
5-
"version": "0.1.0-beta",
5+
"version": "0.2.0-beta",
66
"type": "kirby-plugin",
77
"license": "MIT"
88
}

0 commit comments

Comments
 (0)