Created
August 16, 2021 18:26
-
-
Save robertdrakedennis/13a92a9d7cafc857dbca643f0d9a7cb5 to your computer and use it in GitHub Desktop.
Server side character counting for tiptap v3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Traits; | |
trait SetupEditor | |
{ | |
public function exceedsCharacterCount($delta): bool | |
{ | |
$renderedHtml = (new \ProseMirrorToHtml\Renderer)->render($delta); | |
$strippedHtml = strip_tags($renderedHtml); | |
$characterCount = strlen($strippedHtml); | |
return $characterCount > static::$maxCharacters ? true : false; | |
} | |
public function renderDelta($delta) | |
{ | |
return (new \ProseMirrorToHtml\Renderer)->render($delta); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment