定制 laudis/pandoc 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

laudis/pandoc

Composer 安装命令:

composer require laudis/pandoc

包简介

simple wrapper for easy pandoc handling

README 文档

README

Maintainability Test Coverage MIT License

Installation

Install pandoc on your system.

Install pandoc-php with composer

composer require laudis/pandoc

Quick usage

Pandoc converts text using the convert method.

use Laudis\Pandoc\Pandoc;

$pandoc = new Pandoc();
echo $pandoc->convert('#Hello Pandoc', 'html'); //outputs <h1 id="hello-pandoc">Hello Pandoc</h1>

Pandoc converts files using the convertFile method.

$pandoc->convertFile(__DIR__.'/my-file.txt', 'html', 'text');

Building commands

Pandoc php also handles more complex systems by accepting commands. A builder pattern creates these.

This example builds a command which controls pandoc to convert the markdown to a temporary JSON file.

use Laudis\Pandoc\Commands\Command;
use Laudis\Pandoc\Enums\Option;

$command = Command::create()
    ->withContent('# H1')
    ->withOption(Option::OUTPUT_FILE(), sys_get_temp_dir() . '/tmp.json') // Use the option enumeration for easy ide integration and built in typo protection.
    ->withOption('-w', 'json'); // Strings can also describe an option

$pandoc->run($command);

Streams and resources

Pandoc php supports resources!

use Laudis\Pandoc\Commands\Command;
use Laudis\Pandoc\Enums\Option;

$command = Command::create()
    ->withResource(fopen('https://laudis.tech', 'rb'))
    ->withOption(Option::FROM_FORMAT(), 'html')
    ->withOption(Option::TO_FORMAT(), 'pdf');

echo $pandoc->run($command);

Pandoc also optionally streams the result for a seamless experience.

foreach ($pandoc->stream($command) as $part) {
    echo $part;
}

Configuration

The pandoc constructor accepts the location of the pandoc executable.

$pandoc = new Pandoc(); // Defaults to "pandoc" as the executable,

$pandoc = new Pandoc('/usr/bin/pandoc-beta'); // /usr/bin/pandoc-beta is now the location of the executable,

Version detection

Pandoc is also aware of the version of the executable. The version is accessible through the getVersion method.

$pandoc = new Pandoc();

echo $pandoc->getVersion(); // Echos the version provided in with the --version flag.

统计信息

  • 总下载量: 166
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固