Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jbroadway/slimdown

A simple regex-based Markdown parser in PHP.
https://github.com/jbroadway/slimdown

html markdown parser parsing php regex regexp

Last synced: 1 day ago
JSON representation

A simple regex-based Markdown parser in PHP.

Awesome Lists containing this project

README

        

# Slimdown

![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/jbroadway/slimdown/ci.yml?branch=master)
![GitHub License](https://img.shields.io/github/license/jbroadway/slimdown)
![Packagist Version](https://img.shields.io/packagist/v/jbroadway/slimdown)
![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/jbroadway/slimdown)

A simple regex-based Markdown parser in PHP. Supports the
following elements (and can be extended via `Slimdown::add_rule()`):

* Headers
* Links
* Bold
* Emphasis
* Deletions
* Quotes
* Code blocks
* Inline code
* Blockquotes
* Ordered/unordered lists
* Checklists
* Images

Originally hosted as a [gist here](https://gist.github.com/jbroadway/2836900).

## Usage

Here is the general use case:

```php
\2');

echo Slimdown::render ('Know what I\'m sayin? :)');
```

In this example, we add GitHub-style internal linking
(e.g., `[[Another Page]]`).

```php
%s',
preg_replace ('/[^a-zA-Z0-9_-]+/', '-', $title),
$title
);
}

Slimdown::add_rule ('/\[\[(.*?)\]\]/e', 'mywiki_internal_link (\'\\1\')');

echo Slimdown::render ('Check [[This Page]] out!');
```

### A longer example

```php
A block quote
> across two lines.

- [ ] One
- [x] Two
- [ ] Three

More text...");
```