PHPackages                             fastvolt/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. fastvolt/markdown

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

fastvolt/markdown
=================

A Fast, Simple and Straight-forward Markdown to HTML Converter for PHP.

v0.2.5(7mo ago)6189.0k↓26.4%7[3 issues](https://github.com/fastvolt/markdown/issues)[3 PRs](https://github.com/fastvolt/markdown/pulls)4MITPHPPHP ^8.1

Since Nov 8Pushed 6mo agoCompare

[ Source](https://github.com/fastvolt/markdown)[ Packagist](https://packagist.org/packages/fastvolt/markdown)[ RSS](/packages/fastvolt-markdown/feed)WikiDiscussions v0.3.0 Synced 1w ago

READMEChangelog (7)Dependencies (2)Versions (14)Used By (4)

 [ ![Fastvolt](https://github.com/fastvolt/branding/raw/1c5280745d9c671313f319b7f07d6706a9f75ea9/media/images/fast-mrk.png) ](https://github.com/fastvolt/markdown)

Markdown Parser for PHP
=======================

[](#markdown-parser-for-php)

 **A fast, simple, and straightforward Markdown to HTML converter for PHP.**

 [ ![PHP Composer](https://github.com/fastvolt/markdown/actions/workflows/validator1.yml/badge.svg) ](https://github.com/fastvolt/markdown/actions/workflows/validator1.yml) [ ![License: MIT](https://camo.githubusercontent.com/8174925d009b42074d50ab5cc7e29fcb1aa613b0d9cb2e43097697a40cf90fa4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f77) ](#license) [ ![GitHub Issues](https://camo.githubusercontent.com/38984e25ad1181505592d4b053a8d686c5c2937077d91bdf38de9464850720ea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f66617374766f6c742f6d61726b646f776e) ](https://github.com/fastvolt/markdown/issues) [ ![Repo](https://camo.githubusercontent.com/9179a23aa9659f052e41de0e712c9723eced135aa7db1900532b8cec69f03eb3/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6162656c3d66617374766f6c74266d6573736167653d6d61726b646f776e26636f6c6f723d79656c6c6f77266c6f676f3d676974687562) ](https://github.com/fastvolt/markdown) [![Maintained: Yes](https://camo.githubusercontent.com/04e81c725771f630b883f489e5fe5f7f5ae920cd9d65efedf74645c18da4a08d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65642d7965732d626c7565)](https://camo.githubusercontent.com/04e81c725771f630b883f489e5fe5f7f5ae920cd9d65efedf74645c18da4a08d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65642d7965732d626c7565)

🚀 Installation
--------------

[](#-installation)

```
composer require fastvolt/markdown
```

📦 Basic Usage
-------------

[](#-basic-usage)

```
use FastVolt\Helper\Markdown;

$text = "## Hello, World";

// Initialize the parser
$markdown = new Markdown(); // or Markdown::new()

// set markdown content
$markdown->setContent($text);

// compile and get as raw HTML
echo $markdown->getHtml();
```

#### Output:

[](#output)

```
Hello, World
```

📄 Convert Markdown File to Raw HTML
-----------------------------------

[](#-convert-markdown-file-to-raw-html)

> ***sample.md:***

```
#### Heading 4
### Heading 3
## Heading 2
# Heading 1

- List 1
- List 2

> THIS IS A BLOCKQUOTE

[A LINK](https://github.com/fastvolt)
```

> ***index.php:***

```
$markdown = Markdown::new();

// add markdown file to parse
$markdown->addFile(__DIR__ . '/sample.md');

// compile and get as raw html
echo $markdown->getHtml();
```

> ***Output:***

```
Heading 4
Heading 3
Heading 2
Heading 1

  List 1
  List 2

THIS IS A BLOCKQUOTE
A LINK
```

📝 Convert Markdown File to An HTML File
---------------------------------------

[](#-convert-markdown-file-to-an-html-file)

> ***blogPost.md:***

```
Here is a Markdown File Waiting To Be Compiled To an HTML File
```

> ***index.php:***

```
$markdown = Markdown::new()
    // add markdown file
    ->addFile(__DIR__ . '/blogPost.md')

    // add output directory
    ->addOutputDirectory(__DIR__ . '/pages/')

    // compile as an html file
    ->saveToHtmlFile(filename: 'index.html');

if ($markdown) {
  echo "Compiled to ./pages/index.html";
}
```

Convert Directory to HTML Directory Structure
---------------------------------------------

[](#convert-directory-to-html-directory-structure)

This compiles all `.md` files in a source directory into a mirrored structure of `.html` files in an output directory.

```
use FastVolt\Helper\Markdown;
use FastVolt\Helper\Markdown\Enums\MarkdownEnum;

$markdown = Markdown::new()
    // Set the source directory to read all .md files from (including sub-directories)
    ->setSourceDirectory(__DIR__ . '/docs/')

    // Set the output directory to compile the mirrored HTML structure to (Alias: ->setCompileDir())
    ->addOutputDirectory(__DIR__ . '/public/')

    // Run the directory conversion process
    ->run(MarkdownEnum::TO_HTML_DIRECTORY);

if ($markdown) {
    echo "Directory conversion successful!";
}

// If '/docs/guide/*.md' exists, it creates '/public/guide/*.html'.
```

Single Point Execution
----------------------

[](#single-point-execution)

This is the universal executor that can operate in three different modes using the `MarkdownEnum` enum and `run` method.

### Interface

[](#interface)

```
  run(
    MarkdownEnum $as,
    ?string $fileName
  ): mixed;
```

### MarkdownEnum Interface

[](#markdownenum-interface)

```
enum MarkdownEnum
{
  // convert markdown source to raw html (raw/file => raw html)
  case TO_HTML;

  // convert markdown source to an html file (markdown raw/file => html file)
  case TO_HTML_FILE;

  // convert markdown source directory to html directory (markdown directory => html directory)
  case TO_HTML_DIRECTORY;
}
```

### Usage Examples

[](#usage-examples)

#### Using The `MarkdownEnum::TO_HTML` Enum

[](#using-the-markdownenumto_html-enum)

> This is an alternative way to call `getHtml()`.

```
Markdown::new()
    ->setContent('# Heading 1')
    ->run(MarkdownEnum::TO_HTML);
```

#### Using The `MarkdownEnum::TO_HTML_FILE` Enum

[](#using-the-markdownenumto_html_file-enum)

> This is an alternative way to call `saveToHtmlFile()`.

```
Markdown::new()
    ->addOutputDirectory(__DIR__ . '/build')
    ->run(MarkdownEnum::TO_HTML_FILE, 'index.html');
```

#### Using The `MarkdownEnum::TO_HTML_DIRECTORY` Enum

[](#using-the-markdownenumto_html_directory-enum)

> This is the only method that uses `setSourceDirectory()`. It crawls the source directory, converts all .md files, and saves them (preserving the folder structure) to the output directory.

```
Markdown::new()
    ->setSourceDirectory(__DIR__ . '/src/my-docs')
    ->addOutputDirectory(__DIR__ . '/public/docs')
    ->run(MarkdownEnum::TO_HTML_DIRECTORY);
```

🔒 Sanitizing HTML Output (XSS Protection)
-----------------------------------------

[](#-sanitizing-html-output-xss-protection)

You can sanitize input HTML and prevent cross-site scripting (XSS) attack using the `sanitize` flag.

> `$sanitize`: Set to `true` (default) to escape HTML tags in the Markdown. Set to `false` only if you completely trust the source of your Markdown and need raw HTML to be rendered.

```
$markdown = Markdown::new(
  sanitize: true
);

$markdown_unsafe = Markdown::new(
  sanitize: false
);

$content = 'Hello World';

echo $markdown
  ->setContent($content)
  ->getHtml();

echo $markdown_unsafe
  ->setContent($content)
  ->getHtml();
```

> ***Output:***

```
Sanitize Enabled: &lt;h1&gt;Hello World&lt;/h1&gt;

Sanitize Disabled: Hello World
```

⚙️ Advanced Use Case
--------------------

[](#️-advanced-use-case)

### Inline Markdown

[](#inline-markdown)

```
$markdown = Markdown::new();

$markdown->setInlineContent('_My name is **vincent**, the co-author of this blog_');

echo $markdown->getHtml();
```

> ***Output:***

```
My name is vincent, the co-author of this blog
```

> ***NOTE:*** Some markdown symbols are not supported with this method

### Example #1

[](#example-1)

Combine multiple markdown files, contents and compile them in multiple directories:

> ***Header.md***

```
# Blog Title
### Here is the Blog Sub-title
```

> ***Footer.md***

```
### Thanks for Visiting My BlogPage
```

> ***index.php***

```
$markdown = Markdown::new(sanitize: true)
    // include header file's markdown contents
    ->addFile('./Header.md')
    // body contents
    ->setInlineContent('_My name is **vincent**, the co-author of this blog_')
    ->setContent('Kindly follow me on my GitHub page via: [@vincent](https://github.com/oladoyinbov).')
    ->setContent('Here are the lists of my projects:')
    ->setContent('
- Dragon CMS
- Fastvolt Framework.
  + Fastvolt Router
  + Markdown Parser.
    ')
    // include footer file's markdown contents
    ->addFile(__DIR__ . '/Footer.md')
   
    // add the main compilation directory
    ->addOutputDirectory(__DIR__ . '/pages/')
   
    // add another compilation directory to backup the result
    ->addOutputDirectory(__DIR__ . '/backup/pages/')

    // compile and store as 'index.html'
    ->saveToHtmlFile(file_name: 'index.html');

if ($markdown) {
  echo "Compile Successful. Files created in /pages/ and /backup/pages/";
}
```

> ***Output:*** `pages/index.html`, `backup/pages/index.html`

```
Blog Title
Here is the Blog Sub-title
My name is vincent, the co-author of this blog
Kindly follow me on my github page via: @vincent.
Here are the lists of my projects:

  Dragon CMS
  Fastvolt Framework.

      Fastvolt Router
      Markdown Parser.

Thanks for Visiting My BlogPage
```

Error Handling
--------------

[](#error-handling)

The parser uses custom exceptions for clarity:

- `MarkdownFileNotFound`: Thrown when a file specified in `addFile()` or a directory in `setSourceDirectory()` does not exist.
- `LogicException`: Thrown if you try to execute a conversion (`getHtml()` or `saveToHtmlFile()`) before any content (setContent, addFile, etc.) has been added to the queue.
- `RuntimeException`: Thrown if the system fails to create an output directory (mkdir fails) or if a required directory is missing during run() execution.

🧠 Interface Method Reference
----------------------------

[](#-interface-method-reference)

The parser uses a fluent (chainable) API. This is your command cheatsheet for configuration and execution:

Method NameReturn TypeDescription`::new(bool $sanitize = true)``self`**Initialize** the parser instance. The preferred static factory method.`->setSourceDirectory(string $name)``static`Sets the **input root directory** for whole-directory compilation.`->setContent(string $content)``static`Adds **multi-line** Markdown content (supports lists, headings, etc.) to the queue.`->setInlineContent(string $content)``static`Adds **single-line** Markdown content (*bold*, **italic**) to the queue.`->addFile(string $fileName)``static`Adds a single Markdown file path to the compilation queue. *(Alias: `->setFile()`)*`->addMultipleFiles(array $names)``static`Adds an array of Markdown file paths to the compilation queue.`->addOutputDirectory(string $dir)``static`Adds a directory where the compiled HTML will be saved. Allows multiple targets. *(Alias: `->setCompileDir()`)*`->addMultipleOutputDirectories(array $dirs)``static`Adds an array of directories where the compiled HTML will be saved.`->getHtml()``string|null`**Execute** compilation and return the raw HTML string. *(Alias: `->toHtml()`)*`->saveToHtmlFile(string $name)``bool`**Execute** compilation and write the output to the specified HTML file(s). *(Alias: `->toHtmlFile()`)*`->run(MarkdownEnum $as, ?string $file)``mixed`Universal command to execute conversion based on the specified `MarkdownEnum` target.
Supported Formatting Symbols
----------------------------

[](#supported-formatting-symbols)

Markdown SyntaxDescriptionExample SyntaxRendered Output`#` to `######`Headings (H1–H6)`## Heading 2`Heading 2
---------

[](#heading-2)

`**text**` or `__text__`Bold`**bold**`**bold**`*text*` or `_text_`Italic`*italic*`*italic*`~~text~~`Strikethrough`~~strike~~`strike``code``Inline code``echo```echo```code block``Code block````php\n echo "Hi"; \n`````...``-`, `+`, or `*`Unordered list`- Item 1`
`* Item 2``Item``1.` `2.`Ordered list`1. Item`
`2. Item``Item``[text](url)`Hyperlink`[GitHub](https://github.com)`[GitHub](https://github.com)`> blockquote`Blockquote`> This is a quote`> This is a quote

`---`, `***`, `___`Horizontal Rule`---````![alt](image.jpg)`Image`![Logo](logo.png)````\`Escape special character`\*not italic\*`*not italic* (as text)
✅ Requirements
--------------

[](#-requirements)

PHP 8.1 or newer.

ℹ️ Notes
--------

[](#ℹ️-notes)

> This library is an extended and simplified version of the excellent [Parsedown](https://github.com/erusev/parsedown/) by Erusev.

📄 License
---------

[](#-license)

This project is open-source and licensed under the MIT License by @fastvolt.

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance66

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.8% 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 ~69 days

Recently: every ~42 days

Total

12

Last Release

182d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ec082f466748198430847b06e885b7d77eecdfb61395e89ebbf7279637a84003?d=identicon)[oladoyinboadverts](/maintainers/oladoyinboadverts)

---

Top Contributors

[![oladoyinbov](https://avatars.githubusercontent.com/u/73993087?v=4)](https://github.com/oladoyinbov "oladoyinbov (61 commits)")[![Datahider](https://avatars.githubusercontent.com/u/29582937?v=4)](https://github.com/Datahider "Datahider (1 commits)")[![k00ni](https://avatars.githubusercontent.com/u/381727?v=4)](https://github.com/k00ni "k00ni (1 commits)")

---

Tags

markdownmarkdown-convertermarkdown-itmarkdown-parsermarkdown-to-htmlphpphp-markdownphp-markdown-parsermarkdownmarkdown-to-htmlmarkdown-parsermarkdown-library

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[erusev/parsedown

Parser for Markdown.

15.0k155.2M835](/packages/erusev-parsedown)[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

3.0k426.1M927](/packages/league-commonmark)[michelf/php-markdown

PHP Markdown

3.5k53.8M370](/packages/michelf-php-markdown)[league/html-to-markdown

An HTML-to-markdown conversion helper for PHP

1.9k31.0M266](/packages/league-html-to-markdown)[cebe/markdown

A super fast, highly extensible markdown parser for PHP

1.0k33.5M146](/packages/cebe-markdown)

PHPackages © 2026

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