Skip to content
Draft
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
26 changes: 18 additions & 8 deletions config/laravel_editorjs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
'paragraph' => [
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
],
'header' => [
'text' => [
'type' => 'string',
'allowedTags' => 'a[href],mark[class]',
'allowedTags' => 'a[href],mark[class],span[class]',
],
'level' => [1, 2, 3, 4, 5, 6],
],
Expand All @@ -26,7 +26,7 @@
'data' => [
'-' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
],
],
Expand Down Expand Up @@ -79,7 +79,7 @@
],
'caption' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
'withBorder' => 'boolean',
'withBackground' => 'boolean',
Expand All @@ -95,7 +95,7 @@
'data' => [
'-' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
],
],
Expand All @@ -105,11 +105,11 @@
'quote' => [
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
'caption' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
'alignment' => [
0 => 'left',
Expand Down Expand Up @@ -138,7 +138,7 @@
'data' => [
'text' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class]',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
'checked' => 'boolean',
],
Expand Down Expand Up @@ -166,6 +166,16 @@
'height' => 'integer',
'caption' => 'string',
],
'warning' => [
'title' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
'message' => [
'type' => 'string',
'allowedTags' => 'i,b,a[href],code[class],mark[class],span[class]',
],
],
],
],
];
2 changes: 1 addition & 1 deletion resources/views/blocks/checklist.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@foreach($data['items'] as $item)
<li>
<input type="checkbox" {{ $item['checked'] ? 'checked' : '' }} disabled>
<span>{!! $item['text'] !!}</span>
<span>{!! editorjs_render_inline_code($item['text'] ?? '') !!}</span>
</li>
@endforeach
</ul>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/blocks/header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
$tag = "h{$level}";
@endphp

<{{ $tag }}>{{ $data['text'] ?? '' }}</{{ $tag }}>
<{{ $tag }}>{!! editorjs_render_inline_code($data['text'] ?? '') !!}</{{ $tag }}>
2 changes: 1 addition & 1 deletion resources/views/blocks/list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@

<{{ $tag }}>
@foreach($data['items'] as $item)
<li>{{ $item }}</li>
<li>{!! editorjs_render_inline_code($item) !!}</li>
@endforeach
</{{ $tag }}>
2 changes: 1 addition & 1 deletion resources/views/blocks/paragraph.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>{{ $data['text'] }}</p>
<p>{!! editorjs_render_inline_code($data['text'] ?? '') !!}</p>
6 changes: 3 additions & 3 deletions resources/views/blocks/quote.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@endphp

<blockquote class="editor-quote">
<p class="{{ $class }}">{{ $data['text'] }}</p>
<p class="{{ $class }}">{!! editorjs_render_inline_code($data['text'] ?? '') !!}</p>
@if (!empty($data['caption']))
<small class="{{ $class }}">— {{ $data['caption'] }}</small>
<small class="{{ $class }}">— {!! editorjs_render_inline_code($data['caption']) !!}</small>
@endif
</blockquote>
</blockquote>
4 changes: 2 additions & 2 deletions resources/views/blocks/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
@php $tag = ($loop->first && $data['withHeadings']) ? 'th' : 'td'; @endphp

@foreach($row as $cell)
<{{ $tag }}> {{ $cell }} </{{ $tag }}>
<{{ $tag }}> {!! editorjs_render_inline_code($cell) !!} </{{ $tag }}>
@endforeach
</tr>
@endforeach
</table>
</table>
29 changes: 29 additions & 0 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,32 @@ function editorjs()
return app(LaravelEditorJs::class);
}
}

if (! function_exists('editorjs_render_inline_code')) {
/**
* Render text allowing only <span class="inline-code"> ... </span> tags; escape everything else.
*/
function editorjs_render_inline_code(?string $text): string
{
if ($text === null || $text === '') {
return '';
}

// Escape everything first
$escaped = e($text);

// Unescape ONLY <span class="inline-code"> and </span>
// Convert the exact escaped opening tag back to real HTML
$escaped = str_replace('&lt;/span&gt;', '</span>', $escaped);

// Replace opening span with class="inline-code" only
// Use a regex to match exactly class="inline-code" (order and spacing normalized by browser is irrelevant here as we control the output)
$escaped = preg_replace(
'/&lt;span\s+class=&quot;inline-code&quot;&gt;/i',
'<span class="inline-code">',
$escaped
);

return $escaped;
}
}