You are here

class Parsedown in Markdown 3.0.x

Plugin annotation


@MarkdownParser(
  id = "erusev/parsedown",
  label = @Translation("Parsedown"),
  url = "https://parsedown.org",
)

Hierarchy

Expanded class hierarchy of Parsedown

File

src/Plugin/Markdown/Parsedown.php, line 15

Namespace

Drupal\markdown\Plugin\Markdown
View source
class Parsedown extends BaseParser implements MarkdownParserBenchmarkInterface {
  use MarkdownParserBenchmarkTrait;

  /**
   * The parser class.
   *
   * @var string
   */
  protected static $parserClass = '\\Parsedown';

  /**
   * MarkdownExtra parsers, keyed by filter identifier.
   *
   * @var \Parsedown[]
   */
  protected static $parsers = [];

  /**
   * {@inheritdoc}
   */
  public static function installed() : bool {
    return class_exists(static::$parserClass);
  }

  /**
   * {@inheritdoc}
   */
  public static function version() : string {
    if (static::installed()) {
      $class = static::$parserClass;
      return $class::version;
    }
  }

  /**
   * {@inheritdoc}
   */
  public function convertToHtml($markdown, LanguageInterface $language = NULL) {
    return $this
      ->getParser()
      ->text($markdown);
  }

  /**
   * Retrieves the PHP Markdown parser.
   *
   * @return \Parsedown
   *   A PHP Markdown parser.
   */
  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];
  }

  /**
   * Retrieves the method used to configure a specific setting.
   *
   * @param string $name
   *   The name of the setting.
   *
   * @return string|null
   *   The method name or NULL if method does not exist.
   */
  protected function getSettingMethod($name) {
    $map = static::settingMethodMap();
    return isset($map[$name]) ? $map[$name] : NULL;
  }

  /**
   * A map of setting <-> method.
   *
   * @return array
   */
  protected static function settingMethodMap() {
    return [
      'breaks_enabled' => 'setBreaksEnabled',
      'markup_escaped' => 'setMarkupEscaped',
      'safe_mode' => 'setSafeMode',
      'strict_mode' => 'setStrictMode',
      'urls_linked' => 'setUrlsLinked',
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseParser::$allowedTags protected property The allowed HTML tags, if set.
BaseParser::$extensions protected static property MarkdownExtension plugins specific to a parser. 1
BaseParser::$filter protected property The current filter being used.
BaseParser::$filterId protected property The filter identifier.
BaseParser::$settings protected property The parser settings.
BaseParser::getAllowedTags public function Retrieves allowed HTML tags, if set. Overrides MarkdownParserInterface::getAllowedTags
BaseParser::getDescription public function Retrieves the description of the plugin, if set. Overrides MarkdownInstallablePluginInterface::getDescription
BaseParser::getFilter public function Retrieves the markdown filter plugin, if set. Overrides MarkdownParserInterface::getFilter
BaseParser::getFilterFormat public function Retrieves a filter format entity. Overrides MarkdownParserInterface::getFilterFormat
BaseParser::getGuidelines public function Builds a guide on how to use the Markdown Parser. Overrides MarkdownGuidelinesInterface::getGuidelines 1
BaseParser::getLabel public function Displays the human-readable label of the plugin. Overrides MarkdownInstallablePluginInterface::getLabel
BaseParser::getSummary public function Retrieves a short summary of what the MarkdownParser does. Overrides MarkdownParserInterface::getSummary
BaseParser::getUrl public function Retrieves the URL for the parser, if any. Overrides MarkdownParserInterface::getUrl
BaseParser::getVersion public function The current version of the parser. Overrides MarkdownInstallablePluginInterface::getVersion
BaseParser::isInstalled public function Indicates whether the parser is installed. Overrides MarkdownInstallablePluginInterface::isInstalled
BaseParser::load public function Loads a cached ParsedMarkdown object. Overrides MarkdownParserInterface::load
BaseParser::loadPath public function Loads a cached ParsedMarkdown object for a local file system path. Overrides MarkdownParserInterface::loadPath
BaseParser::loadUrl public function Loads a cached ParsedMarkdown object for a URL. Overrides MarkdownParserInterface::loadUrl
BaseParser::parsePath public function Parses markdown from a local file into HTML. Overrides MarkdownParserInterface::parsePath
BaseParser::parseUrl public function Parses markdown from an external URL into HTML. Overrides MarkdownParserInterface::parseUrl
BaseParser::setAllowedTags public function Sets the allowed HTML tags. Overrides MarkdownParserInterface::setAllowedTags
BaseParser::tips public function Generates a filter's tip. Overrides MarkdownParserInterface::tips
BaseParser::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
MarkdownParserBenchmarkTrait::$benchmark protected static property Flag indicating whether this is currently in the process of a benchmark.
MarkdownParserBenchmarkTrait::benchmark public function
MarkdownParserBenchmarkTrait::benchmarkAverages public function
MarkdownParserBenchmarkTrait::benchmarkParse public function
MarkdownParserBenchmarkTrait::benchmarkRender public function
MarkdownParserBenchmarkTrait::parse public function
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
Parsedown::$parserClass protected static property The parser class. 1
Parsedown::$parsers protected static property MarkdownExtra parsers, keyed by filter identifier.
Parsedown::convertToHtml public function Converts Markdown into HTML. Overrides BaseParser::convertToHtml
Parsedown::getParser public function Retrieves the PHP Markdown parser.
Parsedown::getSettingMethod protected function Retrieves the method used to configure a specific setting.
Parsedown::installed public static function Indicates whether the parser is installed. Overrides BaseParser::installed
Parsedown::settingMethodMap protected static function A map of setting <-> method.
Parsedown::version public static function Retrieves the version of the installed parser. Overrides BaseParser::version
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.