Download the PHP package mistralys/markdown-renderer without Composer
On this page you can find all versions of the php package mistralys/markdown-renderer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mistralys/markdown-renderer
More information about mistralys/markdown-renderer
Files in mistralys/markdown-renderer
Package markdown-renderer
Short Description CommonMark Markdown renderer for PHP with pre- and post-processors.
License MIT
Informations about the package markdown-renderer
Markdown Renderer
CommonMark Markdown renderer for PHP with the capability to define pre- and post-processors with custom syntax.
Usage
From a Markdown string
From a Markdown file
Adding a processor
Any number of processors can be added with the addProcessor()
method. They are executed in the order that they are added.
Example: Adding the bundled video processor.
Custom syntax
The library is based on a simple syntax for defining custom commands, which follow the following scheme with pseudo HTML attributes:
The parsing of these commands is handled automatically by the library, and the attributes can easily be accessed via a helper class when rendering the matching content.
Adding a custom processor
If you want to do your own syntax parsing, create a class based on
BaseProcessor
. Use the BaseCommandBasedProcessor
class if you want
to use the library's command syntax (easiest to implement). Simply
implement all abstract methods, and you're good to go.
Every abstract method has documentation on what you are supposed to do.
You can create your processor class anywhere in your project, and add
it to the renderer with the addProcessor()
method.
Origin
I had created similar Markdown filters in several of my personal and professional projects. Each project had different enough requirements for syntax and content, and were easy enough to implement, so for a long time I did not take the step to move the common functionality to a separate library.
Another recent project made me take the step. As is often the case, I was annoyed enough by having to create regexes to parse the commands that I decided to do it right.
Philosophy
I have read quite a few discussions on what kind of information should be included in a Markdown file. Image widths are one thing that the community is divided on. I agree that the width of an image is layout information, not content. The requirement is real however, and appears often enough for me to take a pragmatic approach.
My philosophy is that as long as the Markdown content stays easily readable, and that the added syntax does not interfere with reading the document, I don't mind.
All versions of markdown-renderer with dependencies
mistralys/application-localization Version >=1.4.1
league/commonmark Version >=2.4.1