Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(132)

Unified Diff: lib/src/prism/components/prism-bash.js

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/prism/components/prism-autoit.min.js ('k') | lib/src/prism/components/prism-bash.min.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/prism/components/prism-bash.js
diff --git a/lib/src/prism/components/prism-bash.js b/lib/src/prism/components/prism-bash.js
index 5b6486d61933f4fd5ef846b9b3e3a757e6909ab2..648268b8bc34df62e274ccfa5e5e29db47b055c1 100644
--- a/lib/src/prism/components/prism-bash.js
+++ b/lib/src/prism/components/prism-bash.js
@@ -1,31 +1,78 @@
-Prism.languages.bash = Prism.languages.extend('clike', {
- 'comment': {
- pattern: /(^|[^"{\\])#.*/,
- lookbehind: true
- },
- 'string': {
- //allow multiline string
- pattern: /("|')(\\?[\s\S])*?\1/,
- inside: {
- //'property' class reused for bash variables
- 'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^\}]+\})/
- }
- },
- // Redefined to prevent highlighting of numbers in filenames
- 'number': {
- pattern: /([^\w\.])-?(0x[\dA-Fa-f]+|\d*\.?\d+([Ee]-?\d+)?)\b/,
- lookbehind: true
- },
- // Originally based on http://ss64.com/bash/
- 'function': /\b(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)\b/,
- 'keyword': /\b(if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)\b/
-});
+(function(Prism) {
+ var insideString = {
+ variable: [
+ // Arithmetic Environment
+ {
+ pattern: /\$?\(\([\w\W]+?\)\)/,
+ inside: {
+ // If there is a $ sign at the beginning highlight $(( and )) as variable
+ variable: [{
+ pattern: /(^\$\(\([\w\W]+)\)\)/,
+ lookbehind: true
+ },
+ /^\$\(\(/,
+ ],
+ number: /\b-?(?:0x[\dA-Fa-f]+|\d*\.?\d+(?:[Ee]-?\d+)?)\b/,
+ // Operators according to https://www.gnu.org/software/bash/manual/bashref.html#Shell-Arithmetic
+ operator: /--?|-=|\+\+?|\+=|!=?|~|\*\*?|\*=|\/=?|%=?|<<=?|>>=?|<=?|>=?|==?|&&?|&=|\^=?|\|\|?|\|=|\?|:/,
+ // If there is no $ sign at the beginning highlight (( and )) as punctuation
+ punctuation: /\(\(?|\)\)?|,|;/
+ }
+ },
+ // Command Substitution
+ {
+ pattern: /\$\([^)]+\)|`[^`]+`/,
+ inside: {
+ variable: /^\$\(|^`|\)$|`$/
+ }
+ },
+ /\$(?:[a-z0-9_#\?\*!@]+|\{[^}]+\})/i
+ ],
+ };
-Prism.languages.insertBefore('bash', 'keyword', {
- //'property' class reused for bash variables
- 'property': /\$([a-zA-Z0-9_#\?\-\*!@]+|\{[^}]+\})/
-});
-Prism.languages.insertBefore('bash', 'comment', {
- //shebang must be before comment, 'important' class from css reused
- 'important': /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/
-});
+ Prism.languages.bash = {
+ 'shebang': {
+ pattern: /^#!\s*\/bin\/bash|^#!\s*\/bin\/sh/,
+ alias: 'important'
+ },
+ 'comment': {
+ pattern: /(^|[^"{\\])#.*/,
+ lookbehind: true
+ },
+ 'string': [
+ //Support for Here-Documents https://en.wikipedia.org/wiki/Here_document
+ {
+ pattern: /((?:^|[^<])<<\s*)(?:"|')?(\w+?)(?:"|')?\s*\r?\n(?:[\s\S])*?\r?\n\2/g,
+ lookbehind: true,
+ inside: insideString
+ },
+ {
+ pattern: /("|')(?:\\?[\s\S])*?\1/g,
+ inside: insideString
+ }
+ ],
+ 'variable': insideString.variable,
+ // Originally based on http://ss64.com/bash/
+ 'function': {
+ pattern: /(^|\s|;|\||&)(?:alias|apropos|apt-get|aptitude|aspell|awk|basename|bash|bc|bg|builtin|bzip2|cal|cat|cd|cfdisk|chgrp|chmod|chown|chroot|chkconfig|cksum|clear|cmp|comm|command|cp|cron|crontab|csplit|cut|date|dc|dd|ddrescue|df|diff|diff3|dig|dir|dircolors|dirname|dirs|dmesg|du|egrep|eject|enable|env|ethtool|eval|exec|expand|expect|export|expr|fdformat|fdisk|fg|fgrep|file|find|fmt|fold|format|free|fsck|ftp|fuser|gawk|getopts|git|grep|groupadd|groupdel|groupmod|groups|gzip|hash|head|help|hg|history|hostname|htop|iconv|id|ifconfig|ifdown|ifup|import|install|jobs|join|kill|killall|less|link|ln|locate|logname|logout|look|lpc|lpr|lprint|lprintd|lprintq|lprm|ls|lsof|make|man|mkdir|mkfifo|mkisofs|mknod|more|most|mount|mtools|mtr|mv|mmv|nano|netstat|nice|nl|nohup|notify-send|nslookup|open|op|passwd|paste|pathchk|ping|pkill|popd|pr|printcap|printenv|printf|ps|pushd|pv|pwd|quota|quotacheck|quotactl|ram|rar|rcp|read|readarray|readonly|reboot|rename|renice|remsync|rev|rm|rmdir|rsync|screen|scp|sdiff|sed|seq|service|sftp|shift|shopt|shutdown|sleep|slocate|sort|source|split|ssh|stat|strace|su|sudo|sum|suspend|sync|tail|tar|tee|test|time|timeout|times|touch|top|traceroute|trap|tr|tsort|tty|type|ulimit|umask|umount|unalias|uname|unexpand|uniq|units|unrar|unshar|uptime|useradd|userdel|usermod|users|uuencode|uudecode|v|vdir|vi|vmstat|wait|watch|wc|wget|whereis|which|who|whoami|write|xargs|xdg-open|yes|zip)(?=$|\s|;|\||&)/,
+ lookbehind: true
+ },
+ 'keyword': {
+ pattern: /(^|\s|;|\||&)(?:let|:|\.|if|then|else|elif|fi|for|break|continue|while|in|case|function|select|do|done|until|echo|exit|return|set|declare)(?=$|\s|;|\||&)/,
+ lookbehind: true
+ },
+ 'boolean': {
+ pattern: /(^|\s|;|\||&)(?:true|false)(?=$|\s|;|\||&)/,
+ lookbehind: true
+ },
+ 'operator': /&&?|\|\|?|==?|!=?|<<<?|>>|<=?|>=?|=~/,
+ 'punctuation': /\$?\(\(?|\)\)?|\.\.|[{}[\];]/
+ };
+
+ var inside = insideString.variable[1].inside;
+ inside['function'] = Prism.languages.bash['function'];
+ inside.keyword = Prism.languages.bash.keyword;
+ inside.boolean = Prism.languages.bash.boolean;
+ inside.operator = Prism.languages.bash.operator;
+ inside.punctuation = Prism.languages.bash.punctuation;
+})(Prism);
« no previous file with comments | « lib/src/prism/components/prism-autoit.min.js ('k') | lib/src/prism/components/prism-bash.min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698