BaseMarkdown.php 885 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2008 Yii Software LLC
  4. * @link http://www.yiiframework.com/
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\helpers;
  8. use Michelf\MarkdownExtra;
  9. /**
  10. * BaseMarkdown provides concrete implementation for [[Markdown]].
  11. *
  12. * Do not use BaseMarkdown. Use [[Markdown]] instead.
  13. *
  14. * @author Alexander Makarov <[email protected]>
  15. * @since 2.0
  16. */
  17. class BaseMarkdown
  18. {
  19. /**
  20. * @var MarkdownExtra
  21. */
  22. protected static $markdown;
  23. /**
  24. * Converts markdown into HTML
  25. *
  26. * @param string $content
  27. * @param array $config
  28. * @return string
  29. */
  30. public static function process($content, $config = [])
  31. {
  32. if (static::$markdown === null) {
  33. static::$markdown = new MarkdownExtra();
  34. }
  35. foreach ($config as $name => $value) {
  36. static::$markdown->{$name} = $value;
  37. }
  38. return static::$markdown->transform($content);
  39. }
  40. }