ueberdosis/pandoc 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

ueberdosis/pandoc

最新稳定版本:0.9.0

Composer 安装命令:

composer require ueberdosis/pandoc

包简介

Pandoc PHP Package

README 文档

README

Integrate Sponsor

If you need to convert text files from one format to another, pandoc is your swiss-army knife. This package is a PHP wrapper for pandoc.

Installation

You can install the package via composer:

composer require ueberdosis/pandoc

This package is a wrapper for the command-line tool pandoc. Don’t forget to install pandoc. Here is an example for Ubuntu:

sudo apt-get update
sudo apt-get install -y wget
sudo mkdir -p /usr/src/pandoc
cd /usr/src/pandoc
sudo wget https://github.com/jgm/pandoc/releases/download/2.15/pandoc-2.15-1-amd64.deb
sudo dpkg -i pandoc-2.15-1-amd64.deb

More examples are available in the pandoc documentation

Usage

Return the converted text as string

$output = (new \Pandoc\Pandoc)
    ->from('markdown')
    ->input('# Test')
    ->to('html')
    ->run();

Use a file as input and write a file as output

(new \Pandoc\Pandoc)
    ->from('markdown')
    ->inputFile('tests/data/example.md')
    ->to('plain')
    ->output('tests/temp/example.txt')
    ->run();

Change path to Pandoc

new \Pandoc\Pandoc([
    'command' => '/usr/local/bin/pandoc',
]);

Change working directory

(new \Pandoc\Pandoc)->cwd('/tmp/pandoc/');

List available input formats

(new \Pandoc\Pandoc)->listInputFormats();

List available output formats

(new \Pandoc\Pandoc)->listOutputFormats();

Write a log file

echo (new \Pandoc\Pandoc)
    ->from('markdown')
    ->input('# Markdown')
    ->to('html')
    ->log('log.txt')
    ->run();

Retrieve Pandoc version

echo (new \Pandoc\Pandoc)->version();

Use magic methods to make calls shorter

$output = (new \Pandoc\Pandoc)
    ->fromMarkdown('# Test')
    ->toHtml('tests/temp/example.txt')
    ->run();

Pass options to Pandoc

echo (new \Pandoc\Pandoc)
    ->fromMarkdown('# Test')
    ->toHtml('tests/temp/example.txt')
    ->option('fail-if-warnings')
    ->option('data-dir', './tmp')
    ->run();

See https://pandoc.org/MANUAL.html for a full list of available options

Laravel Facade

This package includes a Laravel facade for people that like that little bit of syntactic sugar.

echo \Pandoc\Facades\Pandoc::version();

Exceptions

If something went wrong, the package throws a generic \Symfony\Component\Process\Exception\ProcessFailedException. There are even a few specific exceptions.

  • \Pandoc\Exceptions\PandocNotFound
  • \Pandoc\Exceptions\InputFileNotFound
  • \Pandoc\Exceptions\UnknownInputFormat
  • \Pandoc\Exceptions\UnknownOutputFormat
  • \Pandoc\Exceptions\LogFileNotWriteable
  • \Pandoc\Exceptions\BadMethodCall

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 82
  • Watchers: 1
  • Forks: 9
  • 开发语言: PHP

其他信息

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