You are here

function hook_markdown_alter in Markdown 8.2

Allows modules to alter markdown prior to it being parsed.

Note: this may introduce or cause performance issues when attempting to parse a lot of markdown content at the same time. If a parser is extensible, it's highly recommended that you create an extension for that specific parser rather than relying on this Drupal hook. This hook is primarily to assist in dealing with parsers that are not extensible and require manual manipulation of the parser itself.

Parameters

string $markdown: The markdown to alter.

array $context: An associative array of context, containing:

  • parser: \Drupal\markdown\Plugin\Markdown\MarkdownParserInterface The parser that these HTML restrictions belong to.
  • filter: \Drupal\filter\Plugin\FilterInterface Optional. A filter that is associated with the parser, may not be set.
  • format: \Drupal\filter\Entity\FilterFormat Optional. A filter format entity that is associated with the filter, may not be set.
  • language: (LanguageInterface) The language of the markdown, if known.
1 invocation of hook_markdown_alter()
BaseParser::parse in src/Plugin/Markdown/BaseParser.php
Parses markdown into HTML.

File

./markdown.api.php, line 41
Hooks and alters provided by the Markdown module.

Code

function hook_markdown_alter(&$markdown, array $context) {

  // Append a company name with an inline stock price widget. It's highly
  // recommended to place your replacements in a callback in case they are
  // computationally expensive. This ensures it's only executed when needed.
  $markdown = preg_replace_callback('/Company Name/', function ($matches) {
    return $matches[0] . ' ' . my_module_inline_stock_widget();
  }, $markdown);
}