Download the PHP package seiler/shortcoder without Composer
On this page you can find all versions of the php package seiler/shortcoder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download seiler/shortcoder
More information about seiler/shortcoder
Files in seiler/shortcoder
Package shortcoder
Short Description Build your own shortcodes system with ease
License MIT
Homepage https://github.com/fredericseiler/shortcoder
Informations about the package shortcoder
Shortcoder
Shortcoder helps you to build your own shortcodes system in your PHP application with ease.
This package is compliant with PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.
Requirements
The following versions of PHP are supported by this version.
- PHP 5.5
- PHP 5.6
- PHP 7.0
- HHVM
Installation
Via Composer
Usage
-
Create a new Shortcoder instance:
-
Add your shortcodes:
- Parse some text:
Documentation
A shortcode is defined by a pattern, a replacement and an optional regex flag. A shortcode pattern usually contains one or more wildcards to represent the content to be preserved between the pattern and the replacement.
Shortcoder allows you to add()
shortcodes with the following syntaxes.
-
Method arguments:
-
Key/value array:
-
Descriptive array:
- Multiple shortcodes at once:
The flush()
and set()
methods are useful for flushing the current shortcodes stack. The set()
method also adds new shortcodes after a flush.
Because set()
is called when you create a new Shortcoder instance, all of the add()
syntaxes are available in the constructor as well.
The parse()
method takes any string as input and parses it with the stacked shortcodes.
Method chaining
The add()
, set()
and flush()
methods supports method chaining.
Multiple wildcards
Wildcards are replaced by regular expression powered catch-alls when adding shortcodes to the stack. It means that when you add multiple wildcards, Shortcoder will match each wildcard in a pattern to its corresponding position in the replacement.
When a wildcard directly follows another wildcard in a pattern, only the first word of the matching expression will be assigned to the first wildcard, the remaining of the expression will be catched as the second wildcard.
Regular expressions
When setting the third argument of the add()
method (or the regex
attribute of the shortcode) to any 'true' value, Shortcoder will handle pattern and replacement as raw regular expressions, which can be useful for more advanced usages.
Backreferences
When forcing position of some of the backreferences in a shortcode's replacement, Shortcoder will guess what to do with the remaining wildcards.
Markdown compatibility
In case you're using Shortcoder to render some HTML blocks, just append markdown=1
in your replacement attributes to support Markdown Extra. Here's an example with Parsedown Extra:
With CommonMark, it's a little bit more tricky. Rules are not the same for inline and block level elements. Example of an inline level element with the league/commonmark implementation:
And here's the same example, but this time with a block level element:
Testing
Contributing
Please see CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Frederic Seiler
- All Contributors
License
The MIT License (MIT). Please see License File for more information.