You are here

public function ReadmehelpMarkdown::tokenizeEscapedSpecialChars in README Help 8

Tokenizes escaped markdown special symbols.

Parameters

string $text: The text string to be filtered.

Return value

string The text with tokenized special symbols.

1 call to ReadmehelpMarkdown::tokenizeEscapedSpecialChars()
ReadmehelpMarkdown::process in src/Plugin/Filter/ReadmehelpMarkdown.php
Performs the filter processing.

File

src/Plugin/Filter/ReadmehelpMarkdown.php, line 119

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

public function tokenizeEscapedSpecialChars($text) {
  return preg_replace_callback('/([\\\\])(.)/xs', function ($matches) {
    $match = '';
    if ($match = !empty($matches[2]) ? $matches[2] : '') {
      if ($match == '*') {
        $match = "@THEASTERISK@";
      }
      elseif ($match == '_') {
        $match = "@THEUNDERSCORE@";
      }
      elseif ($match == '`') {
        $match = "@THEBACKTICK@";
      }
      elseif ($match == '#') {
        $match = "@THEHASH@";
      }
      elseif ($match == "-") {
        $match = '@THEDASH@';
      }
      elseif ($match == '(') {
        $match = "@THELEFTPAREN@";
      }
      elseif ($match == ")") {
        $match = '@THERIGHTPAREN@';
      }
      elseif ($match == "[") {
        $match = '@THELEFTBRACKET@';
      }
      elseif ($match == "]") {
        $match = '@THERIGHTBRACKET@';
      }
      elseif ($match == " ") {
        $match = '@THESPACE@';
      }
      elseif ($match == ">") {
        $match = '@THEGREATERTHAN@';
      }
      else {
        $match = $matches[0];
      }
    }
    return $match;
  }, $text);
}