jbzoo/markdown

Tools to render markdown text from PHP code

7.0.1 2024-01-28 12:43 UTC

This package is auto-updated.

Last update: 2024-11-28 14:33:47 UTC


README

CI Coverage Status Psalm Coverage Psalm Level CodeFactor
Stable Version Total Downloads Dependents GitHub License

Installing

composer require jbzoo/markdown

Usage

Rendering Table

<?php declare(strict_types=1);

use JBZoo\Markdown\Table;

echo (new Table())
    ->addAutoIndex('Index', 999)
    ->setHeaders(['Header #1', 'Header #2'])
    ->setAlignments([Table::ALIGN_CENTER, Table::ALIGN_RIGHT])
    ->appendRow(['123', '456'])
    ->appendRows([
        ['789_1', '9871'],
        ['789_2', '']
    ])
    ->render();

Result

| Index | Header #1 | Header #2 |
|------:|:---------:|----------:|
|   999 |    123    |       456 |
|  1000 |   789_1   |      9871 |
|  1001 |   789_2   |           |
See Live Example

Rendering other tags

<?php declare(strict_types=1);

use JBZoo\Markdown\Markdown;

// Page Navigation
Markdown::title('Page Name', 1));   // # Page Name\n
Markdown::title('Title', 2));       // ## Title\n
Markdown::title('Sub Title', 3));   // ### Sub Title\n

// [Google](https://google.com)
Markdown::url('Google', 'https://google.com');

// [![Status](https://travis-ci.org/)](https://travis-ci.org/Status)
Markdown::badge('Status', 'https://travis-ci.org/', 'https://travis-ci.org/Status');

// ![Logo](https://google.com/example.jpg)
Markdown::image('https://google.com/example.jpg', 'Logo');

// > Quote LIne 1
// > Quote LIne 2
// > Quote LIne 3
Markdown::blockquote(["Quote LIne 1\nQuote LIne 2\nQuote LIne 3"]);
Markdown::blockquote(['Quote LIne 1', 'Quote LIne 2', 'Quote LIne 3'])

// <details>
//   <summary>Quote Text</summary>
//   
//   Some hidden text
//   
// </details>
Markdown::spoiler('Quote Text', 'Some hidden text');

// ```php
// <?php
// echo 1;
// 
// ```
Markdown::code("<?php\necho 1;\n", 'php');

Unit tests and check code style

make update
make test-all

License

MIT