Skip to content

Markdown

Viames Marino edited this page Oct 19, 2026 · 2 revisions

Pair framework: Markdown

Pair\Helpers\Markdown is a lightweight Markdown-to-HTML converter.

It supports a focused subset for fast rendering and safe output.

Main method

Markdown::toHtml(string $markdown): string

Converts markdown text into HTML.

Supported features include:

  • headings
  • emphasis/strong
  • links/images with URL sanitization
  • inline/code blocks
  • lists
  • tables
  • basic block structures

Safety behavior

  • HTML-sensitive characters are escaped
  • relative URLs and fragments are accepted; explicit schemes are limited to http, https, mailto, and tel
  • dangerous schemes (e.g. javascript:) are rejected
  • fragment links are resolved against the current router URL, so they require an initialized application/router
  • this is a focused Markdown subset, not a complete CommonMark implementation

Implementation example

use Pair\Helpers\Markdown;

$md = "# Title\n\nVisit [Pair](https://example.com).";
$html = Markdown::toHtml($md);

Render table markdown:

$md = "| Name | Value |\n|:-----|------:|\n| A | 10 |";
$html = Markdown::toHtml($md);

See also: TemplateRenderer, Utilities, View.

Clone this wiki locally