donatj/mddom

A Simple Markdown DOM

v0.1.0 2019-01-31 00:04 UTC

This package is auto-updated.

Last update: 2020-01-29 17:21:15 UTC


README

Latest Stable Version License Scrutinizer Code Quality Code Coverage Build Status

A Simple Easy To Use Way to Generate Markdown Using a "DOM" Like Interface

See: docs/docs.md

Requirements

  • php: >=5.4
  • ext-dom: *
  • ext-libxml: *

Installing

Install the latest version with:

composer require 'donatj/mddom'

Example

<?php

use donatj\MDDom;

require __DIR__ . '/../vendor/autoload.php';

$doc = new MDDom\Document();

$doc->appendChild(new MDDom\Header("Hello World!"));
$doc->appendChild(new MDDom\Paragraph("This text is in a paragraph"));
$doc->appendChild(new MDDom\Paragraph("This text is in a separate paragraph"));

$sub = new MDDom\DocumentDepth();
$doc->appendChild($sub);

// Header Level, e.g. <h2> is determined by the depth.
$sub->appendChild(new MDDom\Header("Sub-Header!"));
$sub->appendChild(new MDDom\CodeBlock("echo 'Hello World';", 'php'));

echo $doc->exportMarkdown();

Outputs:

# Hello World!

This text is in a paragraph

This text is in a separate paragraph

## Sub-Header!

```php
echo 'Hello World';
```