Skip to content

Commit

Permalink
Add skiperrors option to allow debugging pandoc conversion issues
Browse files Browse the repository at this point in the history
  • Loading branch information
olberger committed Mar 16, 2022
1 parent d3b3af4 commit 5f270a4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
35 changes: 29 additions & 6 deletions app/src/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App;

use Pandoc\Pandoc;
use Pandoc\PandocException;
use App\CleanLink;
use App\PandocFix;

Expand Down Expand Up @@ -44,6 +45,12 @@ class Convert
*/
private $indexes = false;

/**
* Set to true will skip files failing conversion
* @var boolean
*/
private $skiperrors = false;

/**
* Which format to convert files to.
* @var string
Expand Down Expand Up @@ -126,14 +133,28 @@ public function convertData()
{
foreach ($this->dataToConvert as $node) {
$fileMeta = $this->retrieveFileInfo($node->xpath('title'));

$text = $node->xpath('revision/text');
$text = $this->cleanText($text[0], $fileMeta);
$text = $this->runPandoc($text);

$text .= $this->getMetaData($fileMeta);
$this->saveFile($fileMeta, $text);
$this->counter++;
$converted=false;
// handle a bit more details when pandoc fails
try {
$text = $this->runPandoc($text);
$converted=true;
} catch (PandocException $e) {
$this->message("Failed converting " . $fileMeta['title'] . ":" );
if(! $this->skiperrors) {
throw new \Exception($e);
}
else {
print($e->getMessage());
}
}
if($converted)
{
$text .= $this->getMetaData($fileMeta);
$this->saveFile($fileMeta, $text);
$this->counter++;
}
}
}

Expand Down Expand Up @@ -301,6 +322,7 @@ public function setArguments($options)
$this->setOption('flatten', $options);
$this->setOption('indexes', $options);
$this->setOption('addmeta', $options);
$this->setOption('skiperrors', $options);
$this->output = rtrim($this->output, '/') . '/';
}

Expand Down Expand Up @@ -379,6 +401,7 @@ public function help()
directory. File names will be converted in the following way:
Mediawiki_folder/My_File_Name -> Mediawiki_folder_My_File_Name
and saved in a file called 'Mediawiki_folder_My_File_Name.md'
--skiperrors : This flag will not stop on pandoc parsing errors, and just skip file (Default: false).
--version : Displays the program's version
--help : This help message.
Expand Down
1 change: 1 addition & 0 deletions convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'addmeta::',
'flatten::',
'indexes::',
'skiperrors::',
'version::',
'help::'
]
Expand Down

0 comments on commit 5f270a4

Please sign in to comment.