ParsedownHtmlTrait.php 991 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @package Grav\Common\Page
  4. *
  5. * @copyright Copyright (C) 2015 - 2019 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. trait ParsedownHtmlTrait
  12. {
  13. /**
  14. * @var \Grav\Common\Markdown\Parsedown
  15. */
  16. protected $parsedown;
  17. /**
  18. * Return HTML markup from the medium.
  19. *
  20. * @param string $title
  21. * @param string $alt
  22. * @param string $class
  23. * @param string $id
  24. * @param bool $reset
  25. * @return string
  26. */
  27. public function html($title = null, $alt = null, $class = null, $id = null, $reset = true)
  28. {
  29. $element = $this->parsedownElement($title, $alt, $class, $id, $reset);
  30. if (!$this->parsedown) {
  31. $this->parsedown = new Parsedown(new Excerpts());
  32. }
  33. return $this->parsedown->elementToHtml($element);
  34. }
  35. }