Skip to content

Commit

Permalink
Improve highlight:
Browse files Browse the repository at this point in the history
- add highlight for directives in C/C++ macros and C#/F# preprocessor lines;
- add some predefined constants in C;
- remove 'true' and 'false' from keyword list in JavaScript, they should be considered as boolean constant.
  • Loading branch information
chaosshen committed Oct 10, 2015
1 parent 0924b07 commit ad316a3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
10 changes: 9 additions & 1 deletion components/prism-c.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ Prism.languages.insertBefore('c', 'string', {
'string': {
pattern: /(#\s*include\s*)(<.+?>|("|')(\\?.)+?\3)/,
lookbehind: true
},
// highlight macro directives as keywords
'directive': {
pattern: /(#\s*)\b(define|elif|else|endif|error|ifdef|ifndef|if|import|include|line|pragma|undef|using)\b/,
lookbehind: true,
alias: 'keyword'
}
}
}
},
// highlight predefined macros as constants
'constant': /\b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|__func__|EOF|NULL|stdin|stdout|stderr)\b/
});

delete Prism.languages.c['class-name'];
Expand Down
11 changes: 10 additions & 1 deletion components/prism-csharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Prism.languages.csharp = Prism.languages.extend('clike', {
Prism.languages.insertBefore('csharp', 'keyword', {
'preprocessor': {
pattern: /(^\s*)#.*/m,
lookbehind: true
lookbehind: true,
alias: 'property',
inside: {
// highlight preprocessor directives as keywords
'directive': {
pattern: /(\s*#)\b(define|elif|else|endif|endregion|error|if|line|pragma|region|undef|warning)\b/,
lookbehind: true,
alias: 'keyword'
}
}
}
});
14 changes: 12 additions & 2 deletions components/prism-fsharp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,15 @@ Prism.languages.fsharp = Prism.languages.extend('clike', {
]
});
Prism.languages.insertBefore('fsharp', 'keyword', {
'preprocessor': /^[^\r\n\S]*#.*/m
});
'preprocessor': {
pattern: /^[^\r\n\S]*#.*/m,
alias: 'property',
inside: {
'directive': {
pattern: /(\s*#)\b(else|endif|if|light|line|nowarn)\b/,
lookbehind: true,
alias: 'keyword'
}
}
}
});
2 changes: 1 addition & 1 deletion components/prism-javascript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Prism.languages.javascript = Prism.languages.extend('clike', {
'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|false|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|true|try|typeof|var|void|while|with|yield)\b/,
'keyword': /\b(as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|var|void|while|with|yield)\b/,
'number': /\b-?(0x[\dA-Fa-f]+|0b[01]+|0o[0-7]+|\d*\.?\d+([Ee][+-]?\d+)?|NaN|Infinity)\b/,
// Allow for all non-ASCII characters (See http://stackoverflow.com/a/2008444)
'function': /[_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*(?=\()/i
Expand Down

0 comments on commit ad316a3

Please sign in to comment.