Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Core/DOMParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function processChildren($node): array
continue;
}

if ($child->hasChildNodes()) {
if (!$class::$noContent && $child->hasChildNodes()) {
$item = array_merge($item, [
'content' => $this->processChildren($child),
]);
Expand Down
2 changes: 2 additions & 0 deletions src/Core/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Node extends Extension

public static $topNode = false;

public static $noContent = false;

public static $marks = '_';

public function addAttributes()
Expand Down
34 changes: 34 additions & 0 deletions tests/DOMParser/Nodes/BlockquoteCite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Tiptap\Tests\DOMParser\Nodes;

use Tiptap\Core\Node;

class BlockquoteCite extends Node
{
public static $name = 'blockquoteCite';

public static $noContent = true;

public function addAttributes(): array
{
return [
'quote' => [
'parseHTML' => fn ($domNode) => $domNode->childNodes[0]->childNodes[0]->textContent ?? '',
],
'author' => [
'parseHTML' => fn ($domNode) => $domNode->childNodes[1]->textContent ?? '',
],
];
}

public function parseHTML()
{
return [
[
'tag' => 'blockquote',
'getAttrs' => fn ($domNode) => isset($domNode->childNodes[1]) && $domNode->childNodes[1]->tagName === 'cite',
],
];
}
}
29 changes: 29 additions & 0 deletions tests/DOMParser/Nodes/BlockquoteCiteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Tiptap\Editor;
use Tiptap\Extensions\StarterKit;
use Tiptap\Tests\DOMParser\Nodes\BlockquoteCite;

test('no content node gets rendered correctly', function () {
$html = '<blockquote><p>Quote</p><cite>Author</cite></blockquote>';

$result = (new Editor([
'extensions' => [
new StarterKit,
new BlockquoteCite,
],
]))->setContent($html)->getDocument();

expect($result)->toEqual([
'type' => 'doc',
'content' => [
[
'type' => 'blockquoteCite',
'attrs' => [
'quote' => 'Quote',
'author' => 'Author',
],
],
],
]);
});
Loading