Update website
This commit is contained in:
parent
0591a4aeb4
commit
7cd3d51e77
43 changed files with 4124 additions and 2 deletions
23
vendor/ueberdosis/pandoc/.github/dependabot.yml
vendored
Normal file
23
vendor/ueberdosis/pandoc/.github/dependabot.yml
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Dependabot creates pull requests to keep your dependencies secure and up-to-date.
|
||||
# Documentation: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
open-pull-requests-limit: 10
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
day: 'monday'
|
||||
reviewers:
|
||||
- 'hanspagel'
|
||||
|
||||
- package-ecosystem: 'composer'
|
||||
directory: '/'
|
||||
open-pull-requests-limit: 10
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
day: 'monday'
|
||||
reviewers:
|
||||
- 'hanspagel'
|
63
vendor/ueberdosis/pandoc/.github/workflows/main.yml
vendored
Normal file
63
vendor/ueberdosis/pandoc/.github/workflows/main.yml
vendored
Normal file
|
@ -0,0 +1,63 @@
|
|||
name: run-tests
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
php: [7.4, 8.0]
|
||||
dependency-version: [prefer-stable]
|
||||
|
||||
env:
|
||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, bcmath, soap, intl, iconv
|
||||
|
||||
name: P${{ matrix.php }} - ${{ matrix.dependency-version }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Cache dependencies
|
||||
uses: actions/cache@v3.0.1
|
||||
with:
|
||||
path: ~/.composer/cache/files
|
||||
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
|
||||
|
||||
- name: Setup PHP extensions
|
||||
id: cache-env
|
||||
uses: shivammathur/cache-extensions@v1
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: ${{ env.extensions }}
|
||||
key: php-extensions-cache-v1
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@2.18.0
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: ${{ env.extensions }}
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
|
||||
|
||||
- name: Install Pandoc
|
||||
run: |
|
||||
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
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/phpunit
|
31
vendor/ueberdosis/pandoc/.php_cs
vendored
Normal file
31
vendor/ueberdosis/pandoc/.php_cs
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
$finder = Symfony\Component\Finder\Finder::create()
|
||||
->notPath('vendor')
|
||||
->notPath('bootstrap')
|
||||
->notPath('storage')
|
||||
->in(__DIR__)
|
||||
->name('*.php')
|
||||
->notName('*.blade.php')
|
||||
->notName('_ide_helper.php');
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setUsingCache(false)
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'array_indentation' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'blank_line_after_opening_tag' => true,
|
||||
'cast_spaces' => true,
|
||||
'concat_space' => ['spacing' => 'none'],
|
||||
'elseif' => true,
|
||||
'no_blank_lines_after_class_opening' => true,
|
||||
'no_closing_tag' => true,
|
||||
'no_leading_import_slash' => true,
|
||||
'no_trailing_whitespace' => true,
|
||||
'no_unused_imports' => true,
|
||||
'no_useless_else' => true,
|
||||
'ordered_imports' => ['sortAlgorithm' => 'length'],
|
||||
'trailing_comma_in_multiline_array' => true,
|
||||
])
|
||||
->setFinder($finder);
|
4
vendor/ueberdosis/pandoc/.styleci.yml
vendored
Normal file
4
vendor/ueberdosis/pandoc/.styleci.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
preset: laravel
|
||||
|
||||
disabled:
|
||||
- single_class_element_per_statement
|
47
vendor/ueberdosis/pandoc/CHANGELOG.md
vendored
Normal file
47
vendor/ueberdosis/pandoc/CHANGELOG.md
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Changelog
|
||||
|
||||
All notable changes to `pandoc` will be documented in this file
|
||||
|
||||
## 0.5.0 - 2020-03-20
|
||||
|
||||
- add symfony/process executable finder
|
||||
|
||||
## 0.4.0 - 2020-03-20
|
||||
|
||||
- add magic from method (e. g. ->fromMarkdown()))
|
||||
- add magic to method (e. g. ->toHtml()))
|
||||
- add BadMethodCall exception
|
||||
|
||||
## 0.3.0 - 2020-03-19
|
||||
|
||||
- add LogFileNotWriteable exception
|
||||
- add InputFileNotFound exception
|
||||
|
||||
## 0.2.1 - 2020-03-19
|
||||
|
||||
- add support for --data-dir (custom templates)
|
||||
|
||||
## 0.2.0 - 2020-03-18
|
||||
|
||||
- changed namespace
|
||||
|
||||
## 0.1.2 - 2020-03-18
|
||||
|
||||
- add PandocNotFound exception
|
||||
- add UnknownInputFormat exception
|
||||
- add UnknownOutputFormat exception
|
||||
|
||||
## 0.1.1 - 2020-03-18
|
||||
|
||||
- compatibility with symfony/process 4.*
|
||||
|
||||
## 0.1.0 - 2020-03-18
|
||||
|
||||
- initial release
|
||||
- return the converted text
|
||||
- use a file as input and write a file as output
|
||||
- change path to Pandoc
|
||||
- list available input formats
|
||||
- list available output formats
|
||||
- write a log file
|
||||
- retrieve Pandoc version
|
55
vendor/ueberdosis/pandoc/CONTRIBUTING.md
vendored
Normal file
55
vendor/ueberdosis/pandoc/CONTRIBUTING.md
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
# Contributing
|
||||
|
||||
Contributions are **welcome** and will be fully **credited**.
|
||||
|
||||
Please read and understand the contribution guide before creating an issue or pull request.
|
||||
|
||||
## Etiquette
|
||||
|
||||
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
|
||||
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
|
||||
extremely unfair for them to suffer abuse or anger for their hard work.
|
||||
|
||||
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
|
||||
world that developers are civilized and selfless people.
|
||||
|
||||
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
|
||||
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
|
||||
|
||||
## Viability
|
||||
|
||||
When requesting or submitting new features, first consider whether it might be useful to others. Open
|
||||
source projects are used by many developers, who may have entirely different needs to your own. Think about
|
||||
whether or not your feature is likely to be used by other users of the project.
|
||||
|
||||
## Procedure
|
||||
|
||||
Before filing an issue:
|
||||
|
||||
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
|
||||
- Check to make sure your feature suggestion isn't already present within the project.
|
||||
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
|
||||
- Check the pull requests tab to ensure that the feature isn't already in progress.
|
||||
|
||||
Before submitting a pull request:
|
||||
|
||||
- Check the codebase to ensure that your feature doesn't already exist.
|
||||
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
|
||||
|
||||
## Requirements
|
||||
|
||||
If the project maintainer has any additional requirements, you will find them listed here.
|
||||
|
||||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer).
|
||||
|
||||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
|
||||
|
||||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
|
||||
|
||||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an option.
|
||||
|
||||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
|
||||
|
||||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
|
||||
|
||||
**Happy coding**!
|
21
vendor/ueberdosis/pandoc/LICENSE.md
vendored
Normal file
21
vendor/ueberdosis/pandoc/LICENSE.md
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Hans Pagel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
144
vendor/ueberdosis/pandoc/README.md
vendored
Normal file
144
vendor/ueberdosis/pandoc/README.md
vendored
Normal file
|
@ -0,0 +1,144 @@
|
|||
# Pandoc PHP Package
|
||||
[](https://packagist.org/packages/ueberdosis/pandoc)
|
||||
[](https://github.com/ueberdosis/pandoc/actions)
|
||||
[](https://packagist.org/packages/ueberdosis/pandoc)
|
||||
[](https://github.com/sponsors/ueberdosis)
|
||||
|
||||
If you need to convert text files from one format to another, [pandoc](https://pandoc.org/) is your swiss-army knife. This package is a PHP wrapper for pandoc.
|
||||
|
||||
## Installation
|
||||
You can install the package via composer:
|
||||
|
||||
```bash
|
||||
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:
|
||||
|
||||
```bash
|
||||
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](https://pandoc.org/installing.html)
|
||||
|
||||
## Usage
|
||||
|
||||
### Return the converted text as string
|
||||
```php
|
||||
$output = (new \Pandoc\Pandoc)
|
||||
->from('markdown')
|
||||
->input('# Test')
|
||||
->to('html')
|
||||
->run();
|
||||
```
|
||||
|
||||
### Use a file as input and write a file as output
|
||||
```php
|
||||
(new \Pandoc\Pandoc)
|
||||
->from('markdown')
|
||||
->inputFile('tests/data/example.md')
|
||||
->to('plain')
|
||||
->output('tests/temp/example.txt')
|
||||
->run();
|
||||
```
|
||||
|
||||
### Change path to Pandoc
|
||||
```php
|
||||
new \Pandoc\Pandoc([
|
||||
'command' => '/usr/local/bin/pandoc',
|
||||
]);
|
||||
```
|
||||
|
||||
### Change working directory
|
||||
```php
|
||||
(new \Pandoc\Pandoc)->cwd('/tmp/pandoc/');
|
||||
```
|
||||
|
||||
### List available input formats
|
||||
```php
|
||||
(new \Pandoc\Pandoc)->listInputFormats();
|
||||
```
|
||||
|
||||
### List available output formats
|
||||
```php
|
||||
(new \Pandoc\Pandoc)->listOutputFormats();
|
||||
```
|
||||
|
||||
### Write a log file
|
||||
```php
|
||||
echo (new \Pandoc\Pandoc)
|
||||
->from('markdown')
|
||||
->input('# Markdown')
|
||||
->to('html')
|
||||
->log('log.txt')
|
||||
->run();
|
||||
```
|
||||
|
||||
### Retrieve Pandoc version
|
||||
```php
|
||||
echo (new \Pandoc\Pandoc)->version();
|
||||
```
|
||||
|
||||
### Use magic methods to make calls shorter
|
||||
```php
|
||||
$output = (new \Pandoc\Pandoc)
|
||||
->fromMarkdown('# Test')
|
||||
->toHtml('tests/temp/example.txt')
|
||||
->run();
|
||||
```
|
||||
|
||||
### Pass options to Pandoc
|
||||
```php
|
||||
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.
|
||||
|
||||
```php
|
||||
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
|
||||
``` bash
|
||||
composer test
|
||||
```
|
||||
|
||||
### Changelog
|
||||
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
|
||||
|
||||
## Contributing
|
||||
|
||||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
|
||||
|
||||
## Credits
|
||||
|
||||
- [Hans Pagel](https://github.com/hanspagel)
|
||||
- [Miguel Piedrafita](https://github.com/m1guelpf)
|
||||
- [All Contributors](../../contributors)
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
|
49
vendor/ueberdosis/pandoc/composer.json
vendored
Normal file
49
vendor/ueberdosis/pandoc/composer.json
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
{
|
||||
"name": "ueberdosis/pandoc",
|
||||
"description": "Pandoc PHP Package",
|
||||
"keywords": [
|
||||
"ueberdosis",
|
||||
"pandoc"
|
||||
],
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/ueberdosis/"
|
||||
}
|
||||
],
|
||||
"homepage": "https://github.com/ueberdosis/pandoc",
|
||||
"license": "MIT",
|
||||
"type": "library",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Hans Pagel",
|
||||
"email": "hans.pagel@ueber.io",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.1|^8.0",
|
||||
"symfony/process": ">4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.0 || ^9.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Pandoc\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Pandoc\\Tests\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit",
|
||||
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
|
||||
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
9
vendor/ueberdosis/pandoc/src/Exceptions/BadMethodCall.php
vendored
Normal file
9
vendor/ueberdosis/pandoc/src/Exceptions/BadMethodCall.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class BadMethodCall extends Exception
|
||||
{
|
||||
}
|
9
vendor/ueberdosis/pandoc/src/Exceptions/InputFileNotFound.php
vendored
Normal file
9
vendor/ueberdosis/pandoc/src/Exceptions/InputFileNotFound.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InputFileNotFound extends Exception
|
||||
{
|
||||
}
|
9
vendor/ueberdosis/pandoc/src/Exceptions/LogFileNotWriteable.php
vendored
Normal file
9
vendor/ueberdosis/pandoc/src/Exceptions/LogFileNotWriteable.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class LogFileNotWriteable extends Exception
|
||||
{
|
||||
}
|
9
vendor/ueberdosis/pandoc/src/Exceptions/PandocNotFound.php
vendored
Normal file
9
vendor/ueberdosis/pandoc/src/Exceptions/PandocNotFound.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class PandocNotFound extends Exception
|
||||
{
|
||||
}
|
9
vendor/ueberdosis/pandoc/src/Exceptions/UnknownInputFormat.php
vendored
Normal file
9
vendor/ueberdosis/pandoc/src/Exceptions/UnknownInputFormat.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UnknownInputFormat extends Exception
|
||||
{
|
||||
}
|
9
vendor/ueberdosis/pandoc/src/Exceptions/UnknownOutputFormat.php
vendored
Normal file
9
vendor/ueberdosis/pandoc/src/Exceptions/UnknownOutputFormat.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class UnknownOutputFormat extends Exception
|
||||
{
|
||||
}
|
13
vendor/ueberdosis/pandoc/src/Facades/Pandoc.php
vendored
Normal file
13
vendor/ueberdosis/pandoc/src/Facades/Pandoc.php
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class Pandoc extends Facade
|
||||
{
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return \Pandoc\Pandoc::class;
|
||||
}
|
||||
}
|
304
vendor/ueberdosis/pandoc/src/Pandoc.php
vendored
Normal file
304
vendor/ueberdosis/pandoc/src/Pandoc.php
vendored
Normal file
|
@ -0,0 +1,304 @@
|
|||
<?php
|
||||
|
||||
namespace Pandoc;
|
||||
|
||||
use Exception;
|
||||
use Pandoc\Exceptions\BadMethodCall;
|
||||
use Pandoc\Exceptions\PandocNotFound;
|
||||
use Symfony\Component\Process\Process;
|
||||
use Pandoc\Exceptions\InputFileNotFound;
|
||||
use Pandoc\Exceptions\UnknownInputFormat;
|
||||
use Pandoc\Exceptions\LogFileNotWriteable;
|
||||
use Pandoc\Exceptions\UnknownOutputFormat;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
class Pandoc
|
||||
{
|
||||
public $config;
|
||||
|
||||
protected $input;
|
||||
|
||||
protected $standalone = true;
|
||||
|
||||
protected $inputFile;
|
||||
|
||||
protected $from;
|
||||
|
||||
protected $to;
|
||||
|
||||
protected $output;
|
||||
|
||||
protected $log;
|
||||
|
||||
protected $dataDir;
|
||||
|
||||
protected $cwd;
|
||||
|
||||
protected $options;
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
$this->config = array_merge([
|
||||
'command' => (new ExecutableFinder)->find('pandoc', 'pandoc'),
|
||||
], $config);
|
||||
|
||||
$this->options = [];
|
||||
}
|
||||
|
||||
public function inputFile($value)
|
||||
{
|
||||
$this->inputFile = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function input($value)
|
||||
{
|
||||
$this->input = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function from($value)
|
||||
{
|
||||
$this->from = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function to($value)
|
||||
{
|
||||
$this->to = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function output($value)
|
||||
{
|
||||
$this->output = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function option($name, $value = false)
|
||||
{
|
||||
$this->options[$name] = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function log($value)
|
||||
{
|
||||
$this->log = $value;
|
||||
$this->option('log', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function dataDir($value)
|
||||
{
|
||||
$this->dataDir = $value;
|
||||
$this->option('data-dir', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function cwd($value)
|
||||
{
|
||||
$this->cwd = $value;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/* Convenience wrappers around option() */
|
||||
public function columns($value)
|
||||
{
|
||||
$this->option('columns', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function tocDepth($value)
|
||||
{
|
||||
$this->option('toc-depth', $value);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function standalone()
|
||||
{
|
||||
$this->option('standalone');
|
||||
$this->standalone = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function noStandalone()
|
||||
{
|
||||
$this->standalone = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(array $parameters = [])
|
||||
{
|
||||
$parameters = array_merge([
|
||||
$this->config['command'],
|
||||
], $parameters);
|
||||
|
||||
if (!empty($this->options)) {
|
||||
foreach ($this->options as $name => $value) {
|
||||
if ($value !== false) {
|
||||
array_push($parameters, "--{$name}", $value);
|
||||
} else {
|
||||
array_push($parameters, "--{$name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$process = new Process($parameters);
|
||||
|
||||
if ($this->cwd) {
|
||||
$process->setWorkingDirectory($this->cwd);
|
||||
}
|
||||
|
||||
if ($this->input) {
|
||||
$process->setInput($this->input);
|
||||
}
|
||||
|
||||
$process->run();
|
||||
|
||||
if (!$process->isSuccessful()) {
|
||||
$output = $process->getErrorOutput();
|
||||
|
||||
if (strpos($output, "pandoc: {$this->inputFile}: openBinaryFile: does not exist") !== false) {
|
||||
throw new InputFileNotFound;
|
||||
}
|
||||
|
||||
if (strpos($output, "pandoc: {$this->log}: openBinaryFile: does not exist") !== false) {
|
||||
throw new LogFileNotWriteable;
|
||||
}
|
||||
|
||||
if (strpos($output, 'Unknown input format') !== false) {
|
||||
throw new UnknownInputFormat;
|
||||
}
|
||||
|
||||
if (strpos($output, 'Unknown output format') !== false) {
|
||||
throw new UnknownOutputFormat;
|
||||
}
|
||||
|
||||
if (strpos($output, 'not found') !== false) {
|
||||
throw new PandocNotFound;
|
||||
}
|
||||
|
||||
throw new ProcessFailedException($process);
|
||||
}
|
||||
|
||||
$output = $process->getOutput();
|
||||
|
||||
if ($output === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function run()
|
||||
{
|
||||
$parameters = [
|
||||
'--sandbox',
|
||||
];
|
||||
|
||||
if ($this->standalone) {
|
||||
array_push($parameters, '--standalone');
|
||||
}
|
||||
|
||||
if ($this->inputFile) {
|
||||
array_push($parameters, $this->inputFile);
|
||||
}
|
||||
|
||||
if ($this->from) {
|
||||
array_push($parameters, '--from', "{$this->from}");
|
||||
}
|
||||
|
||||
if ($this->to) {
|
||||
array_push($parameters, '--to', "{$this->to}");
|
||||
}
|
||||
|
||||
if ($this->output) {
|
||||
array_push($parameters, '--output', "{$this->output}");
|
||||
}
|
||||
|
||||
return $this->execute($parameters);
|
||||
}
|
||||
|
||||
public function version()
|
||||
{
|
||||
$output = $this->execute(['--version']);
|
||||
|
||||
preg_match("~^.*\K\d(?<![a-z\d.].)\d*(?:\.\d+)*+~mi", $output, $matches);
|
||||
list($version) = $matches;
|
||||
|
||||
if (!$version) {
|
||||
throw new Exception('Couldn’t find a pandoc version number in the output.');
|
||||
}
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
public function listInputFormats()
|
||||
{
|
||||
$output = $this->execute(['--list-input-formats']);
|
||||
|
||||
return array_filter(explode("\n", $output));
|
||||
}
|
||||
|
||||
public function listOutputFormats()
|
||||
{
|
||||
$output = $this->execute(['--list-output-formats']);
|
||||
|
||||
return array_filter(explode("\n", $output));
|
||||
}
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$stringsStartsWithFrom = strpos($method, 'from') === 0;
|
||||
$desiredInputFormat = strtolower(
|
||||
array_reverse(explode('from', $method, 2))[0]
|
||||
);
|
||||
$availableInputFormats = $this->listInputFormats();
|
||||
|
||||
if ($stringsStartsWithFrom && in_array($desiredInputFormat, $availableInputFormats)) {
|
||||
$this->from($desiredInputFormat);
|
||||
|
||||
if (! empty($args)) {
|
||||
$this->input(...$args);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$stringStartsWithTo = strpos($method, 'to') === 0;
|
||||
$desiredOutputFormat = strtolower(
|
||||
array_reverse(explode('to', $method, 2))[0]
|
||||
);
|
||||
$availableOutputFormats = $this->listOutputFormats();
|
||||
|
||||
if ($stringStartsWithTo && in_array($desiredOutputFormat, $availableOutputFormats)) {
|
||||
$this->to($desiredOutputFormat);
|
||||
|
||||
if (! empty($args)) {
|
||||
$this->output(...$args);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
throw new BadMethodCall(sprintf(
|
||||
'Call to undefined method %s::%s()',
|
||||
get_class($this),
|
||||
$method
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue