You are here

public function ReadmehelpMarkdown::convertLeadingGreaterThanSign in README Help 8

Wraps leading "> " or ">> " text lines into blockquote or cite tag.

Additionally a leading sign turns into anchor link, so the blockquote can be used as a local or external link target. Multiple subsequent leading "> " or ">> " text lines can be used to wrap them into one tag.

Parameters

string $text: The string to be filtered.

Return value

string The HTML source with blockquote or cite blocks.

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

File

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

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

public function convertLeadingGreaterThanSign($text) {
  return preg_replace_callback('/(?(DEFINE)(?<emptyline>(\\n\\n)))(\\n>>? )(\\w.*?)(?&emptyline)/s', function ($matches) {
    $match = '';
    if ($match = !empty($matches[4]) ? preg_replace('/\\n>>? /', '', $matches[4]) : '') {
      $id = trim(Html::getUniqueId(Unicode::truncate($match, 32, TRUE)), '-');
      if (trim($matches[3]) == '>>') {
        $tag = 'cite';
        $sign = '>> ';
      }
      else {
        $tag = 'blockquote';
        $sign = '> ';
      }
      $match = "\n<{$tag}><a id=\"{$id}\" href=\"#{$id}\" class=\"anchor\">{$sign}</a>{$match}</{$tag}>\n";
    }
    return $match;
  }, $text);
}