CommonMarkConverter.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of the league/commonmark package.
  5. *
  6. * (c) Colin O'Dell <colinodell@gmail.com>
  7. *
  8. * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
  9. * - (c) John MacFarlane
  10. *
  11. * For the full copyright and license information, please view the LICENSE
  12. * file that was distributed with this source code.
  13. */
  14. namespace League\CommonMark;
  15. use League\CommonMark\Environment\Environment;
  16. use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension;
  17. /**
  18. * Converts CommonMark-compatible Markdown to HTML.
  19. */
  20. final class CommonMarkConverter extends MarkdownConverter
  21. {
  22. /**
  23. * Create a new Markdown converter pre-configured for CommonMark
  24. *
  25. * @param array<string, mixed> $config
  26. */
  27. public function __construct(array $config = [])
  28. {
  29. $environment = new Environment($config);
  30. $environment->addExtension(new CommonMarkCoreExtension());
  31. parent::__construct($environment);
  32. }
  33. public function getEnvironment(): Environment
  34. {
  35. \assert($this->environment instanceof Environment);
  36. return $this->environment;
  37. }
  38. }