题
我正在获得一个网络主机,我有团队合作项目。我认为让我自己的粘贴网站粘贴没有失效日期是个好主意(我知道 http:// pastie。 org / 存在)和其他事情。我想知道。什么是一个简单的亮点lib我可以在代码上使用?我只会使用C / C ++。
解决方案
问题标记为<!>“; php <!>”;但你<!>;只会使用C / C ++ <!>;?
PHP解决方案是 GeSHi 。
其他提示
仅为一种语言构建荧光笔(无上下文,使用常规词汇,如C ++)实际上非常简单,因为您基本上可以将所有词汇包装成一个大的正则表达式:
$cpplex = '/
(?<string>"(?:\\\\"|.)*?")|
(?<char>\'(?:\\\\\'|.)*?\')|
(?<comment>\\/\\/.*?\n|\\/\*.*?\*\\/)|
(?<preprocessor>#\w+(?:\\\\\n|[^\\\\])*?\n)| # This one is not perfect!
(?<number>
(?: # Integer followed by optional fractional part.
(?:0(?:
x[0-9a-f]+|[0-7]*)|\d+)
(?:\.\d*)?(?:e[+-]\d+)?)
|(?: # Just the fractional part.
(?:\.\d*)(?:e[+-]\d+)?))|
(?<keyword>asm|auto|break|case…)| # TODO Complete. Include ciso646!
(?<identifier>\\w(?:\\w|\\d)*)
/xs';
$matches = preg_match_all($cpplex, $input, $matches, PREG_OFFSET_CAPTURE);
foreach ($matches as $match) {
// TODO: determine which group was matched.
// Don't forget lexemes that are *not* part of the expression:
// i.e. whitespaces and operators. These are between the matches.
echo "<span class=\"$keyword\">$token</span>";
}
不隶属于 StackOverflow