You are here

public function ReadmehelpMarkdown::convertTripleBacktick in README Help 8

Replaces pairs of triple "```" signs by the code tag.

Parameters

string $text: The string to be filtered.

Return value

string The HTML source with text wrapped into code tag which is wrapped into the pre tag.

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

File

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

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

public function convertTripleBacktick($text) {
  return preg_replace_callback('/(```\\w*)[^`].*?[^`](```)/xs', function ($matches) {
    $match = '';
    if ($match = !empty($matches[2]) ? $matches[0] : '') {
      $match = "<pre><code class=\"code--multiline\">" . str_replace([
        $matches[1],
        $matches[2],
      ], '', $match) . "</code></pre>";
    }
    return $match;
  }, $text);
}