22
33namespace SolutionForest \InspireCms \Filament \Forms \Components \RichEditor \TipTapExtensions ;
44
5- use Illuminate \Support \Arr ;
65use Tiptap \Core \Node ;
76use Tiptap \Utils \HTML ;
87
@@ -65,8 +64,7 @@ public function addAttributes(): array
6564 public function renderHTML ($ node , array $ HTMLAttributes = []): array
6665 {
6766 $ innerContent = match (true ) {
68- str_starts_with ($ node ->attrs ?->mimeType ?? '' , 'image/ ' ) =>
69- !str_ends_with ($ node ->attrs ?->filename ?? '' , '.svg ' )
67+ str_starts_with ($ node ->attrs ?->mimeType ?? '' , 'image/ ' ) => ! str_ends_with ($ node ->attrs ?->filename ?? '' , '.svg ' )
7068 ? sprintf (
7169 '<a href="%s" target="_blank" rel="noopener noreferrer" class="trix-attachment-mediapicker-link"><img src="%s" alt="%s" loading="lazy" class="trix-attachment-image trix-attachment-mediapicker-img" %s></a> ' ,
7270 htmlspecialchars ($ node ->attrs ?->url ?? '' ),
@@ -79,18 +77,16 @@ public function renderHTML($node, array $HTMLAttributes = []): array
7977 htmlspecialchars ($ node ->attrs ?->thumbnailUrl ?? $ node ->attrs ?->url ?? '' ),
8078 htmlspecialchars ($ node ->attrs ?->title ?? '' ),
8179 ),
82- str_starts_with ($ node ->attrs ?->mimeType ?? '' , 'video/ ' ) =>
83- sprintf (
84- '<video controls src="%s" alt="%s" loading="lazy" class="trix-attachment-video trix-attachment-mediapicker-video"></video> ' ,
85- htmlspecialchars ($ node ->attrs ?->url ?? '' ),
86- htmlspecialchars ($ node ->attrs ?->title ?? '' ),
87- ),
88- str_starts_with ($ node ->attrs ?->mimeType ?? '' , 'audio/ ' ) =>
89- sprintf (
90- '<audio controls src="%s" alt="%s" loading="lazy" class="trix-attachment-audio trix-attachment-mediapicker-audio"></audio> ' ,
91- htmlspecialchars ($ node ->attrs ?->url ?? '' ),
92- htmlspecialchars ($ node ->attrs ?->title ?? '' ),
93- ),
80+ str_starts_with ($ node ->attrs ?->mimeType ?? '' , 'video/ ' ) => sprintf (
81+ '<video controls src="%s" alt="%s" loading="lazy" class="trix-attachment-video trix-attachment-mediapicker-video"></video> ' ,
82+ htmlspecialchars ($ node ->attrs ?->url ?? '' ),
83+ htmlspecialchars ($ node ->attrs ?->title ?? '' ),
84+ ),
85+ str_starts_with ($ node ->attrs ?->mimeType ?? '' , 'audio/ ' ) => sprintf (
86+ '<audio controls src="%s" alt="%s" loading="lazy" class="trix-attachment-audio trix-attachment-mediapicker-audio"></audio> ' ,
87+ htmlspecialchars ($ node ->attrs ?->url ?? '' ),
88+ htmlspecialchars ($ node ->attrs ?->title ?? '' ),
89+ ),
9490 default => sprintf (
9591 '<a href="%s" target="_blank" rel="noopener noreferrer" class="trix-attachment-mediapicker-link">%s</a> ' ,
9692 htmlspecialchars ($ node ->attrs ?->url ?? '' ),
@@ -120,15 +116,16 @@ private function convertResponsiveAttributes($elements)
120116 $ responsiveData = [];
121117 if ($ elements instanceof \stdClass) {
122118 $ elements = json_decode (json_encode ($ elements ), true );
123- } else if (is_string ($ elements )) {
119+ } elseif (is_string ($ elements )) {
124120 $ elements = json_decode ($ elements , true );
125- }
126- if (!is_array ($ elements )) {
121+ }
122+ if (! is_array ($ elements )) {
127123 return $ responsiveData ;
128124 }
129125 foreach ($ elements as $ key => $ value ) {
130126 $ responsiveData ["data-image-responsive__ {$ key }" ] = $ value ;
131127 }
128+
132129 return $ responsiveData ;
133130 }
134131}
0 commit comments