need help for editing font colour in highlightCode
highlight.keyword, highlight.default, highlight.string, highlight.comment
Добавлено: 04.06.2017 / 02:21
image just example
highlight.keyword, highlight.default, highlight.string, highlight.comment
ini_set("highlight.comment", "#008000");
ini_set("highlight.default", "#000000");
ini_set("highlight.html", "#808080");
ini_set("highlight.keyword", "#0000BB; font-weight: bold");
ini_set("highlight.string", "#DD0000");
function highlightText($text, $fileExt="")
{
if ($fileExt == "php")
{
ini_set("highlight.comment", "#008000");
ini_set("highlight.default", "#000000");
ini_set("highlight.html", "#808080");
ini_set("highlight.keyword", "#0000BB; font-weight: bold");
ini_set("highlight.string", "#DD0000");
}
else if ($fileExt == "html")
{
ini_set("highlight.comment", "green");
ini_set("highlight.default", "#CC0000");
ini_set("highlight.html", "#000000");
ini_set("highlight.keyword", "black; font-weight: bold");
ini_set("highlight.string", "#0000FF");
}
// ...
$text = trim($text);
$text = highlight_string("<?php " . $text, true); // highlight_string() requires opening PHP tag or otherwise it will not colorize the text
$text = trim($text);
$text = preg_replace("|^\\<code\\>\\<span style\\=\"color\\: #[a-fA-F0-9]{0,6}\"\\>|", "", $text, 1); // remove prefix
$text = preg_replace("|\\</code\\>\$|", "", $text, 1); // remove suffix 1
$text = trim($text); // remove line breaks
$text = preg_replace("|\\</span\\>\$|", "", $text, 1); // remove suffix 2
$text = trim($text); // remove line breaks
$text = preg_replace("|^(\\<span style\\=\"color\\: #[a-fA-F0-9]{0,6}\"\\>)(<\\?php )(.*?)(\\</span\\>)|", "\$1\$3\$4", $text); // remove custom added "<?php "
return $text;
}
if (null === $this->geshi) {
$this->geshi = new \GeSHi;
$this->geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 2);
$this->geshi->set_line_style('background: rgba(252, 252, 252, 0.7)', 'background: rgba(255, 255, 255, 0.6);', false);
$this->geshi->set_code_style('white-space: pre-wrap');
}
$this->geshi->set_language($parser);
$php = strtr($code[2], ['<br />' => '']);
$php = html_entity_decode(trim($php), ENT_QUOTES, 'UTF-8');
$this->geshi->set_source($php);
$this->geshi = new \GeSHi;
$this->geshi->enable_classes(); // This not inline style(enable classes css)
# kantry (04.06.2017 / 19:23)do know any reference for complete geshi style?
jimy, Yes! This is the standard library method.
e. g this html code <span style="color:red">php, css, etc string</span> will be replaced by <span class="red">php, css, etc string</span>
link to url