Skip to content

Instantly share code, notes, and snippets.

@robertdrakedennis
Created August 16, 2021 18:26
Show Gist options
  • Save robertdrakedennis/13a92a9d7cafc857dbca643f0d9a7cb5 to your computer and use it in GitHub Desktop.
Save robertdrakedennis/13a92a9d7cafc857dbca643f0d9a7cb5 to your computer and use it in GitHub Desktop.
Server side character counting for tiptap v3
<?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