donatj/mddom

一个简单的Markdown DOM

v0.2.0 2023-10-03 05:14 UTC

README

Latest Stable Version License ci.yml

使用类似于“DOM”的界面生成Markdown的简单易用方法

见:docs/docs.md

需求

  • php: >=7.2

安装

使用以下命令安装最新版本:

composer require 'donatj/mddom'

示例

<?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();

输出

# Hello World!

This text is in a paragraph

This text is in a separate paragraph

## Sub-Header!

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