Download the PHP package onesimus-systems/recoder without Composer
On this page you can find all versions of the php package onesimus-systems/recoder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download onesimus-systems/recoder
More information about onesimus-systems/recoder
Files in onesimus-systems/recoder
Package recoder
Short Description Simple shortcode library
License MIT
Homepage http://blog.onesimussystems.com
Informations about the package recoder
Recoder
Recoder is a simple shortcode processor that uses Wordpress-like syntax. This library supports multiple formats such as:
Requirements
- PHP >= 5.4
- Multibyte string extension
Installation
Composer:
or in your composer.json:
and run composer install
.
Usage
Methods
Basic usage
Shortcodes must be a string and be made up of letters, numbers, hyphens, or underscores. They cannot begin with an underscore. register
and registerAlias
will return false for an invalid code, true otherwise. Shortcodes may be overwritten by registering a new function. They can also be unregistered:
Aliasing Codes
Aliased codes are resolved at processing time. This means, if the callback for the aliased code changes, the alias will resolve to the new callback instead of the original callback when it was registered.
Using Arguments
The options array contains the following library defined keys:
_raw
- Raw shortcode including content and ending tag_content
- Text inside a paired shortcode, blank if shortcode is self-closing_offset
- Offset in the text where the shortcode was found_code
- The shortcode name itself_length
- The length of the raw shortcode string
Any other keys are arguments from the shortcode. Keys beginning with an _ are reserved for library use.
Passing extra arguments to shortcode handlers
Define your own syntax
Edge Cases
- Unregistered shortcodes will be ignored and left as they are.
- Mismatching closing shortcode (
[code]content[/codex]
) will be ignored, opening tag will be interpreted as self-closing shortcode, eg.[code]
. - Overlapping shortcodes (
[code]content[inner][/code]content[/inner]
) are not supported and will be interpreted as self-closing, eg.[code]content[inner][/code]
, second closing tag will be ignored. - Nested shortcodes with the same name are also considered overlapping, which means that (assume that shortcode
[c]
returns its content) string[c]x[c]y[/c]z[/c]
will be interpreted asxyz[/c]
(first closing tag was matched to first opening tag). This can be solved by aliasing given shortcode handler name, because for example[c]x[d]y[/d]z[/c]
will be processed correctly.
License
Recoder is licensed under MIT.