prism-powershell.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function (Prism) {
  2. var powershell = Prism.languages.powershell = {
  3. 'comment': [
  4. {
  5. pattern: /(^|[^`])<#[\s\S]*?#>/,
  6. lookbehind: true
  7. },
  8. {
  9. pattern: /(^|[^`])#.*/,
  10. lookbehind: true
  11. }
  12. ],
  13. 'string': [
  14. {
  15. pattern: /"(?:`[\s\S]|[^`"])*"/,
  16. greedy: true,
  17. inside: null // see below
  18. },
  19. {
  20. pattern: /'(?:[^']|'')*'/,
  21. greedy: true
  22. }
  23. ],
  24. // Matches name spaces as well as casts, attribute decorators. Force starting with letter to avoid matching array indices
  25. // Supports two levels of nested brackets (e.g. `[OutputType([System.Collections.Generic.List[int]])]`)
  26. 'namespace': /\[[a-z](?:\[(?:\[[^\]]*\]|[^\[\]])*\]|[^\[\]])*\]/i,
  27. 'boolean': /\$(?:false|true)\b/i,
  28. 'variable': /\$\w+\b/,
  29. // Cmdlets and aliases. Aliases should come last, otherwise "write" gets preferred over "write-host" for example
  30. // Get-Command | ?{ $_.ModuleName -match "Microsoft.PowerShell.(Util|Core|Management)" }
  31. // Get-Alias | ?{ $_.ReferencedCommand.Module.Name -match "Microsoft.PowerShell.(Util|Core|Management)" }
  32. 'function': [
  33. /\b(?:Add|Approve|Assert|Backup|Block|Checkpoint|Clear|Close|Compare|Complete|Compress|Confirm|Connect|Convert|ConvertFrom|ConvertTo|Copy|Debug|Deny|Disable|Disconnect|Dismount|Edit|Enable|Enter|Exit|Expand|Export|Find|ForEach|Format|Get|Grant|Group|Hide|Import|Initialize|Install|Invoke|Join|Limit|Lock|Measure|Merge|Move|New|Open|Optimize|Out|Ping|Pop|Protect|Publish|Push|Read|Receive|Redo|Register|Remove|Rename|Repair|Request|Reset|Resize|Resolve|Restart|Restore|Resume|Revoke|Save|Search|Select|Send|Set|Show|Skip|Sort|Split|Start|Step|Stop|Submit|Suspend|Switch|Sync|Tee|Test|Trace|Unblock|Undo|Uninstall|Unlock|Unprotect|Unpublish|Unregister|Update|Use|Wait|Watch|Where|Write)-[a-z]+\b/i,
  34. /\b(?:ac|cat|chdir|clc|cli|clp|clv|compare|copy|cp|cpi|cpp|cvpa|dbp|del|diff|dir|ebp|echo|epal|epcsv|epsn|erase|fc|fl|ft|fw|gal|gbp|gc|gci|gcs|gdr|gi|gl|gm|gp|gps|group|gsv|gu|gv|gwmi|iex|ii|ipal|ipcsv|ipsn|irm|iwmi|iwr|kill|lp|ls|measure|mi|mount|move|mp|mv|nal|ndr|ni|nv|ogv|popd|ps|pushd|pwd|rbp|rd|rdr|ren|ri|rm|rmdir|rni|rnp|rp|rv|rvpa|rwmi|sal|saps|sasv|sbp|sc|select|set|shcm|si|sl|sleep|sls|sort|sp|spps|spsv|start|sv|swmi|tee|trcm|type|write)\b/i
  35. ],
  36. // per http://technet.microsoft.com/en-us/library/hh847744.aspx
  37. 'keyword': /\b(?:Begin|Break|Catch|Class|Continue|Data|Define|Do|DynamicParam|Else|ElseIf|End|Exit|Filter|Finally|For|ForEach|From|Function|If|InlineScript|Parallel|Param|Process|Return|Sequence|Switch|Throw|Trap|Try|Until|Using|Var|While|Workflow)\b/i,
  38. 'operator': {
  39. pattern: /(^|\W)(?:!|-(?:b?(?:and|x?or)|as|(?:Not)?(?:Contains|In|Like|Match)|eq|ge|gt|is(?:Not)?|Join|le|lt|ne|not|Replace|sh[lr])\b|-[-=]?|\+[+=]?|[*\/%]=?)/i,
  40. lookbehind: true
  41. },
  42. 'punctuation': /[|{}[\];(),.]/
  43. };
  44. // Variable interpolation inside strings, and nested expressions
  45. powershell.string[0].inside = {
  46. 'function': {
  47. // Allow for one level of nesting
  48. pattern: /(^|[^`])\$\((?:\$\([^\r\n()]*\)|(?!\$\()[^\r\n)])*\)/,
  49. lookbehind: true,
  50. inside: powershell
  51. },
  52. 'boolean': powershell.boolean,
  53. 'variable': powershell.variable,
  54. };
  55. }(Prism));