Skip to content

Commit 01627bf

Browse files
committed
further improve errorhandling
add more output to help solving the problem
1 parent 085539d commit 01627bf

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Diff for: vendor/erusev/parsedown-extra/ParsedownExtra.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -628,20 +628,28 @@ protected function processTag($elementMarkup) # recursive
628628
$elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');
629629

630630
# http://stackoverflow.com/q/4879946/200145
631-
$DOMDocument->loadHTML($elementMarkup, LIBXML_DTDATTR | LIBXML_NONET);
631+
$success = $DOMDocument->loadHTML($elementMarkup);
632+
$DOMDocument->removeChild($DOMDocument->doctype);
632633

633634
$errors = libxml_get_errors();
634635
if ($errors)
635636
{
636-
$errormessage = "<h1>htmlparser error:</h1><br>";
637+
$errormessage = "<h1>HTML-parser error:</h1><br>";
637638
foreach ($errors as $error) {
638-
$errormessage .= $error->message;
639+
$errormessage .= "Line: " . $error->line . " - " . $error->message;
639640
$errormessage .= '<br>';
640641
}
641642
return $errormessage;
642643
}
643644

644-
$DOMDocument->removeChild($DOMDocument->doctype);
645+
if (!isset($DOMDocument->firstChild->firstChild->firstChild))
646+
{
647+
$errormessage = "<h1>General HTML-parser error:</h1><br>";
648+
$errormessage .= "Input:<pre><code>" . htmlspecialchars($elementMarkup) . "</code></pre>";
649+
$errormessage .= "Output:<pre><code>" . htmlspecialchars($DOMDocument->saveHTML()) . "</code></pre>";
650+
return $errormessage;
651+
}
652+
645653
$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
646654

647655
$elementText = '';

Diff for: vendor/erusev/parsedown/Parsedown.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ static function instance($name = 'default')
19771977
protected $regexHtmlAttribute = '[a-zA-Z_:][\w:.-]*+(?:\s*+=\s*+(?:[^"\'=<>`\s]+|"[^"]*+"|\'[^\']*+\'))?+';
19781978

19791979
protected $voidElements = array(
1980-
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source',
1980+
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'frame'
19811981
);
19821982

19831983
protected $textLevelElements = array(

0 commit comments

Comments
 (0)