PHP code example of premier / markdown-builder
1. Go to this page and download the library: Download premier/markdown-builder library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
premier / markdown-builder example snippets
Markdown::builder()
->h1('Markdown Builder')
->p('A helper class to create markdown.')
->h2('Install '.Markdown::bold('this').' powerfull library')
->code('composer markdown features'],
[true, 'Configure CI'],
[false, 'CI readme check'],
])
->getMarkdown();
Markdown::builder()->h1('Hello H1');
Markdown::builder()->h2('Hello H2');
Markdown::builder()->h3('Hello H3');
Markdown::builder()->h4('Hello H4');
Markdown::builder()->h5('Hello H5');
Markdown::builder()->h6('Hello H6');
Markdown::builder()->p('paragraph');
Markdown::builder()->blockquote("Foo\nBar\nBaz");
Markdown::builder()->hr();
Markdown::builder()->code('$var = "test";', 'php');
$var = "test";
Markdown::builder()->badge(
'Latest Stable Version',
'https://poser.pugx.org/premier/markdown-builder/v',
'//packagist.org/packages/premier/markdown-builder',
);
Markdown::builder()->bulletedList(['Foo', 'Bar', 'Baz']);
Markdown::builder()->bulletedList(static function (BulletedListBuilder $builder): void {
$builder
->addLine('Hallo')
->addLine('foo')
->addLine('bar');
});
Markdown::builder()->bulletedList(static function (BulletedListBuilder $builder): void {
$builder
->addLine('C')
->addLine('A')
->addLine('B')
->addLine('D')
->sort(fn (string $left, string $right) => $left <=> $right);
});
Markdown::builder()->numberedList(['Foo', 'Bar', 'Baz']);
Markdown::builder()->numberedList(static function (NumberedListBuilder $builder) {
$builder
->addLine('Hallo')
->addLine('foo')
->addLine('bar');
});
Markdown::builder()->numberedList(static function (NumberedListBuilder $builder) {
$builder
->addLine('A')
->addLine('D')
->addLine('B')
->addLine('C')
->sort(fn (string $left, string $right) => $left <=> $right);
});
Markdown::builder()->checklist([
[false, 'Hallo'],
[false, 'foo'],
[true, 'bar'],
]);
Markdown::builder()->checklist(static function (ChecklistBuilder $builder): void {
$builder
->addLine(false, 'Hallo')
->addLine(false, 'foo')
->addLine(true, 'bar');
});
Markdown::builder()->checklist(static function (ChecklistBuilder $builder): void {
$builder
->addLine(false, 'C')
->addLine(false, 'D')
->addLine(true, 'B')
->addLine(true, 'A')
->sort(fn (array $left, array $right) => $left[1] <=> $right[1]);
});
Markdown::builder()->table(
['First Header', 'Second Header'],
[
['Content from cell 1', 'Content from cell 2'],
['Content in the first column', 'Content in the second column'],
]
);
Markdown::builder()->table(
['First Header', 'Second Header'],
static function (TableBuilder $builder): void {
$builder
->addRow('Content from cell 1', 'Content from cell 2')
->addRow('Content in the first column', 'Content in the second column');
},
);
Markdown::builder()->table(
['First Header', 'Second Header'],
static function (TableBuilder $builder): void {
$builder
->addRow('C', 'Content from cell C')
->addRow('A', 'Content from cell A')
->addRow('B', 'Content from cell B')
->sort(fn (array $left, array $right) => $left[0] <=> $right[0]);
},
);
Markdown::builder()->table(
['First Header', 'Second Header'],
static function (TableBuilder $builder): void {
$builder
->addRow('A', Markdown::listAsHtml(Markdown::checklist([
[true, 'A'],
[false, 'B'],
[false, 'C'],
])))
->addRow('B', Markdown::listAsHtml(Markdown::checklist([
[true, 'D'],
[false, 'E'],
[false, 'F'],
])));
},
);
Markdown::bold('Hey!');
Markdown::italic('huhu');
Markdown::code('$var = "test";');
Markdown::link('https://google.com', 'Google');
Markdown::img('cat.jpg', 'Cat');
Markdown::badge(
'Latest Stable Version',
'https://poser.pugx.org/premier/markdown-builder/v',
'//packagist.org/packages/premier/markdown-builder',
);
Markdown::numberedList(['A', 'B', 'C']);
Markdown::bulletedList(['A', 'B', 'C']);
Markdown::checklist([
[true, 'A'],
[true, 'B'],
[false, 'C'],
]);
Markdown::builder()
->blockquote(
Markdown::builder()
->h1('Lists')
->bulletedList([
'Foo',
Markdown::numberedList(['A', 'B', 'C']),
'Bar'
])->getMarkdown()
)
->getMarkdown();
Markdown::builder()
->p('Callback Example')
->callback(static function (Builder $builder) {
foreach ([1, 2, 3] as $item) {
$builder
->p($item.' paragraph.')
->hr();
}
})
->getMarkdown();
Markdown::builder()->h1('Hello world!')->dump('index.md');
markdown
> Lists
> =====
>
> * Foo
> * 1. A
> 2. B
> 3. C
> * Bar