View source
<?php
namespace Drupal\markdown;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Markdown implements MarkdownInterface {
use ContainerAwareTrait;
use DependencySerializationTrait;
use StringTranslationTrait;
protected $parsers;
public function __construct(MarkdownParserManagerInterface $markdown_parsers) {
$this->parsers = $markdown_parsers;
}
public static function create(ContainerInterface $container = NULL) {
if (!isset($container)) {
$container = \Drupal::getContainer();
}
return new static($container
->get('plugin.manager.markdown.parser'));
}
public static function load($id, $markdown = NULL, $parser = NULL, $filter = NULL, AccountInterface $account = NULL, LanguageInterface $language = NULL) {
return static::create()
->getParser($parser, $filter, $account)
->load($id, $markdown, $language);
}
public static function loadPath($id, $path, $parser = NULL, $filter = NULL, AccountInterface $account = NULL, LanguageInterface $language = NULL) {
return static::create()
->getParser($parser, $filter, $account)
->loadPath($id, $path, $language);
}
public static function loadUrl($id, $url, $parser = NULL, $filter = NULL, AccountInterface $account = NULL, LanguageInterface $language = NULL) {
return static::create()
->getParser($parser, $filter, $account)
->loadUrl($id, $url, $language);
}
public static function parse($markdown, $parser = NULL, $filter = NULL, AccountInterface $account = NULL, LanguageInterface $language = NULL) {
return static::create()
->getParser($parser, $filter, $account)
->parse($markdown, $language);
}
public static function parsePath($path, $parser = NULL, $filter = NULL, AccountInterface $account = NULL, LanguageInterface $language = NULL) {
return static::create()
->getParser($parser, $filter, $account)
->parsePath($path, $language);
}
public static function parseUrl($url, $parser = NULL, $filter = NULL, AccountInterface $account = NULL, LanguageInterface $language = NULL) {
return static::create()
->getParser($parser, $filter, $account)
->parseUrl($url, $language);
}
public function getParser($parser = NULL, $filter = NULL, AccountInterface $account = NULL) {
return $this->parsers
->createInstance($parser, [
'filter' => $filter,
'account' => $account,
]);
}
}