You are here

public function CollapseText::htmlToXmlEntities in Collapse Text 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Filter/CollapseText.php \Drupal\collapse_text\Plugin\Filter\CollapseText::htmlToXmlEntities()

Helper function to convert html entities to xml entities.

HTML entity lists from

@todo -- rewrite to use str_replace

2 calls to CollapseText::htmlToXmlEntities()
CollapseText::checkOptions in src/Plugin/Filter/CollapseText.php
Helper function to see if there is an options tag available.
CollapseText::processChildItem in src/Plugin/Filter/CollapseText.php
Helper function to process a child item.

File

src/Plugin/Filter/CollapseText.php, line 554

Class

CollapseText
Provides a filter to display Collapsible text blocks.

Namespace

Drupal\collapse_text\Plugin\Filter

Code

public function htmlToXmlEntities($text) {
  static $replace = [
    // Latin 1.
    ' ' => ' ',
    '¡' => '¡',
    '¢' => '¢',
    '£' => '£',
    '¤' => '¤',
    '¥' => '¥',
    '¦' => '¦',
    '§' => '§',
    '¨' => '¨',
    '©' => '©',
    'ª' => 'ª',
    '«' => '«',
    '¬' => '¬',
    '­' => '­',
    '®' => '®',
    '¯' => '¯',
    '°' => '°',
    '±' => '±',
    '²' => '²',
    '³' => '³',
    '´' => '´',
    'µ' => 'µ',
    '¶' => '¶',
    '·' => '·',
    '¸' => '¸',
    '¹' => '¹',
    'º' => 'º',
    '»' => '»',
    '¼' => '¼',
    '½' => '½',
    '¾' => '¾',
    '¿' => '¿',
    'À' => 'À',
    'Á' => 'Á',
    'Â' => 'Â',
    'Ã' => 'Ã',
    'Ä' => 'Ä',
    'Å' => 'Å',
    'Æ' => 'Æ',
    'Ç' => 'Ç',
    'È' => 'È',
    'É' => 'É',
    'Ê' => 'Ê',
    'Ë' => 'Ë',
    'Ì' => 'Ì',
    'Í' => 'Í',
    'Î' => 'Î',
    'Ï' => 'Ï',
    'Ð' => 'Ð',
    'Ñ' => 'Ñ',
    'Ò' => 'Ò',
    'Ó' => 'Ó',
    'Ô' => 'Ô',
    'Õ' => 'Õ',
    'Ö' => 'Ö',
    '×' => '×',
    'Ø' => 'Ø',
    'Ù' => 'Ù',
    'Ú' => 'Ú',
    'Û' => 'Û',
    'Ü' => 'Ü',
    'Ý' => 'Ý',
    'Þ' => 'Þ',
    'ß' => 'ß',
    'à' => 'à',
    'á' => 'á',
    'â' => 'â',
    'ã' => 'ã',
    'ä' => 'ä',
    'å' => 'å',
    'æ' => 'æ',
    'ç' => 'ç',
    'è' => 'è',
    'é' => 'é',
    'ê' => 'ê',
    'ë' => 'ë',
    'ì' => 'ì',
    'í' => 'í',
    'î' => 'î',
    'ï' => 'ï',
    'ð' => 'ð',
    'ñ' => 'ñ',
    'ò' => 'ò',
    'ó' => 'ó',
    'ô' => 'ô',
    'õ' => 'õ',
    'ö' => 'ö',
    '÷' => '÷',
    'ø' => 'ø',
    'ù' => 'ù',
    'ú' => 'ú',
    'û' => 'û',
    'ü' => 'ü',
    'ý' => 'ý',
    'þ' => 'þ',
    'ÿ' => 'ÿ',
    // Special.
    ''' => ''',
    'Œ' => 'Œ',
    'œ' => 'œ',
    'Š' => 'Š',
    'š' => 'š',
    'Ÿ' => 'Ÿ',
    'ˆ' => 'ˆ',
    '˜' => '˜',
    ' ' => ' ',
    ' ' => ' ',
    ' ' => ' ',
    '‌' => '‌',
    '‍' => '‍',
    '‎' => '‎',
    '‏' => '‏',
    '–' => '–',
    '—' => '—',
    '‘' => '‘',
    '’' => '’',
    '‚' => '‚',
    '“' => '“',
    '”' => '”',
    '„' => '„',
    '†' => '†',
    '‡' => '‡',
    '‰' => '‰',
    '‹' => '‹',
    '›' => '›',
    '€' => '€',
    // Symbols.
    'ƒ' => 'ƒ',
    'Α' => 'Α',
    'Β' => 'Β',
    'Γ' => 'Γ',
    'Δ' => 'Δ',
    'Ε' => 'Ε',
    'Ζ' => 'Ζ',
    'Η' => 'Η',
    'Θ' => 'Θ',
    'Ι' => 'Ι',
    'Κ' => 'Κ',
    'Λ' => 'Λ',
    'Μ' => 'Μ',
    'Ν' => 'Ν',
    'Ξ' => 'Ξ',
    'Ο' => 'Ο',
    'Π' => 'Π',
    'Ρ' => 'Ρ',
    'Σ' => 'Σ',
    'Τ' => 'Τ',
    'Υ' => 'Υ',
    'Φ' => 'Φ',
    'Χ' => 'Χ',
    'Ψ' => 'Ψ',
    'Ω' => 'Ω',
    'α' => 'α',
    'β' => 'β',
    'γ' => 'γ',
    'δ' => 'δ',
    'ε' => 'ε',
    'ζ' => 'ζ',
    'η' => 'η',
    'θ' => 'θ',
    'ι' => 'ι',
    'κ' => 'κ',
    'λ' => 'λ',
    'μ' => 'μ',
    'ν' => 'ν',
    'ξ' => 'ξ',
    'ο' => 'ο',
    'π' => 'π',
    'ρ' => 'ρ',
    'ς' => 'ς',
    'σ' => 'σ',
    'τ' => 'τ',
    'υ' => 'υ',
    'φ' => 'φ',
    'χ' => 'χ',
    'ψ' => 'ψ',
    'ω' => 'ω',
    'ϒ' => 'ϒ',
    'ϖ' => 'ϖ',
    '•' => '•',
    '…' => '…',
    '′' => '′',
    '″' => '″',
    '‾' => '‾',
    '⁄' => '⁄',
    '℘' => '℘',
    'ℑ' => 'ℑ',
    'ℜ' => 'ℜ',
    '™' => '™',
    'ℵ' => 'ℵ',
    '←' => '←',
    '↑' => '↑',
    '→' => '→',
    '↓' => '↓',
    '↔' => '↔',
    '↵' => '↵',
    '⇐' => '⇐',
    '⇑' => '⇑',
    '⇒' => '⇒',
    '⇓' => '⇓',
    '⇔' => '⇔',
    '∀' => '∀',
    '∂' => '∂',
    '∃' => '∃',
    '∅' => '∅',
    '∇' => '∇',
    '∈' => '∈',
    '∉' => '∉',
    '∋' => '∋',
    '∏' => '∏',
    '∑' => '∑',
    '−' => '−',
    '∗' => '∗',
    '√' => '√',
    '∝' => '∝',
    '∞' => '∞',
    '∠' => '∠',
    '∧' => '∧',
    '∨' => '∨',
    '∩' => '∩',
    '∪' => '∪',
    '∫' => '∫',
    '∴' => '∴',
    '∼' => '∼',
    '≅' => '≅',
    '≈' => '≈',
    '≠' => '≠',
    '≡' => '≡',
    '≤' => '≤',
    '≥' => '≥',
    '⊂' => '⊂',
    '⊃' => '⊃',
    '⊄' => '⊄',
    '⊆' => '⊆',
    '⊇' => '⊇',
    '⊕' => '⊕',
    '⊗' => '⊗',
    '⊥' => '⊥',
    '⋅' => '⋅',
    '⌈' => '⌈',
    '⌉' => '⌉',
    '⌊' => '⌊',
    '⌋' => '⌋',
    '⟨' => '〈',
    '⟩' => '〉',
    '◊' => '◊',
    '♠' => '♠',
    '♣' => '♣',
    '♥' => '♥',
    '♦' => '♦',
  ];

  // Only run the substitution if there is actually an entity in the tag.
  if (strpos($text, '&') !== FALSE) {
    $text = strtr($text, $replace);
  }
  return $text;
}