You are here

public static function Typogrify::initialQuotes in Typogrify 8

Initial quotes.

Wraps initial quotes in ``class="dquo"`` for double quotes or ``class="quo"`` for single quotes. Works in these block tags ``(h1-h6, p, li)`` and also accounts for potential opening inline elements ``a, em, strong, span, b, i``. Optionally choose to apply quote span tags to Gullemets as well.

Parameters

string $text: The text to work on.

bool $do_guillemets: Optipnal. Whether to apply quote span tags to Gullemets.

Return value

string The modified text.

3 calls to Typogrify::initialQuotes()
Typogrify::filter in src/TwigExtension/Typogrify.php
Filter text by Typogrify.
Typogrify::filter in src/Typogrify.php
Typogrify.
TypogrifyFilter::process in src/Plugin/Filter/TypogrifyFilter.php
Performs the filter processing.

File

src/Typogrify.php, line 151

Class

Typogrify
Class \Drupal\typogrify\Typogrify.

Namespace

Drupal\typogrify

Code

public static function initialQuotes($text, $do_guillemets = FALSE) {
  $quote_finder = "/((<(p|h[1-6]|li)[^>]*>|^)                     # start with an opening p, h1-6, li or the start of the string\n                    \\s*                                             # optional white space!\n                    (<(a|em|span|strong|i|b)[^>]*>\\s*)*)            # optional opening inline tags, with more optional white space for each.\n                    ((\"|&ldquo;|&\\#8220;)|('|&lsquo;|&\\#8216;))    # Find me a quote! (only need to find the left quotes and the primes)\n                                                                    # double quotes are in group 7, singles in group 8\n                    /ix";
  if ($do_guillemets) {
    $quote_finder = "";
  }
  return preg_replace_callback($quote_finder, 'self::quoteWrapper', $text);
}