markdown

Markdown-to-HTML converter supporting headings, code blocks, lists, links and escaping.

v1.0.0Data formatsbundledimport "markdown";
Overview Installation Documentation Examples

Overview

A clean, zero-dependency Markdown-to-HTML converter for HolyPHP.

bundled — works offline zero dependencies md html

Quick start

import "markdown";

$md = "# Hello HolyPHP\n\nThis is **bold**, *italic*, and `inline code`.\n\n- First item\n- Second item";
$html = markdown_to_html($md);
println($html);

Using MarkdownParser directly for custom configuration:

import "markdown";

$parser = new MarkdownParser(true, true, 65536);
$html = $parser->parse("> Welcome to [HolyPHP](https://holyphp.dev)!");
println($html);

Installation

In a project

Inside a project (a folder with hphp.yaml, see Projects & packages):

hphp install markdown

This adds the library to hphp.yaml, installs it into .hphp/packages/markdown/ and pins the exact version in hphp.lock:

require:
  markdown: "^1.0"

Use it

import "markdown";

markdown is bundled with the compiler, so import "markdown"; also works in a single file without installing anything, and hphp install works offline.

Outside a project

hphp install markdown          # for your user, shared by all scripts
hphp create myapp                 # or start a project, then: hphp install markdown
Packagemarkdown
Version1.0.0 (follows the compiler)
Entry filemarkdown.hphp
Sourcepackages/lib/markdown ↗

Documentation

Features

API Reference

Functions

Class MarkdownParser

Error Handling

Invalid configuration or oversized inputs throw an Exception prefixed with markdown::

try {
    $parser = new MarkdownParser(true, true, 0);
} catch (Exception $e) {
    println($e->getMessage());
}

Examples

01Quick start

Bundled with the compiler — import "markdown"; works offline in any file, or add it to a project with hphp install markdown.

import "markdown";

$md = "# Hello HolyPHP\n\nThis is **bold**, *italic*, and `inline code`.\n\n- First item\n- Second item";
$html = markdown_to_html($md);
println($html);

Using MarkdownParser directly for custom configuration:

import "markdown";

$parser = new MarkdownParser(true, true, 65536);
$html = $parser->parse("> Welcome to [HolyPHP](https://holyphp.dev)!");
println($html);
Try it
hphp install markdown
hphp run main.hphp

Covered by the official test suite in tests/positive/lib_markdown.hphp.