Skip to content

Commit

Permalink
Ignore missing code tag in code block parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
David Bohn authored and nperez0111 committed Aug 12, 2024
1 parent 303877d commit d7d6303
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Nodes/CodeBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public function addAttributes()
return [
'language' => [
'parseHTML' => function ($DOMNode) {
if (!($DOMNode->childNodes[0] instanceof \DOMElement)) {
return null;
}

return preg_replace(
"/^" . $this->options['languageClassPrefix']. "/",
"",
Expand Down
21 changes: 21 additions & 0 deletions tests/DOMParser/Nodes/CodeBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@
],
]);
});

test('it handles code blocks without a code tag', function () {
$html = '<pre>body { display: none }</pre>';

$result = (new Editor)->setContent($html)->getDocument();

expect($result)->toEqual([
'type' => 'doc',
'content' => [
[
'type' => 'codeBlock',
'content' => [
[
'type' => 'text',
'text' => 'body { display: none }',
],
],
],
],
]);
});

0 comments on commit d7d6303

Please sign in to comment.