You are here

public static function Typogrify::amp in Typogrify 8

Enable custom styling of ampersands.

Wraps apersands in html with '<span class="amp">', so they can be styled with CSS. Ampersands are also normalized to '&amp;. Requires ampersands to have whitespace or an '&nbsp;' on both sides.

It won't mess up & that are already wrapped, in entities or URLs.

Parameters

string $text: The text to work on.

Return value

string The modified text.

4 calls to Typogrify::amp()
SmartyPants::smartAmpersand in src/SmartyPants.php
Wrapping ampersands.
Typogrify::filter in src/TwigExtension/Typogrify.php
Filter text by Typogrify.
Typogrify::filter in src/Typogrify.php
Typogrify.
TypogrifyClassTest::testAmpersandWrapping in tests/src/Unit/TypogrifyClassTest.php
Tests ampersand-wrapping.

File

src/Typogrify.php, line 25

Class

Typogrify
Class \Drupal\typogrify\Typogrify.

Namespace

Drupal\typogrify

Code

public static function amp($text) {
  $amp_finder = "/(\\s|&nbsp;)(&|&amp;|&\\#38;|&#038;)(\\s|&nbsp;)/";
  return preg_replace($amp_finder, '\\1<span class="amp">&amp;</span>\\3', $text);
}