You are here

public function ReadmehelpMarkdown::convertMultiDashSign in README Help 8

Wraps line followed with multi "-" sign line into h2 tag.

Additionally "#" sign turned into anchor link, so the heading can be used as a local or external link target.

Parameters

string $text: The string to be filtered.

Return value

string The HTML source with the heading.

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

File

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

Class

ReadmehelpMarkdown
Provides a filter for markdown.

Namespace

Drupal\readmehelp\Plugin\Filter

Code

public function convertMultiDashSign($text) {
  return preg_replace_callback('/\\n(\\w.*?)\\n\\-+\\n/', function ($matches) {
    if ($match = !empty($matches[1]) ? rtrim($matches[1]) : '') {
      $id = trim(Html::getUniqueId($match), '-');
      $match = "<h2 class=\"h-2\"><a id=\"{$id}\" href=\"#{$id}\" class=\"anchor\"># </a>{$match}</h2>";
    }
    return $match;
  }, $text);
}