Html.php 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Utils;
  3. use Parsedown;
  4. class Html
  5. {
  6. private const encoding = 'UTF-8';
  7. private const flags = ENT_QUOTES | ENT_HTML5;
  8. /*
  9. * Escapa un texto a HTML 5.
  10. */
  11. public static function escape(?string $text = '')
  12. {
  13. return htmlentities($text ?? '', self::flags, self::encoding, true);
  14. }
  15. /*
  16. * Escapa algunos caracteres de un texto a HTML 5.
  17. */
  18. public static function simpleEscape(?string $text = '')
  19. {
  20. return htmlspecialchars($text ?? '', self::flags, self::encoding, true);
  21. }
  22. /*
  23. * Convierte un texto en Markdown a HTML 5.
  24. */
  25. public static function fromMarkdown(?string $text = '')
  26. {
  27. return Parsedown::instance()
  28. ->setSafeMode(true)
  29. ->setMarkupEscaped(true)
  30. ->setBreaksEnabled(false)
  31. ->setUrlsLinked(false)
  32. ->text($text ?? '');
  33. }
  34. }