https://github.com/becklyn/mobiledoc-php
A PHP-based renderer for the mobiledoc format.
https://github.com/becklyn/mobiledoc-php
Last synced: about 1 month ago
JSON representation
A PHP-based renderer for the mobiledoc format.
- Host: GitHub
- URL: https://github.com/becklyn/mobiledoc-php
- Owner: Becklyn
- License: bsd-3-clause
- Created: 2018-11-12T13:50:58.000Z (about 7 years ago)
- Default Branch: 2.x
- Last Pushed: 2022-01-11T08:33:42.000Z (almost 4 years ago)
- Last Synced: 2025-07-16T05:28:56.447Z (4 months ago)
- Language: PHP
- Size: 109 KB
- Stars: 6
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
Mobiledoc PHP
=============
A PHP-based renderer for the mobiledoc format.
Rendering Mobiledoc
-------------------
```php
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.
```php
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 '';
}
}
$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.