You are here

public function ReadmehelpMarkdown::convertLeadingMultiDashAsteriskUnderscore in README Help 8

Replaces "*", "-" and "_" sign sequences by a ruler tag.

At least three signs should placed on a line wrapped into two empty lines. The "___" turns into a slim ruler tag, the "***" turns into middle one and "---" into fat ruler tag.

Parameters

string $text: The string to be filtered.

Return value

string The HTML source with the rulers.

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

File

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

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

public function convertLeadingMultiDashAsteriskUnderscore($text) {
  $pattern = '/(\\n\\n)(\\-\\-\\-+\\n+)|(\\*\\*\\*+\\n+)|(\\_\\_\\_+\\n+)(\\n)/xs';
  return preg_replace_callback($pattern, function ($matches) {
    $match = '';
    if ($match = !empty($matches[0]) ? $matches[0] : '') {
      if (strstr($match, '___')) {
        $class = 'underscore';
      }
      elseif (strstr($match, '***')) {
        $class = 'asterisk';
      }
      else {
        $class = 'dash';
      }
      $match = "\n\n<hr class=\"hr-{$class}\">\n\n";
    }
    return $match;
  }, $text);
}