You are here

protected static function SmartyPants::smartDashes in Typogrify 8

SmartDashes.

Parameters

string $text: Text to be parsed.

string $attr: Value of the smart_quotes="" attribute.

string $ctx: MT context object (unused).

Return value

string $text with replacements.

File

src/SmartyPants.php, line 494

Class

SmartyPants
SmartyPants - Smart punctuation for web sites.

Namespace

Drupal\typogrify

Code

protected static function smartDashes($text, $attr = NULL, $ctx = NULL) {
  if ($attr == NULL) {
    $attr = self::$smartypantsAttr;
  }

  // Reference to the subroutine to use for dash education,
  // default to educateDashes:
  $dash_sub_ref = 'educateDashes';
  if ($attr == 0) {

    // Do nothing.
    return $text;
  }
  elseif ($attr == 2) {

    // Use old smart dash shortcuts, "--" for en, "---" for em.
    $dash_sub_ref = 'educateDashesOldSchool';
  }
  elseif ($attr == 3) {

    // Inverse of 2, "--" for em, "---" for en.
    $dash_sub_ref = 'educateDashesOldSchoolInverted';
  }
  $tokens;
  $tokens = self::tokenizeHtml($text);
  $result = '';

  // Keep track of when we're inside <pre> or <code> tags.
  $in_pre = 0;
  foreach ($tokens as $cur_token) {
    if ($cur_token[0] == "tag") {

      // Don't mess with quotes inside tags.
      $result .= $cur_token[1];
      if (preg_match(self::SMARTYPANTS_TAGS_TO_SKIP, $cur_token[1], $matches)) {
        $in_pre = isset($matches[1]) && $matches[1] == '/' ? 0 : 1;
      }
    }
    else {
      $t = $cur_token[1];
      if (!$in_pre) {
        $t = self::processEscapes($t);
        $t = self::$dash_sub_ref($t);
      }
      $result .= $t;
    }
  }
  return $result;
}