You are here

public function ReadmehelpMarkdown::detokenizeSpecialChars in README Help 8

Changes tokens for markdown special symbols.

Parameters

string $text: The HTML string to be filtered.

Return value

string The text with the symbols without special meaning.

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

File

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

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

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