Skip to content

Commit

Permalink
Add support of infilter
Browse files Browse the repository at this point in the history
  • Loading branch information
dehbka committed Jul 27, 2022
1 parent 0891d4d commit 0d97312
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ public function convert(LowrapperParameters $parameters)

$options = array_merge($this->defaultOptions, [
$documentType ? '--' . $documentType : '',
$parameters->getInputFilter() ? sprintf('--infilter=%s', $parameters->getInputFilter()) : null,
'--convert-to "' . $parameters->getOutputFormat() . $outputFilters . '"',
'"' . $inputFile . '"',
]);
$command = $this->binaryPath . ' ' . implode(' ', $options);
$command = $this->binaryPath . ' ' . implode(' ', array_filter($options));

$process = $this->createProcess($command);

Expand Down
28 changes: 27 additions & 1 deletion src/LowrapperParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ class LowrapperParameters
*/
protected $outputFilters = [];

/**
* Input filters, eg.
* - Text (encoded)
* - UTF8
* @var ?string
*/
protected $inputFilter = null;

public function __construct(
/*string*/ $outputFormat = null,
/*string*/ $outputFile = null,
Expand Down Expand Up @@ -163,6 +171,24 @@ public function getOutputFilters()//: array
return $this->outputFilters;
}

/**
* @param string $outputFilter
* @return LowrapperParameters
*/
public function setInputFilter(/*string*/ $inputFilter)
{
$this->inputFilter = $inputFilter;
return $this;
}

/**
* @return ?string
*/
public function getInputFilter()//: ?string
{
return $this->inputFilter;
}

/**
* @return mixed
*/
Expand All @@ -183,4 +209,4 @@ public function setInputData($inputData)



}
}
11 changes: 10 additions & 1 deletion tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public function converterProvider()
$command .'--web --convert-to "text:some filter" "some_temp_file"',
null,
],
'Input filter' => [
(new LowrapperParameters())
->setInputFile('test.html')
->setOutputFormat(Format::TEXT_TEXT)
->setOutputFile('test.text')
->setInputFilter('some'),
$command .'--web --infilter=some --convert-to "text:Text (encoded):UTF8" "some_temp_file"',
null,
],
'Default text filter' => [
(new LowrapperParameters())
->setInputFile('test.html')
Expand Down Expand Up @@ -124,4 +133,4 @@ public function converterProvider()
];
}

}
}

0 comments on commit 0d97312

Please sign in to comment.