Zwei Werkzeuge im Texteditor (Symbol vor dem Absatz, Listenstil); gespeichert werden nur Schlüssel, Bild und Farbe setzt die Ausgabe ein. Kreisfarben aus der Palette, Verwendung wird mitgezählt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
1.7 KiB
PHP
52 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Support\TipTap;
|
|
|
|
use App\Domain\Cms\Widgets\Support\TextMarkers;
|
|
use Tiptap\Core\Extension;
|
|
|
|
/**
|
|
* Zeichen im Text der Website (ADR-69) als Attribute der Knoten: `data-symbol` am Absatz, `data-marker`, `data-symbol` und
|
|
* `data-tone` an Aufzählung und Nummerierung. Gegenstück zu `public/js/rich-text-marks.js`; der Editor führt den Wert beim
|
|
* Speichern durch dieses PHP-Modell, ein Attribut, das hier fehlt, ginge verloren. Welche Werte gelten, entscheidet
|
|
* {@see TextMarkers} beim Bereinigen.
|
|
*/
|
|
class TextMarksExtension extends Extension
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
public static $name = 'textMarks';
|
|
|
|
/**
|
|
* @return array<int, array<string, mixed>>
|
|
*/
|
|
public function addGlobalAttributes()
|
|
{
|
|
return [
|
|
['types' => ['paragraph'], 'attributes' => ['data-symbol' => self::attribute('data-symbol')]],
|
|
['types' => ['bulletList', 'orderedList'], 'attributes' => [
|
|
'data-marker' => self::attribute('data-marker'),
|
|
'data-symbol' => self::attribute('data-symbol'),
|
|
'data-tone' => self::attribute('data-tone'),
|
|
]],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
private static function attribute(string $name): array
|
|
{
|
|
return [
|
|
'default' => null,
|
|
'parseHTML' => fn ($DOMNode) => $DOMNode->getAttribute($name) ?: null,
|
|
'renderHTML' => function ($attributes) use ($name) {
|
|
$value = is_array($attributes) ? ($attributes[$name] ?? null) : ($attributes->{$name} ?? null);
|
|
|
|
return $value === null || $value === '' ? null : [$name => $value];
|
|
},
|
|
];
|
|
}
|
|
}
|