You are here

public static function UnicodeConversion::map in Typogrify 8

Provides Unicode-mapping.

Parameters

string $type: The map type we're looking for, one of 'ligature', 'punctuation', 'arrow' 'nested' or 'all'.

Return value

array Array of conversions, keyed by the original string.

4 calls to UnicodeConversion::map()
TypogrifyFilter::process in src/Plugin/Filter/TypogrifyFilter.php
Performs the filter processing.
TypogrifyFilter::settingsForm in src/Plugin/Filter/TypogrifyFilter.php
Generates a filter's settings form.
TypogrifyFilter::tips in src/Plugin/Filter/TypogrifyFilter.php
Generates a filter's tip.
UnicodeConversion::convertCharacters in src/UnicodeConversion.php
Perform character conversion.

File

src/UnicodeConversion.php, line 20

Class

UnicodeConversion
Return the unicode conversion maps.

Namespace

Drupal\typogrify

Code

public static function map($type = 'all') {
  $map = [
    // See http://www.unicode.org/charts/PDF/UFB00.pdf .
    'ligature' => [
      'ffi' => 'ffi',
      'ffl' => 'ffl',
      'ff' => 'ff',
      'fi' => 'fi',
      'fl' => 'fl',
      'ij' => 'ij',
      'IJ' => 'IJ',
      'st' => 'st',
      'ss' => 'ß',
    ],
    // See http:#www.unicode.org/charts/PDF/U2000.pdf .
    'punctuation' => [
      '...' => '…',
      '..' => '‥',
      '. . .' => '…',
      '---' => '—',
      '--' => '–',
    ],
    'fraction' => [
      '1/4' => '¼',
      '1/2' => '½',
      '3/4' => '¾',
      '1/3' => '⅓',
      '2/3' => '⅔',
      '1/5' => '⅕',
      '2/5' => '⅖',
      '3/5' => '⅗',
      '4/5' => '⅘',
      '1/6' => '⅙',
      '5/6' => '⅚',
      '1/8' => '⅛',
      '3/8' => '⅜',
      '5/8' => '⅝',
      '7/8' => '⅞',
    ],
    'quotes' => [
      ',,' => '„',
      "''" => '”',
      '<<' => '«',
      '>>' => '»',
    ],
    // See http:#www.unicode.org/charts/PDF/U2190.pdf .
    'arrow' => [
      '->>' => '↠',
      '<<-' => '↞',
      '->|' => '⇥',
      '|<-' => '⇤',
      '<->' => '↔',
      '->' => '→',
      '<-' => '←',
      '<=>' => '⇔',
      '=>' => '⇒',
      '<=' => '⇐',
    ],
  ];
  if ($type == 'all') {
    return array_merge($map['ligature'], $map['arrow'], $map['punctuation'], $map['quotes'], $map['fraction']);
  }
  elseif ($type == 'nested') {
    return $map;
  }
  else {
    return $map[$type];
  }
}