prism-shell-session.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. (function (Prism) {
  2. // CAREFUL!
  3. // The following patterns are concatenated, so the group referenced by a back reference is non-obvious!
  4. var strings = [
  5. // normal string
  6. // 1 capturing group
  7. /(["'])(?:\\[\s\S]|\$\([^)]+\)|`[^`]+`|(?!\1)[^\\])*\1/.source,
  8. // here doc
  9. // 2 capturing groups
  10. /<<-?\s*(["']?)(\w+)\2\s[\s\S]*?[\r\n]\3/.source
  11. ].join('|');
  12. Prism.languages['shell-session'] = {
  13. 'info': {
  14. // foo@bar:~/files$ exit
  15. // foo@bar$ exit
  16. pattern: /^[^\r\n$#*!]+(?=[$#])/m,
  17. alias: 'punctuation',
  18. inside: {
  19. 'path': {
  20. pattern: /(:)[\s\S]+/,
  21. lookbehind: true
  22. },
  23. 'user': /^[^\s@:$#*!/\\]+@[^\s@:$#*!/\\]+(?=:|$)/,
  24. 'punctuation': /:/
  25. }
  26. },
  27. 'command': {
  28. pattern: RegExp(/[$#](?:[^\\\r\n'"<]|\\.|<<str>>)+/.source.replace(/<<str>>/g, function () { return strings; })),
  29. greedy: true,
  30. inside: {
  31. 'bash': {
  32. pattern: /(^[$#]\s*)[\s\S]+/,
  33. lookbehind: true,
  34. alias: 'language-bash',
  35. inside: Prism.languages.bash
  36. },
  37. 'shell-symbol': {
  38. pattern: /^[$#]/,
  39. alias: 'important'
  40. }
  41. }
  42. },
  43. 'output': /.(?:.*(?:[\r\n]|.$))*/
  44. };
  45. Prism.languages['sh-session'] = Prism.languages['shellsession'] = Prism.languages['shell-session'];
  46. }(Prism));