Skip to content

Commit

Permalink
Released 0.3.0 (see release-page)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Kerzig committed Oct 31, 2017
1 parent 71ac407 commit e768a82
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Even if `id.prefix` defaults to `false` I encourage you to set it to something l

#### Default of `id.rules`

You can either pass a regular expression as the replacement or a callback-function. They will be used with `preg_replace_callback` or `preg_replace`, respectively.



```php
[
// characters to replace with an hyphen
Expand All @@ -75,6 +79,8 @@ Even if `id.prefix` defaults to `false` I encourage you to set it to something l
// remove trailing hyphens and squash multiple occurences
'/-+$/' => '',
'/-{2,}/' => '-',
// convert everything to lowercase (using a callback-function)
'/([A-Z]+)/' => function($x) { return strtolower($x[1]); }
]
```

Expand Down
3 changes: 2 additions & 1 deletion anchor-headings.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* @package Kirby CMS
* @author Dennis Kerzig <hi@wottpal.com>
* @version 0.2.0
* @version 0.3.0
*
*/

Expand All @@ -33,6 +33,7 @@ function headingAnchors($field)
'/[^A-Za-z0-9\-]/' => '',
'/-+$/' => '',
'/-{2,}/' => '-',
'/([A-Z]+)/' => function($x) { return strtolower($x[1]); }
]),
'markup' => c::get('anchorheadings.markup', "
<a href='#{id}'>{enum}.</a> {heading}
Expand Down
7 changes: 6 additions & 1 deletion helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ function buildID($options, $enum, $text) {
if ($options['id_prepend_enum']) $id = $enum . $options['enum_seperator'] . $id;

foreach($options['id_rules'] as $pattern => $replacement) {
$id = preg_replace($pattern, $replacement, $id);
if (is_callable($replacement)) {
$id = preg_replace_callback($pattern, $replacement, $id);
} else {
$id = preg_replace($pattern, $replacement, $id);
}

}

if ($options['id_prefix']) $id = $options['id_prefix'] . $id;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "anchor-headings",
"description": "A kirby field-method which enumerates heading-elements, generates IDs for anchor-links and inserts custom markup based on your needs.",
"author": "Dennis Kerzig <hi@wottpal.com> (https://wottpal.com)",
"version": "0.2.0",
"version": "0.3.0",
"type": "kirby-plugin",
"license": "MIT"
}

0 comments on commit e768a82

Please # to comment.