Comments (2)
Hi,
to solve this issue I have this proposal:
edit pandoc->option:
public function option($name, $value = false)
{
if(key_exists($name, $this->options)){
if(is_array($value)){
$this->options[$name] = array_merge($this->options[$name], $value);
}else{
array_push($this->options[$name], $value);
}
}else{
$this->options[$name] = is_array($value) ? $value : [$value];
}
return $this;
}
and pandoc->execute:
public function execute(array $parameters = [])
{
$parameters = array_merge([
$this->config['command'],
], $parameters);
//new code start here
if (!empty($this->options)) {
foreach ($this->options as $name => $value) {
foreach ($value as $sub_value) {
if($sub_value !== false){
array_push($parameters, "--{$name}", $sub_value);
}else{
array_push($parameters, "--{$name}");
}
}
}
}
//new code ends here
$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;
}
And for the usage:
//preferred way:
(new \Pandoc\Pandoc)
->option('metadata', 'x=y')
->option('metadata', 'a=b')
//optional way:
(new \Pandoc\Pandoc)->option('metadata', [
'x=y',
'a=b'
])
from pandoc.
To make it more compatible with previous implementation another option could be this:
public function option($name, $value = false, $override = true)
{
if($override){
$this->options[$name] = [];
}
if(key_exists($name, $this->options)){
if(is_array($value)){
$this->options[$name] = array_merge($this->options[$name], $value);
}else{
array_push($this->options[$name], $value);
}
}else{
$this->options[$name] = is_array($value) ? $value : [$value];
}
return $this;
}
$override is set to true by default to keep compatiblility to previous version.
Because if a user was setting 2 times toc-depth (for example) the second one was kept and the first ignored.
so usage would be:
//preferred way:
(new \Pandoc\Pandoc)
->option('metadata', 'x=y', true)
->option('metadata', 'a=b', true)
->option('toc-depth', 2) //ignored
->option('toc-depth', 4)
//optional way:
(new \Pandoc\Pandoc)->option('metadata', [
'x=y',
'a=b'
], true)
->option('toc-depth', 2) //ignored
->option('toc-depth', 4)
Note:
I don't know if is a non issue and pandoc himself understand to override previous value.
I'm pretty new to pandoc.
from pandoc.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pandoc.