Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unconvertable content to the result #114

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Converter/ConfluenceConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DOMElement;
use DOMNode;
use DOMXPath;
use Exception;
use HalloWelt\MediaWiki\Lib\Migration\Converter\PandocHTML;
use HalloWelt\MediaWiki\Lib\Migration\DataBuckets;
use HalloWelt\MediaWiki\Lib\Migration\IOutputAwareInterface;
Expand Down Expand Up @@ -167,7 +168,13 @@ protected function doConvert( SplFileInfo $file ): string {
$this->currentPageTitle = 'not_current_revision_' . $pageId;
}

$dom = $this->preprocessFile();
try {
$dom = $this->preprocessFile();
}
catch ( Exception $e ) {
$rawContent = file_get_contents( $this->rawFile->getPathname() );
return "<-- Unconvertable RAW start-->\n$rawContent\n<-- Unconvertable RAW start-->\n[[Category:Unconvertable]]";
}

$xpath = new DOMXPath( $dom );
$xpath->registerNamespace( 'ac', 'some' );
Expand Down Expand Up @@ -325,7 +332,10 @@ private function preprocessFile() {
$dom->formatOutput = true;
$dom->preserveWhiteSpace = true;
$dom->validateOnParse = false;
$dom->loadXML( $source, LIBXML_PARSEHUGE );
$validXML = $dom->loadXML( $source, LIBXML_PARSEHUGE );
if ( $validXML === false ) {
throw new Exception( 'Unconvertable');
}

$preprocessedPathname = str_replace( '.mraw', '.mprep', $this->rawFile->getPathname() );
$dom->saveHTMLFile( $preprocessedPathname );
Expand Down
Loading