shBrushPython.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * SyntaxHighlighter
  3. * http://alexgorbatchev.com/SyntaxHighlighter
  4. *
  5. * SyntaxHighlighter is donationware. If you are using it, please donate.
  6. * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
  7. *
  8. * @version
  9. * 3.0.83 (July 02 2010)
  10. *
  11. * @copyright
  12. * Copyright (C) 2004-2010 Alex Gorbatchev.
  13. *
  14. * @license
  15. * Dual licensed under the MIT and GPL licenses.
  16. */
  17. ;(function()
  18. {
  19. // CommonJS
  20. typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;
  21. function Brush()
  22. {
  23. // Contributed by Gheorghe Milas and Ahmad Sherif
  24. var keywords = 'and assert break class continue def del elif else ' +
  25. 'except exec finally for from global if import in is ' +
  26. 'lambda not or pass print raise return try yield while';
  27. var funcs = '__import__ abs all any apply basestring bin bool buffer callable ' +
  28. 'chr classmethod cmp coerce compile complex delattr dict dir ' +
  29. 'divmod enumerate eval execfile file filter float format frozenset ' +
  30. 'getattr globals hasattr hash help hex id input int intern ' +
  31. 'isinstance issubclass iter len list locals long map max min next ' +
  32. 'object oct open ord pow print property range raw_input reduce ' +
  33. 'reload repr reversed round set setattr slice sorted staticmethod ' +
  34. 'str sum super tuple type type unichr unicode vars xrange zip';
  35. var special = 'None True False self cls class_';
  36. this.regexList = [
  37. { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
  38. { regex: /^\s*@\w+/gm, css: 'decorator' },
  39. { regex: /(['\"]{3})([^\1])*?\1/gm, css: 'comments' },
  40. { regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm, css: 'string' },
  41. { regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm, css: 'string' },
  42. { regex: /\+|\-|\*|\/|\%|=|==/gm, css: 'keyword' },
  43. { regex: /\b\d+\.?\w*/g, css: 'value' },
  44. { regex: new RegExp(this.getKeywords(funcs), 'gmi'), css: 'functions' },
  45. { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' },
  46. { regex: new RegExp(this.getKeywords(special), 'gm'), css: 'color1' }
  47. ];
  48. this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
  49. };
  50. Brush.prototype = new SyntaxHighlighter.Highlighter();
  51. Brush.aliases = ['py', 'python'];
  52. SyntaxHighlighter.brushes.Python = Brush;
  53. // CommonJS
  54. typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
  55. })();