public function CodeFilter::process in Code Filter 8
Performs the filter processing.
Parameters
string $text: The text string to be filtered.
string $langcode: The language code of the text to be filtered.
Return value
\Drupal\filter\FilterProcessResult The filtered text, wrapped in a FilterProcessResult object, and possibly with associated assets, cacheability metadata and placeholders.
Overrides FilterInterface::process
See also
\Drupal\filter\FilterProcessResult
File
- src/
Plugin/ Filter/ CodeFilter.php, line 55
Class
- CodeFilter
- Text filter for highlighting PHP source code.
Namespace
Drupal\codefilter\Plugin\FilterCode
public function process($text, $langcode) {
// Escape code tags to prevent other filters from acting on them.
$text = preg_replace_callback('@<code>(.+?)</code>@s', [
get_class($this),
'codeTagCallback',
], $text);
$text = preg_replace_callback('@[\\[<](\\?php)(.+?)(\\?)[\\]>]@s', [
get_class($this),
'phpTagCallback',
], $text);
// Replace code.
$text = preg_replace_callback('@\\[codefilter_code\\](.+?)\\[/codefilter_code\\]@s', [
get_class($this),
'processCodeCallback',
], $text);
$text = preg_replace_callback('@\\[codefilter_php\\](.+?)\\[/codefilter_php\\]@s', [
get_class($this),
'processPHPCallback',
], $text);
// A hack, so we can conditionally nowrap based on filter settings.
// @todo Refactor how replacements are done so we can do this more cleanly.
if ($this->settings['nowrap_expand']) {
$text = str_replace('class="codeblock"', 'class="codeblock nowrap-expand"', $text);
}
return new FilterProcessResult($text);
}