ParsedownHtmlTrait.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @package Grav\Common\Page
  4. *
  5. * @copyright Copyright (c) 2015 - 2023 Trilby Media, LLC. All rights reserved.
  6. * @license MIT License; see LICENSE file for details.
  7. */
  8. namespace Grav\Common\Page\Medium;
  9. use Grav\Common\Markdown\Parsedown;
  10. use Grav\Common\Page\Markdown\Excerpts;
  11. /**
  12. * Trait ParsedownHtmlTrait
  13. * @package Grav\Common\Page\Medium
  14. */
  15. trait ParsedownHtmlTrait
  16. {
  17. /** @var Parsedown|null */
  18. protected $parsedown;
  19. /**
  20. * Return HTML markup from the medium.
  21. *
  22. * @param string|null $title
  23. * @param string|null $alt
  24. * @param string|null $class
  25. * @param string|null $id
  26. * @param bool $reset
  27. * @return string
  28. */
  29. public function html($title = null, $alt = null, $class = null, $id = null, $reset = true)
  30. {
  31. $element = $this->parsedownElement($title, $alt, $class, $id, $reset);
  32. if (!$this->parsedown) {
  33. $this->parsedown = new Parsedown(new Excerpts());
  34. }
  35. return $this->parsedown->elementToHtml($element);
  36. }
  37. }