pachico / markdownwriter
此包已被弃用且不再维护。未建议替代包。
Markdown 文本编辑器。
0.1.0-beta
2016-04-29 19:42 UTC
Requires
- php: ~5.3|~7.0
- league/flysystem: 1.0.*
- webmozart/assert: 1.0.2
Requires (Dev)
- codacy/coverage: dev-master
- phpunit/phpunit: 4.*
- squizlabs/php_codesniffer: 2.6.*
This package is auto-updated.
Last update: 2022-01-21 22:15:25 UTC
README
用于编写 markdown 文档的 Php 包。
它是什么:一个 markdown 文本编辑器。 它不是什么:一个 markdown 解析器。
为什么?因为编写它很有趣,因为你可能希望使用来自数据库、csv 文件等的数据以编程方式编写文档、博客条目等。越来越多地,静态站点生成器使用 markdown 作为源,所以我决定尝试一下。
目录
安装
通过 Composer
$ composer require pachico/markdownwriter
用法
标题
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Add Header elements $document ->add(new El\H1('This is a H1 header.')) ->add(new El\H2('This is a H2 header.')) ->add(new El\H3('This is a H3 header.')) ->add(new El\H4('This is a H4 header.')) ->add(new El\H5('This is a H5 header.')) ->add(new El\H6('This is a H6 header.')) ; $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
# This is a H1 header.
## This is a H2 header.
### This is a H3 header.
#### This is a H4 header.
##### This is a H5 header.
###### This is a H6 header.
段落
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Create a first paragraph with elements in its constructor // Direct string and Text objects will be put inline // You can also add instances of Image and Link $paragraph1 = new El\Paragraph( 'First span of text as simple string.', new El\Text('Second span of text as instance of Text.'), new El\Text('Third span of text as decorated instance of Text.', El\Text::BOLD) ); $document->add($paragraph1); // Paragraphs can also be injected with content after being instantiated $paragraph2 = new El\Paragraph(); $paragraph2->addContent('Fourth span of text added to second paragraph.'); $paragraph2->addContent(new El\Text('Fifth span of text added to second paragraph as instance of Text.')); $paragraph2->addContent(new El\Text('Sixth span of text added to second paragraph as decorated instance of Text.')); $document->add($paragraph2); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
First span of text as simple string. Second span of text as instance of Text. **Third span of text as decorated instance of Text.**
Fourth span of text added to second paragraph. Fifth span of text added to second paragraph as instance of Text. Sixth span of text added to second paragraph as decorated instance of Text.
引用
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Create a first blockquote with elements in its constructor // Direct string and Text objects will be put inline // You can also add instances of Image and Link $blockquote1 = new El\Blockquote( 'First span of text as simple string.', new El\Text('Second span of text as instance of Text.'), new El\Text('Third span of text as decorated instance of Text.', El\Text::BOLD) ); $document->add($blockquote1); // Blockquotes can also be injected with content after being instantiated $blockquote2 = new El\Blockquote(); $blockquote2->addContent('Fourth span of text added to second blockquote.'); $blockquote2->addContent(new El\Text('Fifth span of text added to second blockquote as instance of Text.')); $blockquote2->addContent(new El\Text('Sixth span of text added to second blockquote as decorated instance of Text.')); $document->add($blockquote2); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
> First span of text as simple string. Second span of text as instance of Text. **Third span of text as decorated instance of Text.**
> Fourth span of text added to second blockquote. Fifth span of text added to second blockquote as instance of Text. Sixth span of text added to second blockquote as decorated instance of Text.
代码
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; $code1 = new El\Code('var code = "This is Javascript code";', El\Code::JAVASCRIPT); $code2 = new El\Code('This is generic code'); $document->add($code1)->add($code2); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
水平线
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Create diffent types of horizontal rules $hRule1 = new El\HRule(El\HRule::ASTERISK); $hRule2 = new El\HRule(El\HRule::DASH); $hRule3 = new El\HRule(El\HRule::UNDERSCORE); // Add them to the document $document->add($hRule1)->add($hRule2)->add($hRule3); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
***
---
___
图片
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Create an image element $image = new El\Image( 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Markdown-mark.svg/208px-Markdown-mark.svg.png', // path 'https://es.wikipedia.org/wiki/Markdown', // link 'Markdown logo', // alt text 'Markdown logo' // title ); // link, alt text and title are optional parameters // Add it to the document $document->add($image); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
[](https://es.wikipedia.org/wiki/Markdown "Markdown logo")
链接
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Create a link $link = new El\Link('Markdown Writer!', 'https://github.com/pachico/markdownwriter'); // Add it to the document $document->add($link); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
[Markdown Writer!](https://github.com/pachico/markdownwriter)
Lizt (列表)
列表称为 Lizt,因为 "list" 是 Php 的保留字。
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; // Create Document $document = new Document; // Create a list $list = new El\Lizt; $list->addOrderedItem('First item.') ->addOrderedItem('Second item.') ->addOrderedItem('Third item.') ->levelDown() // Go one level down/right ->addUnorderedItem('Some more.') ->addUnorderedItem('Some more again.') ->levelUp() ->addOrderedItem('Fourth item.'); // Add it to the document $document->add($list); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
将输出
1. First item.
2. Second item.
3. Third item.
* Some more.
* Some more again.
4. Fourth item.
输出
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; // Create Document $document = new Document(); //... // To fetch the markdown as a string simply $markdown = $document->toMarkdown(); // To save it somewhere we use the great FlySystem abstraction layer: // Define file system adapter $adapter = new Adapter\Local(__DIR__); // Inject it to the save method and it will be persisted $document->save($adapter, basename(__FILE__, 'php') . 'md'); // Check http://flysystem.thephpleague.com/ to see the adapters list
查看 FlySystem 以获取完整的适配器列表。
示例
<?php require __DIR__ . '/../vendor/autoload.php'; use Pachico\MarkdownWriter\Document; use League\Flysystem\Adapter; use Pachico\MarkdownWriter\Element as El; $document = new Document(); $document->add(new El\H1('This is a simple example')) ->add(new El\Paragraph('And here is something I want to say.', 'And something more.')) ->add(new El\Code('$variable = new Foo\Bar();')) ->add(new El\Paragraph('Time to wrap up.', new El\Text('Something italic', El\Text::ITALIC))); $paragraph = new El\Paragraph; $paragraph->addContent(new El\Text('Some bold text', El\Text::BOLD)); $document->add($paragraph); $document->add(new El\H2('Some subtitle too')); $document->add(new El\HRule(El\HRule::ASTERISK)); $adapter = new Adapter\Local(__DIR__); $document->save($adapter, basename(__FILE__, 'php') . 'md');
此 README 文件已使用此包编写。查看示例文件夹以获取更多详细信息。
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 pachicodev@gmail.com 而不是使用问题跟踪器。
鸣谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。