You are here

public static function CodeFilter::processPHPInline in Code Filter 8

Helper function for processCode().

File

src/Plugin/Filter/CodeFilter.php, line 175

Class

CodeFilter
Text filter for highlighting PHP source code.

Namespace

Drupal\codefilter\Plugin\Filter

Code

public static function processPHPInline($matches) {

  // Undo nl2br.
  $text = str_replace('<br />', '', $matches[0]);

  // Decode entities (the highlighter re-entifies) and highlight text.
  $text = highlight_string(Html::decodeEntities($text), 1);

  // Remove PHPs own added code tags.
  $text = str_replace([
    '<code>',
    '</code>',
    "\n",
  ], [
    '',
    '',
    '',
  ], $text);
  return $text;
}