Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve highlight. #801

Merged
merged 1 commit into from
Oct 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Improve highlight:
- 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.
chaosshen committed Oct 10, 2015

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit ad316a36724109e12e69ff3e3878305ca67a405f
10 changes: 9 additions & 1 deletion components/prism-c.js
Original file line number Diff line number Diff line change
@@ -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'];
11 changes: 10 additions & 1 deletion components/prism-csharp.js
Original file line number Diff line number Diff line change
@@ -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
@@ -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