Parsedown.php in Markdown 3.0.x
File
src/Plugin/Markdown/Parsedown.php
View source
<?php
namespace Drupal\markdown\Plugin\Markdown;
use Drupal\Core\Language\LanguageInterface;
use Drupal\markdown\Traits\MarkdownParserBenchmarkTrait;
class Parsedown extends BaseParser implements MarkdownParserBenchmarkInterface {
use MarkdownParserBenchmarkTrait;
protected static $parserClass = '\\Parsedown';
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::version;
}
}
public function convertToHtml($markdown, LanguageInterface $language = NULL) {
return $this
->getParser()
->text($markdown);
}
public function getParser() {
if (!isset(static::$parsers[$this->filterId])) {
$parser = new static::$parserClass();
if ($this->filter) {
foreach ($this->settings as $name => $value) {
if ($method = $this
->getSettingMethod($name)) {
$parser
->{$method}($value);
}
}
}
static::$parsers[$this->filterId] = $parser;
}
return static::$parsers[$this->filterId];
}
protected function getSettingMethod($name) {
$map = static::settingMethodMap();
return isset($map[$name]) ? $map[$name] : NULL;
}
protected static function settingMethodMap() {
return [
'breaks_enabled' => 'setBreaksEnabled',
'markup_escaped' => 'setMarkupEscaped',
'safe_mode' => 'setSafeMode',
'strict_mode' => 'setStrictMode',
'urls_linked' => 'setUrlsLinked',
];
}
}