PHPackages                             woutersioen/sir-trevor-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. woutersioen/sir-trevor-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

woutersioen/sir-trevor-php
==========================

A Sir Trevor to HTML conversion helper for PHP

2.0.0(10y ago)2834.6k↑33.3%9[1 issues](https://github.com/WouterSioen/sir-trevor-php/issues)[1 PRs](https://github.com/WouterSioen/sir-trevor-php/pulls)MITPHPPHP &gt;=5.3

Since Mar 11Pushed 8y ago5 watchersCompare

[ Source](https://github.com/WouterSioen/sir-trevor-php)[ Packagist](https://packagist.org/packages/woutersioen/sir-trevor-php)[ Docs](https://github.com/woutersioen/sir-trevor-php)[ RSS](/packages/woutersioen-sir-trevor-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

A Sir Trevor JSON to HTML Converter
===================================

[](#a-sir-trevor-json-to-html-converter)

[![Build Status](https://camo.githubusercontent.com/0a46e2856f88e3d5ef6f835d1c495fbeda3f80c76fccb9b0d6a4074995bebc55/68747470733a2f2f7472617669732d63692e6f72672f576f7574657253696f656e2f7369722d747265766f722d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/WouterSioen/sir-trevor-php) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/216e3086caac8491d3a882313bc7824d4e692a38245308bd8590f4879ecf407e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f576f7574657253696f656e2f7369722d747265766f722d7068702f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/WouterSioen/sir-trevor-php/?branch=master) [![SensioLabsInsight](https://camo.githubusercontent.com/8c161eeb549c900f5302129c487e79bdb1f45bb02205988b0c43b82dcf11818f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f66373836353863632d303666322d343562302d383730342d3638616161303938346433382f6d696e692e706e67)](https://insight.sensiolabs.com/projects/f78658cc-06f2-45b0-8704-68aaa0984d38)

Introduction
------------

[](#introduction)

This is a Conversion library that handles the input from [Sir Trevor](http://madebymany.github.io/sir-trevor-js/)and converts it to HTML. In the future, the conversion from HTML to the Json input Sir Trevor needs will be implemented too.

### Supported Sir Trevor blocks

[](#supported-sir-trevor-blocks)

- Heading
- Paragraph
- List
- Video
- Quote
- Image

It's easy to add a custom block. Just add a new ConversionType in the Sioen\\Types namespace and register it in the ToJsonContect and the ToHtmlContect.

Requirement
-----------

[](#requirement)

This library package requires PHP 5.3 or later.

Installation
------------

[](#installation)

Require the library in your composer.json:

run `composer require woutersioen/sir-trevor-php`.

Make sure you have `require 'vendor/autoload.php';` in the top of your script. If you're using a Framework, this should be ok by default.

Usage
-----

[](#usage)

### Overal

[](#overal)

```
// add the composer autoloader to your file
require_once 'vendor/autoload.php';

// Add the needed use statements to be able to use this library
use Sioen\HtmlToJson;
use Sioen\JsonToHtml;

```

### Conversion to HTML

[](#conversion-to-html)

```
// fetch the data from the post
$sirTrevorInput = $_POST['textarea'];

// create a JsonToHtml object
$jsonToHtml = new JsonToHtml();

// add the wanted converters (you'll probably want to use your DIC container or a factory)
$jsonToHtml->addConverter(new Sioen\JsonToHtml\BlockquoteConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\HeadingConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\IframeConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\ImageConverter());
$jsonToHtml->addConverter(new Sioen\JsonToHtml\BaseConverter());

// generate your html
$html = $jsonToHtml->toHtml($sirTrevorInput);

```

### Conversion to Json

[](#conversion-to-json)

```
// fetch html from database or wherever you want to fetch it from
$html = 'This is my html';

// create a HtmlToJson object
$htmlToJson = new HtmlToJson();

// add the wanted converters (you'll probably want to use your DIC container or a factory)
$jsonToHtml->addConverter(new Sioen\HtmlToJson\BlockquoteConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\HeadingConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\ImageConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\IframeConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\ListConverter());
$jsonToHtml->addConverter(new Sioen\HtmlToJson\BaseConverter());

// generate your json
$json = $htmlToJson->toJson($html);

```

### Adding your own converters.

[](#adding-your-own-converters)

Create a class that implements/extends the right abstraction

HtmlToJson converters should extend `Sioen\HtmlToJson\Converter`JsonToHtml converters should implement `Sioen\JsonToHtml\Converter`

You can add your own converts using the `addConverter` method.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 96.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~391 days

Total

2

Last Release

3689d ago

Major Versions

v1.0 → 2.0.02016-04-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/47020dbad12c7484fcbf5d489573b7d67a3a9f479d7b3f47b314e8bf4372aab5?d=identicon)[WouterSioen](/maintainers/WouterSioen)

---

Top Contributors

[![WouterSioen](https://avatars.githubusercontent.com/u/1398405?v=4)](https://github.com/WouterSioen "WouterSioen (81 commits)")[![Andreyco](https://avatars.githubusercontent.com/u/829963?v=4)](https://github.com/Andreyco "Andreyco (2 commits)")[![ankr](https://avatars.githubusercontent.com/u/1147674?v=4)](https://github.com/ankr "ankr (1 commits)")

---

Tags

htmlSIRSir Trevorsir trevor jsTrevor

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/woutersioen-sir-trevor-php/health.svg)

```
[![Health](https://phpackages.com/badges/woutersioen-sir-trevor-php/health.svg)](https://phpackages.com/packages/woutersioen-sir-trevor-php)
```

###  Alternatives

[spatie/laravel-html

A fluent html builder

8376.4M72](/packages/spatie-laravel-html)[ckeditor/ckeditor

JavaScript WYSIWYG web text editor.

5234.2M76](/packages/ckeditor-ckeditor)[caxy/php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML.

21520.9M15](/packages/caxy-php-htmldiff)[yajra/laravel-datatables-html

Laravel DataTables HTML builder plugin

2899.6M48](/packages/yajra-laravel-datatables-html)[wa72/htmlpagedom

jQuery-inspired DOM manipulation extension for Symfony's Crawler

3383.9M34](/packages/wa72-htmlpagedom)[tinymce/tinymce

Web based JavaScript HTML WYSIWYG editor control.

1697.5M106](/packages/tinymce-tinymce)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
