You are here

public function Markdown::process in Markdown 3.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Filter/Markdown.php \Drupal\markdown\Plugin\Filter\Markdown::process()

Performs the filter processing.

Parameters

string $text: The text string to be filtered.

string $langcode: The language code of the text to be filtered.

Return value

\Drupal\filter\FilterProcessResult The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.

Overrides FilterInterface::process

See also

\Drupal\filter\FilterProcessResult

File

src/Plugin/Filter/Markdown.php, line 223

Class

Markdown
Provides a filter for Markdown.

Namespace

Drupal\markdown\Plugin\Filter

Code

public function process($text, $langcode) {

  // Only use the parser to process the text if it's not empty.
  if (!empty($text)) {
    $language = \Drupal::languageManager()
      ->getLanguage($langcode);
    $markdown = $this
      ->getParser()
      ->parse($text, $language);

    // Enable all tags, let other filters (i.e. filter_html) handle that.
    $text = $markdown
      ->setAllowedTags(TRUE)
      ->getHtml();
  }
  return new FilterProcessResult($text);
}