File tree Expand file tree Collapse file tree 4 files changed +66
-1
lines changed
Expand file tree Collapse file tree 4 files changed +66
-1
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,7 @@ private function processChildren($node): array
8282 continue ;
8383 }
8484
85- if ($ child ->hasChildNodes ()) {
85+ if (! $ class :: $ noContent && $ child ->hasChildNodes ()) {
8686 $ item = array_merge ($ item , [
8787 'content ' => $ this ->processChildren ($ child ),
8888 ]);
Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ class Node extends Extension
88
99 public static $ topNode = false ;
1010
11+ public static $ noContent = false ;
12+
1113 public static $ marks = '_ ' ;
1214
1315 public function addAttributes ()
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Tiptap \Tests \DOMParser \Nodes ;
4+
5+ use Tiptap \Core \Node ;
6+
7+ class BlockquoteCite extends Node
8+ {
9+ public static $ name = 'blockquoteCite ' ;
10+
11+ public static $ noContent = true ;
12+
13+ public function addAttributes (): array
14+ {
15+ return [
16+ 'quote ' => [
17+ 'parseHTML ' => fn ($ domNode ) => $ domNode ->childNodes [0 ]->childNodes [0 ]->textContent ?? '' ,
18+ ],
19+ 'author ' => [
20+ 'parseHTML ' => fn ($ domNode ) => $ domNode ->childNodes [1 ]->textContent ?? '' ,
21+ ],
22+ ];
23+ }
24+
25+ public function parseHTML ()
26+ {
27+ return [
28+ [
29+ 'tag ' => 'blockquote ' ,
30+ 'getAttrs ' => fn ($ domNode ) => isset ($ domNode ->childNodes [1 ]) && $ domNode ->childNodes [1 ]->tagName === 'cite ' ,
31+ ],
32+ ];
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Tiptap \Editor ;
4+ use Tiptap \Extensions \StarterKit ;
5+ use Tiptap \Tests \DOMParser \Nodes \BlockquoteCite ;
6+
7+ test ('no content node gets rendered correctly ' , function () {
8+ $ html = '<blockquote><p>Quote</p><cite>Author</cite></blockquote> ' ;
9+
10+ $ result = (new Editor ([
11+ 'extensions ' => [
12+ new StarterKit ,
13+ new BlockquoteCite ,
14+ ],
15+ ]))->setContent ($ html )->getDocument ();
16+
17+ expect ($ result )->toEqual ([
18+ 'type ' => 'doc ' ,
19+ 'content ' => [
20+ [
21+ 'type ' => 'blockquoteCite ' ,
22+ 'attrs ' => [
23+ 'quote ' => 'Quote ' ,
24+ 'author ' => 'Author ' ,
25+ ],
26+ ],
27+ ],
28+ ]);
29+ });
You can’t perform that action at this time.
0 commit comments