現在syntaxhighlighterを使って自分のブログでソースコードを色付けしているのですが
http://freesofutotravel.blog94.fc2.com/blog-entry-22.html
をみると分かる通り
cpp
1#include <iostream> 2#include <string> 3#include <vector> 4#include <stdexcept> 5#include <algorithm>
のようにあると、vectorとかstringに緑色の色がついてしまいます。
syntaxhighlighterの置換リストは
js
1 this.regexList = [ 2 { regex: /#[ ]*(?:define|error|import|undef|elif|include|using|ifdef|line|ifndef|if|pragma|else|endif)/g, css: 'preprocessor' }, 3 { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' }, // one line comments 4 { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments 5 { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings 6 { regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings 7 { regex: /!(?:defined)/g, css: 'preprocessor' }, 8 { regex: new RegExp(this.getKeywords(preprocessor_word), 'gm'), css: 'preprocessor' }, 9 { regex: new RegExp(this.getKeywords(typedefined), 'gm'), css: 'color1 bold' }, 10 { regex: new RegExp(this.getKeywords(macro), 'gm'), css: 'color2 bold' }, 11 { regex: new RegExp(this.getKeywords(reserved), 'gm'), css: 'keyword bold' } 12 ]; 13
のようになっていて
(js全体:shBrushCpp_kai.js)
vectorとかstringがtypedefined
にマッチするので緑色になっています。
で、#include と同じ行かつ#includeの後にある<>
にマッチする正規表現と言うのは書けるものなのでしょうか?書けるとしたらどのようにかけばいいでしょうか?
追記
@tozjp 氏の修正を
js
1new RegExp(this.getKeywords(typedefined) + "(?!>$)", 'gm')
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/03/24 11:13