phpnomad/markdown

Interfaces related to adapting and working with markdown and HTML

Maintainers

Package info

github.com/phpnomad/markdown

Type:project

pkg:composer/phpnomad/markdown

Statistics

Installs: 1 748

Dependents: 2

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2025-06-06 19:20 UTC

This package is auto-updated.

Last update: 2026-04-10 02:09:57 UTC


README

Latest Version Total Downloads PHP Version License

phpnomad/markdown defines the contracts PHPNomad applications use to convert between markdown and HTML. It ships two interfaces and a small exception hierarchy, with no concrete logic of its own. Like the rest of PHPNomad, it keeps your consumer code pointed at an abstraction so the underlying library stays swappable. The drop-in implementation lives in phpnomad/league-markdown-integration, which bridges these contracts to League CommonMark and league/html-to-markdown.

Installation

composer require phpnomad/markdown

On its own this package provides no conversion logic, so you also need an implementation package bound to the interfaces in your container. phpnomad/league-markdown-integration is the canonical one.

Overview

  • CanConvertMarkdownToHtml declares toHtml(string $markdown): string for turning markdown source into an HTML string, throwing ConvertToHtmlException on failure.
  • CanConvertHtmlToMarkdown declares toMarkdown(string $html): string for the reverse direction, throwing ConvertToMarkdownException on failure.
  • MarkdownException is the base exception that both conversion failures extend, so a single catch block can handle any markdown conversion error in your application.
  • Because both conversion directions are separate interfaces, a binding can implement one, the other, or both. A read-only renderer never has to pull in HTML-to-markdown machinery it will not use.
  • Consumers type-hint against the interfaces rather than any concrete class. Swapping the implementation is a container binding change, not a refactor.

Documentation

Full documentation lives at phpnomad.com.

License

MIT. See LICENSE.