public function GeshiFilterFilter::prepareMarkdownCallback 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::prepareMarkdownCallback()
Callback for preparing input text from markdown(```) tags.
Replaces the code tags brackets with geshifilter specific ones to prevent possible messing up by other filters, e.g. '[python]foo[/python]' to '[geshifilter-python]foo[/geshifilter-python]'. Replaces newlines with " " to prevent issues with the line break filter Escapes the tricky characters like angle brackets with SafeMarkup::checkPlain() to prevent messing up by other filters like the HTML filter.
Parameters
array $match: An array with the pieces from matched string.
Return value
string Return escaped code block.
File
- src/
Plugin/ Filter/ GeshiFilterFilter.php, line 970
Class
- GeshiFilterFilter
- Provides a base filter for Geshi Filter.
Namespace
Drupal\geshifilter\Plugin\FilterCode
public function prepareMarkdownCallback(array $match) {
$tag_name = $match[2];
$tag_attributes = '';
$content = $match[3];
// Get the default highlighting mode.
$lang = $this->config
->get('default_highlighting');
if ($lang == GeshiFilter::DEFAULT_DONOTHING) {
// If the default highlighting mode is GeshiFilter::DEFAULT_DONOTHING
// and there is no language set (with language tag or language attribute),
// we should not do any escaping in this prepare phase,
// so that other filters can do their thing.
$enabled_languages = GeshiFilter::getEnabledLanguages();
// Usage of language tag?
list($generic_code_tags, $language_tags, $tag_to_lang) = $this
->getTags();
if (isset($tag_to_lang[$tag_name]) && isset($enabled_languages[$tag_to_lang[$tag_name]])) {
$lang = $tag_to_lang[$tag_name];
}
// If no language was set: prevent escaping and return original string.
if ($lang == GeshiFilter::DEFAULT_DONOTHING) {
return $match[0];
}
}
if ($this
->decodeEntities()) {
$content = $this
->unencode($content);
}
// Return escaped code block.
return '[geshifilter-' . $tag_name . $tag_attributes . ']' . str_replace([
"\r",
"\n",
], [
'',
' ',
], SafeMarkup::checkPlain($content)) . '[/geshifilter-' . $tag_name . ']';
}