Rich Editor <p> tag

is it possible to remove <p> tag when saving or when displaying the content?
Solution:
I already solved it.. just for reference ``` <?php namespace App\Features\Filament\Fields;...
Jump to solution
5 Replies
yakslav
yakslav4w ago
yeah. it is possible.
Eskie
EskieOP4w ago
Can you guide me on how to do it?
yakslav
yakslav4w ago
above all else, You can use php's String function library. Or if it is frontend side, u can use JS. Are u developer? What project are u working on? plz, Could u give me the project details?
Eskie
EskieOP4w ago
@yakslav im looking for a cleaner way.. i can remove them if i want to but i just want to know if there is really a clean way to do it
Solution
Eskie
Eskie4w ago
I already solved it.. just for reference
<?php

namespace App\Features\Filament\Fields;

use Closure;
use Filament\Forms\Components\RichEditor as BaseRichEditor;

class RichEditor extends BaseRichEditor
{
protected int | Closure | null $maxLength = 65535;

/**
* @var array<string>
*/
protected array | Closure $toolbarButtons = [
'link',
];

public static function make(string $name): static
{
$static = app(static::class, ['name' => $name]);
$static->configure();

$static->formatOutput();

return $static;
}

/**
* This will remove the <p></p> tag
*
* @return void
*/
public function formatOutput(): void
{
$this->dehydrateStateUsing = function ($state) {
return preg_replace('/<\/?p>/', '', $state);
};
}
}
<?php

namespace App\Features\Filament\Fields;

use Closure;
use Filament\Forms\Components\RichEditor as BaseRichEditor;

class RichEditor extends BaseRichEditor
{
protected int | Closure | null $maxLength = 65535;

/**
* @var array<string>
*/
protected array | Closure $toolbarButtons = [
'link',
];

public static function make(string $name): static
{
$static = app(static::class, ['name' => $name]);
$static->configure();

$static->formatOutput();

return $static;
}

/**
* This will remove the <p></p> tag
*
* @return void
*/
public function formatOutput(): void
{
$this->dehydrateStateUsing = function ($state) {
return preg_replace('/<\/?p>/', '', $state);
};
}
}

Did you find this page helpful?