1<?php 2 3/* 4 * This file is part of the league/commonmark package. 5 * 6 * (c) Colin O'Dell <colinodell@gmail.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace League\CommonMark; 13 14/** 15 * Converts CommonMark-compatible Markdown to HTML. 16 * 17 * @deprecated This class is deprecated since league/commonmark 1.4, use MarkdownConverter instead. 18 */ 19class Converter implements ConverterInterface 20{ 21 /** 22 * The document parser instance. 23 * 24 * @var DocParserInterface 25 */ 26 protected $docParser; 27 28 /** 29 * The html renderer instance. 30 * 31 * @var ElementRendererInterface 32 */ 33 protected $htmlRenderer; 34 35 /** 36 * Create a new commonmark converter instance. 37 * 38 * @param DocParserInterface $docParser 39 * @param ElementRendererInterface $htmlRenderer 40 */ 41 public function __construct(DocParserInterface $docParser, ElementRendererInterface $htmlRenderer) 42 { 43 if (!($this instanceof MarkdownConverter)) { 44 @trigger_error(sprintf('The %s class is deprecated since league/commonmark 1.4, use %s instead.', self::class, MarkdownConverter::class), E_USER_DEPRECATED); 45 } 46 47 $this->docParser = $docParser; 48 $this->htmlRenderer = $htmlRenderer; 49 } 50 51 /** 52 * Converts CommonMark to HTML. 53 * 54 * @param string $commonMark 55 * 56 * @throws \RuntimeException 57 * 58 * @return string 59 * 60 * @api 61 */ 62 public function convertToHtml(string $commonMark): string 63 { 64 $documentAST = $this->docParser->parse($commonMark); 65 66 return $this->htmlRenderer->renderBlock($documentAST); 67 } 68 69 /** 70 * Converts CommonMark to HTML. 71 * 72 * @see Converter::convertToHtml 73 * 74 * @param string $commonMark 75 * 76 * @throws \RuntimeException 77 * 78 * @return string 79 */ 80 public function __invoke(string $commonMark): string 81 { 82 return $this->convertToHtml($commonMark); 83 } 84} 85