MissingParser.php in Markdown 8.2
File
src/Plugin/Markdown/MissingParser.php
View source
<?php
namespace Drupal\markdown\Plugin\Markdown;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Cache\RefinableCacheableDependencyTrait;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Theme\ActiveTheme;
use Drupal\markdown\Annotation\MarkdownAllowedHtml;
use Drupal\markdown\Render\ParsedMarkdown;
use Drupal\markdown\Traits\EnabledPluginTrait;
use Drupal\markdown\Traits\ParserAllowedHtmlTrait;
use Drupal\markdown\Traits\SettingsTrait;
use Drupal\markdown\Util\FilterHtml;
class MissingParser extends InstallablePluginBase implements AllowedHtmlInterface, ParserInterface {
use EnabledPluginTrait;
use ParserAllowedHtmlTrait;
use RefinableCacheableDependencyTrait;
use SettingsTrait;
protected function convertToHtml($markdown, LanguageInterface $language = NULL) {
return $markdown;
}
public function getAllowedHtml() {
return $this
->getCustomAllowedHtml();
}
public function getAllowedHtmlPlugins(ActiveTheme $activeTheme = NULL) {
return $this
->config()
->get('render_strategy.plugins') ?: [];
}
public function getConfiguration() {
$configuration = $this->configuration ?: [];
$configuration += [
'id' => $this
->getPluginId(),
'render_strategy' => [],
];
$configuration['render_strategy'] += [
'type' => $this
->getRenderStrategy(),
'custom_allowed_html' => $this
->getCustomAllowedHtml(),
'plugins' => $this
->getAllowedHtmlPlugins(),
];
ksort($configuration['render_strategy']['plugins']);
return $configuration;
}
public function getCustomAllowedHtml() {
return $this
->config()
->get('render_strategy.custom_allowed_html');
}
public function getRenderStrategy() {
$type = $this
->config()
->get('render_strategy.type');
return isset($type) ? $type : static::FILTER_OUTPUT;
}
public function parse($markdown, LanguageInterface $language = NULL) {
$html = (string) FilterHtml::fromParser($this)
->process($markdown, $language ? $language
->getId() : NULL);
return ParsedMarkdown::create($markdown, $html, $language);
}
}
Classes
Name |
Description |
MissingParser |
The parser used as a fallback when the requested one doesn't exist. |