becklyn/mobiledoc

A PHP-based renderer for the mobiledoc format.

Maintainers

👁 becklyn

Package info

github.com/Becklyn/mobiledoc-php

pkg:composer/becklyn/mobiledoc

Statistics

Installs: 3 164

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 0

2.0.2 2022-01-11 08:33 UTC

Requires

  • php: ^7.4 || ^8.0
  • ext-dom: *

Suggests

  • masterminds/html5: To automatically preprocess the given HTML to increase compatibility with the native DOM tools when importing HTML.

Provides

None

Conflicts

None

Replaces

None

BSD-3-Clause 60e05da58b3f4828369f3a243f8e222b3a778927

This package is auto-updated.

Last update: 2026-06-11 18:24:28 UTC


README

A PHP-based renderer for the mobiledoc format.

Rendering Mobiledoc

use Becklyn\Mobiledoc\Extension\ExtensionRegistry;
use Becklyn\Mobiledoc\Renderer\MobiledocRenderer;

$extensions = new ExtensionRegistry();
$renderer = new MobiledocRenderer($extensions);

// returns the rendered document
$document = $renderer->render([
 "version" => "0.3.1",
 // ... rest of the mobiledoc document
]);


// returns the mobiledoc
$document->getMobiledoc();

// returns the HTML
$document->getHtml();
(string) $document:

Registering Extensions

Your extension must extend RichTextExtensionInterface. Cards and Atoms are both handled universally, so there is no separation in the code. You can only have one of extension of any type for a given name.

use Becklyn\Mobiledoc\Extension\ExtensionRegistry;
use Becklyn\Mobiledoc\Extension\RichTextExtensionInterface;


class IframeCard implements RichTextExtensionInterface
{
 /**
 * @inheritDoc
 */
 public function getName () : string
 {
 return "iframe";
 }


 /**
 * @inheritDoc
 */
 public function render (?string $content, array $payload) : string
 {
 return '<iframe src="' . $payload["src"] . '"></iframe>';
 }
}


$extensions = new ExtensionRegistry();
$extensions->registerExtension(new IframeCard());
  • Atoms receive the text content in the $content parameter, cards will always receive null as content.
  • Missing atoms fall back to their content as plain text.
  • Missing cards fall back are not rendered.