protected function GeshiFilterFilter::replaceCallback in GeSHi Filter for syntax highlighting 8
Same name and namespace in other branches
- 8.2 src/Plugin/Filter/GeshiFilterFilter.php \Drupal\geshifilter\Plugin\Filter\GeshiFilterFilter::replaceCallback()
Callback for preg_replace_callback.
Old: _geshifilter_replace_callback($match, $format).
Parameters
array $match: Elements from array:
- 0: complete matched string.
- 1: tag name.
- 2: tag attributes.
- 3: tag content.
Return value
string Return the string processed by geshi library.
File
- src/
Plugin/ Filter/ GeshiFilterFilter.php, line 703
Class
- GeshiFilterFilter
- Provides a base filter for Geshi Filter.
Namespace
Drupal\geshifilter\Plugin\FilterCode
protected function replaceCallback(array $match) {
$complete_match = $match[0];
$tag_name = $match[1];
$tag_attributes = $match[2];
$source_code = $match[3];
// Undo linebreak and escaping from preparation phase.
$source_code = Html::decodeEntities($source_code);
// Initialize to default settings.
$lang = $this->config
->get('default_highlighting');
$line_numbering = $this->config
->get('default_line_numbering');
$linenumbers_start = 1;
$title = NULL;
// Determine language based on tag name if possible.
list($generic_code_tags, $language_tags, $tag_to_lang) = $this
->getTags();
if (in_array(GeshiFilter::BRACKETS_PHPBLOCK, array_filter($this
->tagStyles()))) {
$language_tags[] = 'questionmarkphp';
$tag_to_lang['questionmarkphp'] = 'php';
}
if (isset($tag_to_lang[$tag_name])) {
$lang = $tag_to_lang[$tag_name];
}
// Get additional settings from the tag attributes.
$settings = $this
->parseAttributes($tag_attributes);
if (isset($settings['language'])) {
$lang = $settings['language'];
}
if (isset($settings['line_numbering'])) {
$line_numbering = $settings['line_numbering'];
}
if (isset($settings['linenumbers_start'])) {
$linenumbers_start = $settings['linenumbers_start'];
}
if (isset($settings['title'])) {
$title = $settings['title'];
}
if (isset($settings['special_lines'])) {
$special_lines = $settings['special_lines'];
}
if ($lang == GeshiFilter::DEFAULT_DONOTHING) {
// Do nothing, and return the original.
return $complete_match;
}
if ($lang == GeshiFilter::DEFAULT_PLAINTEXT) {
// Use plain text 'highlighting'.
$lang = 'text';
}
$inline_mode = strpos($source_code, "\n") === FALSE;
// Process and return.
return GeshiFilterProcess::processSourceCode($source_code, $lang, $line_numbering, $linenumbers_start, $inline_mode, $title, $special_lines);
}