davidbadura / markdown-builder
Markdown Builder
Installs: 611 882
Dependents: 4
Suggesters: 0
Security: 0
Stars: 22
Watchers: 4
Forks: 3
Open Issues: 10
Requires
- php: >=7.4
- ext-mbstring: *
Requires (Dev)
- infection/infection: ^0.22.1
- patchlevel/coding-standard: ^1.0.0
- phpstan/phpstan: ^0.12.85
- phpunit/phpunit: ^9.5.4
- symfony/var-dumper: ^5.2.3
- vimeo/psalm: ^4.7.2
- dev-master
- 1.1.1
- 1.1.0
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-renovate/phpstan-phpstan-2.x
- dev-renovate/phpstan-phpstan-1.x
- dev-dependabot/composer/symfony/var-dumper-6.4.4
- dev-dependabot/composer/symfony/process-6.4.14
- dev-renovate/actions-checkout-digest
- dev-renovate/lock-file-maintenance
- dev-renovate/major-symfony
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/infection-infection-0.x
This package is auto-updated.
Last update: 2024-12-17 19:38:38 UTC
README
A simple helper class to create markdown.
Installation
composer require 'davidbadura/markdown-builder'
Usage
$builder = new MarkdownBuilder(); $builder ->h1('Markdown Builder') ->p('A simple helper class to create markdown.') ->h2('Install ' . $builder->inlineBold('this') . ' powerfull library') ->code("composer require 'davidbadura/markdown-builder@dev'", 'bash') ->h2('Todos') ->bulletedList([ 'write tests', (string)$builder ->block() ->numberedList(['A', 'B', 'C']) , 'add more markdown features' ]); echo $builder->getMarkdown();
Markdown Builder
================
A simple helper class to create markdown.
Install **this** powerfull library
----------------------------------
```bash
composer require 'davidbadura/markdown-builder@dev'
```
Todos
-----
* write tests
* 1. A
2. B
3. C
* add more markdown features
API
The markdown builder have two kinds of elements, block and inline elements.
Block elements will be buffered and you can get the markdown if you call the method getMarkdown()
.
All inline Elements are prefixed with inline*
and you get instantly the markdown output.
Block Elements
h1
PHP-Code:
echo (new MarkdownBuilder())->h1('Hello World')->getMarkdown();
Markdown:
Hello World
===========
h2
PHP-Code:
echo (new MarkdownBuilder())->h2('Hello second world')->getMarkdown();
Markdown:
Hello second world
------------------
h3
PHP-Code:
echo (new MarkdownBuilder())->h3('My name is...')->getMarkdown();
Markdown:
### My name is...
p
PHP-Code:
echo (new MarkdownBuilder())->p('paragraph')->getMarkdown();
Markdown:
paragraph
blockquote
PHP-Code:
echo (new MarkdownBuilder())->blockquote("Foo\nBar\nBaz")->getMarkdown();
Markdown:
> Foo > Bar > Baz
bulleted list
PHP-Code:
echo (new MarkdownBuilder())->bulletedList(['Foo', 'Bar', 'Baz'])->getMarkdown();
Markdown:
* Foo * Bar * Baz
numbered list
PHP-Code:
echo (new MarkdownBuilder())->numberedList(['Foo', 'Bar', 'Baz'])->getMarkdown();
Markdown:
1. Foo 2. Bar 3. Baz
hr
PHP-Code:
echo (new MarkdownBuilder())->hr()->getMarkdown();
Markdown:
------------------------
code
PHP-Code:
echo (new MarkdownBuilder())->code('$var = "test";', 'php')->getMarkdown();
Markdown:
```php
$var = "test";
```
table
PHP-Code:
echo (new MarkdownBuilder())->table( ['col0', 'col1'], [ ['row01', 'row01'], ['row10', 'row11'], ], [Alignment::CENTER, Alignment::RIGHT] )->getMarkdown();
Markdown:
|col0|col1| |:-:|-:| |row01|row01|
Inline Blocks
bold
PHP-Code:
echo (new MarkdownBuilder())->inlineBold('Hey!');
Markdown:
**Hey!**
italic
PHP-Code:
echo (new MarkdownBuilder())->inlineItalic('huhu');
Markdown:
*huhu*
code
PHP-Code:
echo (new MarkdownBuilder())->inlineCode('$var = "test";');
Markdown:
`$var = "test";`
link
PHP-Code:
echo (new MarkdownBuilder())->inlineLink('http://google.de', 'Google', 'Title');
Markdown:
[Google](http://google.de "Title")
img
PHP-Code:
echo (new MarkdownBuilder())->inlineImg('cat.jpg', 'Cat', 'Title');
Markdown:
![Cat](cat.jpg "Title")
Advance features
if you need collapse blocks, you can create a new builder instance with his own clean buffer.
this can you do by call block()
.
PHP-Code:
$builder = new MarkdownBuilder(); $builder->blockqoute( (string)$builder ->block() ->h1('Lists') ->bulletedList([ 'Foo', $builder->block()->numberedList(['A', 'B', 'C']), 'Bar' ]) );
Markdown:
> Lists > ===== > > * Foo > * 1. A > 2. B > 3. C > * Bar