You are here

abstract class ExtensibleParser in Markdown 3.0.x

Class ExtensibleMarkdownParser.

Hierarchy

Expanded class hierarchy of ExtensibleParser

File

src/Plugin/Markdown/ExtensibleParser.php, line 10

Namespace

Drupal\markdown\Plugin\Markdown
View source
abstract class ExtensibleParser extends BaseParser implements ExtensibleMarkdownParserInterface {

  /**
   * The Markdown Extension Manager service.
   *
   * @var \Drupal\markdown\MarkdownExtensionManagerInterface
   */
  protected static $extensionManager;

  /**
   * MarkdownExtension plugins specific to a parser.
   *
   * @var array
   */
  protected static $extensions;

  /**
   * {@inheritdoc}
   */
  public function alterGuidelines(array &$guides = []) {

    // Allow enabled extensions to alter existing guides.
    foreach ($this
      ->getExtensions() as $plugin_id => $extension) {
      if ($extension instanceof MarkdownGuidelinesAlterInterface) {
        $extension
          ->alterGuidelines($guides);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function getGuidelines() {
    $guides = parent::getGuidelines();

    // Allow enabled extensions to provide their own guides.
    foreach ($this
      ->getExtensions() as $plugin_id => $extension) {
      if ($extension instanceof MarkdownGuidelinesInterface && ($element = $extension
        ->getGuidelines())) {
        $guides['extensions'][$plugin_id] = $element;
      }
    }
    return $guides;
  }

  /**
   * {@inheritdoc}
   */
  public function getExtensions($enabled = NULL) {
    if (!isset(static::$extensions["{$enabled}:{$this->pluginId}"])) {
      static::$extensions["{$enabled}:{$this->pluginId}"] = ($filter = $this
        ->getFilter()) && $filter
        ->isEnabled() ? $this
        ->extensionManager()
        ->getExtensions($this->pluginId, $enabled) : [];
    }

    /* @type \Drupal\markdown\Plugin\Markdown\Extension\MarkdownExtensionInterface $extension */
    foreach (static::$extensions["{$enabled}:{$this->pluginId}"] as $id => $extension) {
      if (isset($this->settings[$id])) {
        $extension
          ->setSettings($this->settings[$id]);
      }
    }

    /** @var \Drupal\markdown\Plugin\Markdown\Extension\MarkdownExtensionInterface[] $extensions */
    $extensions = static::$extensions["{$enabled}:{$this->pluginId}"];
    return $extensions;
  }

  /**
   * Retrieves the Markdown Extension Manager service.
   *
   * @return \Drupal\markdown\MarkdownExtensionManagerInterface
   */
  protected function extensionManager() : MarkdownExtensionManagerInterface {
    if (!static::$extensionManager) {
      static::$extensionManager = \Drupal::service('plugin.manager.markdown.extension');
    }
    return static::$extensionManager;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseParser::$allowedTags protected property The allowed HTML tags, if set.
BaseParser::$filter protected property The current filter being used.
BaseParser::$filterId protected property The filter identifier.
BaseParser::$settings protected property The parser settings.
BaseParser::convertToHtml public function Converts Markdown into HTML. Overrides MarkdownParserInterface::convertToHtml 4
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::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::installed public static function Indicates whether the parser is installed. Overrides MarkdownInstallablePluginInterface::installed 4
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::parse public function Parses markdown into HTML. Overrides MarkdownParserInterface::parse
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::version public static function Retrieves the version of the installed parser. Overrides MarkdownInstallablePluginInterface::version 4
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
ExtensibleParser::$extensionManager protected static property The Markdown Extension Manager service.
ExtensibleParser::$extensions protected static property MarkdownExtension plugins specific to a parser. Overrides BaseParser::$extensions
ExtensibleParser::alterGuidelines public function Alters existing guides on how to use the Markdown Parser. Overrides MarkdownGuidelinesAlterInterface::alterGuidelines
ExtensibleParser::extensionManager protected function Retrieves the Markdown Extension Manager service.
ExtensibleParser::getExtensions public function Retrieves MarkdownExtension plugins. Overrides ExtensibleMarkdownParserInterface::getExtensions
ExtensibleParser::getGuidelines public function Builds a guide on how to use the Markdown Parser. Overrides BaseParser::getGuidelines
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
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.