PHPackages                             schlessera/markdown-escape - 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. [Security](/categories/security)
4. /
5. schlessera/markdown-escape

ActiveLibrary[Security](/categories/security)

schlessera/markdown-escape
==========================

A PHP library for escaping content to be safely embedded in Markdown without breaking rendering

0319PHPCI passing

Since Jun 16Pushed 11mo agoCompare

[ Source](https://github.com/schlessera/markdown-escape-php)[ Packagist](https://packagist.org/packages/schlessera/markdown-escape)[ RSS](/packages/schlessera-markdown-escape/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Markdown Escape PHP \[⚠️ WIP ⚠️\]
=================================

[](#markdown-escape-php-️-wip-️)

[![Tests](https://github.com/schlessera/markdown-escape-php/workflows/Tests/badge.svg)](https://github.com/schlessera/markdown-escape-php/actions)[![Code Coverage](https://camo.githubusercontent.com/f36642033ad863e437efa2c1258f22e7145998a79e1b213d936f01701a0fab76/68747470733a2f2f636f6465636f762e696f2f67682f7363686c6573736572612f6d61726b646f776e2d6573636170652d7068702f67726170682f62616467652e7376673f746f6b656e3d41394a42354c4d515859)](https://codecov.io/gh/schlessera/markdown-escape-php)[![Latest Stable Version](https://camo.githubusercontent.com/274e46035b37799ec747d813786f11d6753bff159d40183eb4ad113d9205f71a/68747470733a2f2f706f7365722e707567782e6f72672f7363686c6573736572612f6d61726b646f776e2d6573636170652f762f737461626c65)](https://packagist.org/packages/schlessera/markdown-escape)[![License](https://camo.githubusercontent.com/0df27def54162ac28460e85199a33a1a87cef6d2c165552f7cec3a82f81a83a2/68747470733a2f2f706f7365722e707567782e6f72672f7363686c6573736572612f6d61726b646f776e2d6573636170652f6c6963656e7365)](https://packagist.org/packages/schlessera/markdown-escape)

A PHP library for escaping content to be safely embedded in Markdown without breaking rendering. Supports multiple Markdown dialects and provides context-aware escaping for different use cases.

Features
--------

[](#features)

- **Multiple Dialect Support**: CommonMark and GitHub Flavored Markdown (GFM)
- **Context-Aware Escaping**: Different escaping strategies for URLs, inline code, code blocks, and general content
- **Templating System**: Built-in templating engine with PHP short tags for generating complex Markdown documents
- **SOLID Design**: Built with clean architecture and design patterns for easy extension
- **PHP 7.2+ Compatible**: Works with PHP 7.2 and all newer versions
- **Fully Tested**: Comprehensive unit and feature tests
- **Zero Dependencies**: No runtime dependencies beyond PHP itself
- **High Test Coverage**: 98%+ code coverage with comprehensive unit and integration tests

Installation
------------

[](#installation)

Install via Composer:

```
composer require schlessera/markdown-escape
```

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

[](#quick-start)

```
use Markdown\Escape\MarkdownEscape;

// Create an escaper instance (defaults to CommonMark)
$escape = new MarkdownEscape();

// Or use factory methods for specific dialects
$escape = MarkdownEscape::commonMark();
$escape = MarkdownEscape::gfm();

// Escape general content
$escaped = $escape->escapeContent('This is *bold* and _italic_ text');
// Output: This is \*bold\* and \_italic\_ text

// Escape URLs
$escaped = $escape->escapeUrl('https://example.com/path with spaces/(parentheses)');
// Output: https://example.com/path%20with%20spaces/%28parentheses%29

// Escape inline code
$escaped = $escape->escapeInlineCode('Use `backticks` for code');
// Output: ``Use `backticks` for code``

// Escape code blocks
$code = "function test() {\n    return true;\n}";
$escaped = $escape->escapeCodeBlock($code, ['use_fences' => true, 'language' => 'php']);
// Output: ```php
//         function test() {
//             return true;
//         }
//         ```
```

### Templating System

[](#templating-system)

Generate complex Markdown documents using the built-in templating system:

```
use Markdown\Escape\MarkdownTemplate;

// Create template instance
$template = MarkdownTemplate::gfm();

// Use built-in templates
$result = $template->render('table', [
    'headers' => ['Name', 'Status', 'Progress'],
    'rows' => [
        ['Feature **A**', 'Complete', '100%'],
        ['Feature *B*', 'In Progress', '75%']
    ]
]);

// Custom templates with automatic escaping
$result = $template->renderString('
#

Published by  on

##

', [
    'title' => 'My **Important** Document',
    'author' => 'John [Admin] Doe',
    'sections' => [
        ['title' => 'Introduction', 'content' => 'Content with *markdown* syntax...']
    ]
]);
```

Documentation
-------------

[](#documentation)

- [User Guide](docs/user-guide.md) - Comprehensive guide to using the library
- [Templating Guide](docs/templating-guide.md) - Complete guide to the templating system
- [Architecture](docs/architecture.md) - Understanding the library's design
- [Examples](examples/) - Working examples demonstrating various features
- [Code Coverage](docs/code-coverage.md) - Testing and coverage information

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

[](#requirements)

- PHP 7.2 or higher
- Composer for dependency management

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

[](#development)

### Running Tests

[](#running-tests)

```
composer test              # Run all tests
composer test:unit         # Run unit tests only
composer test:integration  # Run integration tests only
composer test:performance  # Run performance tests
```

### Code Coverage

[](#code-coverage)

```
composer test:coverage     # Generate HTML coverage report and text summary
composer test:coverage:clover  # Generate Clover XML report
composer coverage:badge    # Generate coverage badge

# View coverage report
open coverage/html/index.html  # macOS
xdg-open coverage/html/index.html  # Linux
start coverage/html/index.html  # Windows
```

### Code Style

[](#code-style)

```
composer cs       # Check code style
composer cs-fix   # Fix code style issues
```

### Static Analysis

[](#static-analysis)

```
composer phpstan
```

### PHP Compatibility Check

[](#php-compatibility-check)

```
composer phpcompat  # Checks PHP 7.2+ compatibility
```

### Full Check

[](#full-check)

```
composer check    # Runs all checks (CS, PHPStan, PHP compatibility, and tests)
```

License
-------

[](#license)

This library is released under the MIT License. See [LICENSE](LICENSE) file for details.

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

[](#contributing)

Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.

Support
-------

[](#support)

If you discover any security related issues, please email  instead of using the issue tracker.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity14

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6dde7f578e5530884238e7173f768ae3a890b6d66eb99262a82f2c494a1b67d4?d=identicon)[schlessera](/maintainers/schlessera)

---

Top Contributors

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

---

Tags

escapellmmarkdownphpsecurity

### Embed Badge

![Health badge](/badges/schlessera-markdown-escape/health.svg)

```
[![Health](https://phpackages.com/badges/schlessera-markdown-escape/health.svg)](https://phpackages.com/packages/schlessera-markdown-escape)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41478.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

87117.5M63](/packages/bjeavons-zxcvbn-php)[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[paragonie/hidden-string

Encapsulate strings in an object to hide them from stack traces

7410.6M39](/packages/paragonie-hidden-string)

PHPackages © 2026

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