xp-forge / markdown
Markdown
Installs: 13 403
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
Requires
- php: >=7.0.0
- xp-framework/core: ^12.0 | ^11.0 | ^10.0
Requires (Dev)
- xp-framework/test: ^2.0 | ^1.0
This package is auto-updated.
Last update: 2024-11-22 16:23:14 UTC
README
The Markdown syntax implemented for the XP Framework.
Example
To transform markdown to HTML, all that is necessary is the following:
use net\daringfireball\markdown\Markdown; $engine= new Markdown(); $transformed= $engine->transform( 'This is [Markdown](http://daringfireball.net/projects/markdown/) for **XP**' );
The implementation is based on a parse tree. To work with the tree, you can use the parse()
method, which returns a net.daringfireball.markdown.ParseTree
instance.
use net\daringfireball\markdown\{Markdown, ToHtml}; use io\streams\TextReader; use io\File; $engine= new Markdown(); $tree= $engine->parse($markdown); $tree= $engine->parse(new TextReader(new File('file.md'))); // ...work with tree... $transformed= $tree->emit(new ToHtml());
You can control the URLs used in the href
and src
attributes of links and images, respectively, by using URL rewriting API:
use net\daringfireball\markdown\{ToHtml, URLs, Rewriting}; $emitter= new ToHtml(new URLs(Rewriting::absolute() ->links('/deref?url=%s') ->images('/proxy?url=&s') ->excluding(['localhost']) )); $transformed= $engine->transform($markdown, [], $emitter); $transformed= $engine->parse($markdown)->emit($emitter);