PhpMarkdown.php in Markdown 3.0.x
File
src/Plugin/Markdown/PhpMarkdown.php
View source
<?php
namespace Drupal\markdown\Plugin\Markdown;
use Drupal\Core\Language\LanguageInterface;
use Drupal\markdown\Traits\MarkdownParserBenchmarkTrait;
class PhpMarkdown extends BaseParser implements MarkdownParserBenchmarkInterface {
use MarkdownParserBenchmarkTrait;
protected static $parserClass = '\\Michelf\\Markdown';
protected static $parsers = [];
public static function installed() : bool {
return class_exists(static::$parserClass);
}
public static function version() : string {
if (static::installed()) {
$class = static::$parserClass;
return $class::MARKDOWNLIB_VERSION;
}
}
public function convertToHtml($markdown, LanguageInterface $language = NULL) {
return $this
->getParser()
->transform($markdown);
}
public function getParser() {
if (!isset(static::$parsers[$this->filterId])) {
$parser = new static::$parserClass();
if ($this->filter) {
foreach ($this->settings as $name => $value) {
$parser->{$name} = $value;
}
}
static::$parsers[$this->filterId] = $parser;
}
return static::$parsers[$this->filterId];
}
}