Skip to content

Commit

Permalink
Add tests with alternative pandoc wrapper, fix CS, add PHP 5.6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
renanbr committed Aug 21, 2023
1 parent 2190252 commit 2a90df5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/coding-standards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jobs:
php-version: 7.4
tools: php-cs-fixer:2, cs2pr

- run: mkdir var

- name: Cache PHP Coding Standards
uses: actions/cache@v2
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
include:
- php-version: '8.0'
coverage: true
- php-version: '8.2'
with-ueberdosis-pandoc: true

steps:

Expand All @@ -39,6 +41,12 @@ jobs:
- name: Install Composer dependencies
uses: ramsey/composer-install@v2

- name: Install Pandoc wrapper
if: ${{ matrix.with-ueberdosis-pandoc }}
run: |
composer remove --dev ryakad/pandoc-php
composer require --dev ueberdosis/pandoc
- name: Run PHPUnit
run: vendor/bin/phpunit --testdox ${{ matrix.coverage && '--coverage-clover ./coverage.xml' || '--no-coverage' }}

Expand Down
11 changes: 6 additions & 5 deletions src/Processor/LatexToUnicodeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __invoke(array $entry)
private function decode($text)
{
try {
return $this->getConverter()($text);
return \call_user_func($this->getConverter(), $text);
} catch (Exception $exception) {
throw new ProcessorException(sprintf('Error while processing LaTeX to Unicode: %s', $exception->getMessage()), 0, $exception);
}
Expand All @@ -79,17 +79,18 @@ private function getConverter()
if (InstalledVersions::isInstalled('ueberdosis/pandoc')) {
$pandoc = new Pandoc();

return $this->converter = function ($text) use ($pandoc) {
return substr($pandoc->input($text)->execute([
return $this->converter = static function ($text) use ($pandoc) {
// @phpstan-ignore-next-line
return mb_substr($pandoc->input($text)->execute([
'--from', 'latex',
'--to', 'plain',
'--wrap', 'none',
]), 0, -1);
};
} else if (InstalledVersions::isInstalled('ryakad/pandoc-php')) {
} elseif (InstalledVersions::isInstalled('ryakad/pandoc-php')) {
$pandoc = new Pandoc();

return $this->converter = function ($text) use ($pandoc) {
return $this->converter = static function ($text) use ($pandoc) {
return $pandoc->runWith($text, [
'from' => 'latex',
'to' => 'plain',
Expand Down

0 comments on commit 2a90df5

Please sign in to comment.