현장에 붙여 넣기, 구문 강조 표시
-
08-07-2019 - |
문제
웹 호스트를 받고 있으며 Teammats와 프로젝트가 있습니다. 나는 페이스트에 만료 날짜가없는 내 자신의 페이스트 사이트를 갖는 것이 좋은 생각이라고 생각했다 (나는 알고있다. http://pastie.org/ 존재)와 다른 것들. 알고 싶었습니다. 코드에서 사용할 수있는 간단한 하이라이트 LIB는 무엇입니까? C/C ++ 만 사용하고 있습니다.
해결책
문제는 "PHP"태그가 지정되었지만 "C/C ++ 만 사용하는 것"입니까?
PHP 솔루션입니다 Geshi.
다른 팁
하나의 언어만으로도 (C ++와 같은 일반 Lexemes를 사용하여 컨텍스트 무료)로서의 형광펜을 구축하는 것은 실제로 모든 lexemes를 하나의 큰 정규 표현으로 랩핑 할 수 있기 때문에 실제로는 매우 쉽습니다.
$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