PHPackages                             nks-hub/nette-markdown - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. nks-hub/nette-markdown

ActiveLibrary[Templating &amp; Views](/categories/templating)

nks-hub/nette-markdown
======================

Nette DI extension wrapping league/commonmark with Latte filter support

v1.2.0(1mo ago)05↓100%MITPHPPHP ^8.2CI passing

Since Mar 12Pushed 1mo agoCompare

[ Source](https://github.com/nks-hub/nette-markdown)[ Packagist](https://packagist.org/packages/nks-hub/nette-markdown)[ RSS](/packages/nks-hub-nette-markdown/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (4)Used By (0)

nks-hub/nette-markdown
======================

[](#nks-hubnette-markdown)

[![Build Status](https://github.com/nks-hub/nette-markdown/actions/workflows/ci.yml/badge.svg)](https://github.com/nks-hub/nette-markdown/actions)[![Packagist Version](https://camo.githubusercontent.com/7d720c27b4ebdc1def1f607740eaeb480a08e94bed189ef269fbf78b980bed14/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6b732d6875622f6e657474652d6d61726b646f776e2e737667)](https://packagist.org/packages/nks-hub/nette-markdown)[![Packagist Downloads](https://camo.githubusercontent.com/a71ae4173680aa9138333b36cadbc06ce4b527442ddc2f719f11818363b53331/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6b732d6875622f6e657474652d6d61726b646f776e2e737667)](https://packagist.org/packages/nks-hub/nette-markdown)[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/6ae0b8f5cdc48f275d19b87d9c57bbce4335a792ad870bd1770888fd608dfc7c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e322b2d3838393262652e737667)](https://php.net/)[![Tests](https://camo.githubusercontent.com/ca3ff910cac115cd06569aa566715cc6514eeb96c11a06d928ea321ed2294df1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d31302532307061737365642d627269676874677265656e2e737667)](https://github.com/nks-hub/nette-markdown/actions)

> Nette Framework DI extension wrapping [league/commonmark](https://commonmark.thephpleague.com/) with GitHub Flavored Markdown support, Latte filter integration, and configurable extension system.

---

Why nette-markdown?
-------------------

[](#why-nette-markdown)

Nette Framework lacks a first-class Markdown integration. While `league/commonmark` is an excellent CommonMark parser, wiring it into Nette's DI container, configuring extensions, and registering Latte filters requires boilerplate code in every project.

This package provides a **zero-config drop-in** that just works:

- **Nette DI Extension** — Register in `config.neon`, get `MarkdownConverter` autowired everywhere
- **Latte Filter** — Use `{$content|markdown}` in any template, automatically registered
- **GFM by Default** — Tables, task lists, strikethrough, autolinks out of the box
- **Configurable** — Enable/disable extensions, set security policies, add heading permalinks
- **Safe by Default** — HTML input stripped, unsafe links blocked

---

Quick Start
-----------

[](#quick-start)

### Installation

[](#installation)

```
composer require nks-hub/nette-markdown
```

### Register in Nette DI

[](#register-in-nette-di)

```
# config/common.neon
extensions:
    markdown: NksHub\Markdown\DI\MarkdownExtension
```

That's it. `MarkdownConverter` is now available for injection, and the `|markdown` Latte filter is registered automatically.

---

Usage
-----

[](#usage)

### In Presenters / Services (Dependency Injection)

[](#in-presenters--services-dependency-injection)

```
use NksHub\Markdown\MarkdownConverter;

class WikiPresenter extends Nette\Application\UI\Presenter
{
    public function __construct(
        private MarkdownConverter $markdown,
    ) {}

    public function renderView(string $slug): void
    {
        $page = $this->pages->findBySlug($slug);
        $this->template->htmlContent = $this->markdown->convert($page->getContent());
    }
}
```

### In Latte Templates

[](#in-latte-templates)

```
{* Filter syntax *}
{$page->getContent()|markdown|noescape}

{* Or in a block *}
{var $html = ($page->getContent()|markdown)}
{$html|noescape}
```

### Standalone (Without Nette DI)

[](#standalone-without-nette-di)

```
use NksHub\Markdown\MarkdownConverter;

$converter = new MarkdownConverter();
$html = $converter->convert('# Hello **World**');
// Hello World

// Safe mode — strips all HTML, blocks unsafe links
$safeHtml = $converter->convertSafe($userInput);
```

---

Features
--------

[](#features)

FeatureDescription**CommonMark**Full CommonMark spec compliance via league/commonmark 2.x**GFM Tables**Pipe-delimited tables with alignment**Task Lists**`- [x] Done` / `- [ ] Todo` checkbox rendering**Strikethrough**`~~deleted~~` to `deleted`**Autolinks**URLs automatically converted to clickable links**Footnotes**`[^1]` reference-style footnotes (opt-in)**Smart Punctuation**Curly quotes, em-dashes, ellipsis (opt-in)**Heading Permalinks**Anchor links on headings for deep linking (opt-in)**Table of Contents**Auto-generated TOC from headings (opt-in)**Fenced Code Blocks**````lang` syntax with language class output**XSS Protection**HTML stripped, unsafe links (`javascript:`) blocked by default**Latte Integration**`|markdown` filter auto-registered on all Latte engines---

Configuration
-------------

[](#configuration)

### Default (Zero Config)

[](#default-zero-config)

```
extensions:
    markdown: NksHub\Markdown\DI\MarkdownExtension
```

Defaults: CommonMark + GFM (tables, task lists, strikethrough, autolinks), HTML stripped, unsafe links blocked.

### Full Configuration

[](#full-configuration)

```
extensions:
    markdown: NksHub\Markdown\DI\MarkdownExtension

markdown:
    # Extensions to enable (default: commonmark + gfm)
    extensions:
        - commonmark       # Core CommonMark spec (always needed)
        - gfm              # Tables + Strikethrough + Task Lists + Autolinks
        - footnote         # Reference-style footnotes
        - smartpunct       # Curly quotes, em-dashes, ellipsis
        - heading_permalink # Anchor links on headings
        - toc              # Auto-generated Table of Contents

    # HTML input handling: strip (default), allow, escape
    html_input: strip

    # Block javascript:, vbscript:, data: links (default: false = blocked)
    allow_unsafe_links: false

    # Heading permalink symbol (only when heading_permalink extension enabled)
    heading_permalink:
        symbol: '#'
```

### Available Extensions

[](#available-extensions)

KeyExtensionDescription`commonmark``CommonMarkCoreExtension`Core CommonMark spec — always include this`gfm`Tables + Strikethrough + TaskList + AutolinkGitHub Flavored Markdown bundle`footnote``FootnoteExtension``[^1]` reference-style footnotes`smartpunct``SmartPunctExtension`Smart quotes, dashes, ellipsis`heading_permalink``HeadingPermalinkExtension`Clickable anchor links on headings`toc``TableOfContentsExtension`Auto-generated TOC from headings---

API Reference
-------------

[](#api-reference)

### `MarkdownConverter`

[](#markdownconverter)

```
use NksHub\Markdown\MarkdownConverter;

// Default: CommonMark + GFM, HTML stripped, unsafe links blocked
$converter = new MarkdownConverter();

// Custom config
$converter = new MarkdownConverter([
    'extensions' => ['commonmark', 'gfm', 'footnote'],
    'html_input' => 'allow',
    'allow_unsafe_links' => false,
]);

// Convert Markdown to HTML
$html = $converter->convert($markdown);

// Safe conversion (always strips HTML + blocks unsafe links, regardless of config)
$safeHtml = $converter->convertSafe($untrustedInput);
```

### `MarkdownFilter` (Latte)

[](#markdownfilter-latte)

Automatically registered when using the DI extension. Callable as a Latte filter:

```
{$content|markdown|noescape}
```

Returns `Latte\Runtime\Html` instance, so `|noescape` is required to render the HTML.

### `MarkdownExtension` (Nette DI)

[](#markdownextension-nette-di)

Registers two services:

- `NksHub\Markdown\MarkdownConverter` — injectable converter
- `NksHub\Markdown\Latte\MarkdownFilter` — auto-registered on all Latte engines

---

Security
--------

[](#security)

The converter is **safe by default**:

SettingDefaultEffect`html_input``strip`Removes all raw HTML from Markdown input`allow_unsafe_links``false`Blocks `javascript:`, `vbscript:`, `data:` URLsFor user-generated content, use `convertSafe()` which enforces both settings regardless of constructor config.

**Never** use `html_input: allow` with untrusted input — it allows raw HTML injection including `` tags.

---

Development
-----------

[](#development)

```
# Install dependencies
composer install

# Run tests (PHPUnit 10)
vendor/bin/phpunit

# Run with coverage
vendor/bin/phpunit --coverage-html coverage/

# Static analysis
vendor/bin/phpstan analyse
```

---

Requirements
------------

[](#requirements)

- **PHP**: 8.2+
- **league/commonmark**: ^2.8
- **nette/di**: ^3.1
- **latte/latte**: ^3.0

---

Contributing
------------

[](#contributing)

Contributions are welcome! For major changes, please open an issue first.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'feat: description'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

Support
-------

[](#support)

- 📧 **Email:**
- 🐛 **Bug reports:** [GitHub Issues](https://github.com/nks-hub/nette-markdown/issues)
- 📖 **CommonMark docs:** [commonmark.thephpleague.com](https://commonmark.thephpleague.com/)
- 🏗️ **Nette Framework:** [nette.org](https://nette.org)

License
-------

[](#license)

MIT License — see [LICENSE](LICENSE) for details.

---

Links
-----

[](#links)

- [league/commonmark](https://commonmark.thephpleague.com/) — The underlying CommonMark parser
- [Packagist Package](https://packagist.org/packages/nks-hub/nette-markdown)
- [@nks-hub/texy-editor](https://github.com/nks-hub/texy-ts-editor) — TypeScript Texy/Markdown editor with toolbar

---

 Made with ❤️ by [NKS Hub](https://github.com/nks-hub)

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance97

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

3

Last Release

48d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/01e4841749ee2b4cf7211d784b093bf67523ed6489c6931401211b130df13884?d=identicon)[lukyrys](/maintainers/lukyrys)

---

Top Contributors

[![lukyrys](https://avatars.githubusercontent.com/u/2318346?v=4)](https://github.com/lukyrys "lukyrys (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nks-hub-nette-markdown/health.svg)

```
[![Health](https://phpackages.com/badges/nks-hub-nette-markdown/health.svg)](https://phpackages.com/packages/nks-hub-nette-markdown)
```

###  Alternatives

[tightenco/jigsaw

Simple static sites with Laravel's Blade.

2.2k438.5k29](/packages/tightenco-jigsaw)[spatie/commonmark-shiki-highlighter

Highlight code blocks with league/commonmark and Shiki

893.5M9](/packages/spatie-commonmark-shiki-highlighter)[contributte/latte

Extra contrib to nette/latte

111.5M2](/packages/contributte-latte)[webrouse/n-asset-macro

Asset macro for Latte and Nette Framework useful for assets cache busting (with gulp, webpack, etc.)

1264.4k1](/packages/webrouse-n-asset-macro)[nepada/form-renderer

Latte template based form renderer for Nette forms with full support for Bootstrap 3, 4 &amp; 5.

11251.0k](/packages/nepada-form-renderer)[nextras/forms-rendering

Rendering helpers for Nette Framework Forms.

1698.4k2](/packages/nextras-forms-rendering)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
