mj-zana / view-markdown
Safe Markdown rendering for mj-zana/view, on league/commonmark
v2.5.0
2026-10-26 14:55 UTC
Requires
- php: ^8.5
- league/commonmark: ^2.6
- mj-zana/view: ^2.4
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Safe Markdown for mj-zana/view, on
league/commonmark.
composer require mj-zana/view-markdown
Register MarkdownServiceProvider after ViewServiceProvider. Templates
then print editors' Markdown with <?= $this->markdown($post->body) ?>
(Twig: {{ markdown(post.body) }}).
- Raw HTML is escaped, never passed through, so editors cannot inject scripts.
- Unsafe links are removed:
javascript:,vbscript:,file:, anddata:other than images. - Headings get ids for links to sections (
view.markdown.heading_anchors). - GitHub-flavoured Markdown: tables, strikethrough, task lists and autolinks.
- Rendering costs time: store the HTML with the content when it is
saved, through
MarkdownRendererInterface, instead of rendering on every request.
License
MIT