You are here

public function ReadmehelpMarkdown::process in README Help 8

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/ReadmehelpMarkdown.php, line 78

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

public function process($text, $langcode, $file_path = NULL) {
  if (!empty($text)) {
    $request = \Drupal::request();
    $path = $request
      ->getPathInfo();
    $host = str_replace($path, '', $request
      ->getSchemeAndHttpHost() . $request
      ->getRequestUri());
    $path = $file_path ? trim($file_path, '/') : trim($path, '/');
    $text = $text . "\n";
    $text = preg_replace('/\\r\\n?/', '\\n', $text);
    $text = preg_replace('/\\t/', '  ', $text);
    $text = $this
      ->tokenizeEscapedSpecialChars($text);
    $text = $this
      ->convertLeadingDashSpace($text);
    $text = $this
      ->convertLeadingNumberDotSpace($text);
    $text = $this
      ->convertLeadingGreaterThanSign($text);
    $text = $this
      ->convertLeadingHash($text);
    $text = $this
      ->convertLeadingMultiDashAsteriskUnderscore($text);
    $text = $this
      ->convertMultiEqualitySign($text);
    $text = $this
      ->convertMultiDashSign($text);
    $text = $this
      ->convertDoubleAsterisk($text);
    $text = $this
      ->convertSingleAsterisk($text);
    $text = $this
      ->convertDoubleUnderscore($text);
    $text = $this
      ->convertSingleUnderscore($text);
    $text = $this
      ->convertMarkdownImage($text, $host, $path);
    $text = $this
      ->convertMarkdownLink($text, $host);
    $text = $this
      ->convertTripleBacktick($text);
    $text = $this
      ->convertSingleBacktick($text);
    $text = $this
      ->detokenizeSpecialChars($text);
  }
  return new FilterProcessResult($text);
}