Setze Symbole vor Absätze, Nummern in Kreise und Symbole statt Aufzählungspunkte im Text (ADR-69)
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>
This commit is contained in:
1 parent
67764c3e4f
commit
e904b500fb
24 files changed
+814
-14
No files matched your search
@@ -0,0 +1,51 @@
|
||||
<?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];
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user