shBrushPython.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * SyntaxHighlighter
  3. * http://alexgorbatchev.com/
  4. *
  5. * SyntaxHighlighter is donationware. If you are using it, please donate.
  6. * http://alexgorbatchev.com/wiki/SyntaxHighlighter:Donate
  7. *
  8. * @version
  9. * 2.1.364 (October 15 2009)
  10. *
  11. * @copyright
  12. * Copyright (C) 2004-2009 Alex Gorbatchev.
  13. *
  14. * @license
  15. * This file is part of SyntaxHighlighter.
  16. *
  17. * SyntaxHighlighter is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Lesser General Public License as published by
  19. * the Free Software Foundation, either version 3 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * SyntaxHighlighter is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with SyntaxHighlighter. If not, see <http://www.gnu.org/copyleft/lesser.html>.
  29. */
  30. SyntaxHighlighter.brushes.Python = function()
  31. {
  32. // Contributed by Gheorghe Milas and Ahmad Sherif
  33. var keywords = 'and assert break class continue def del elif else ' +
  34. 'except exec finally for from global if import in is ' +
  35. 'lambda not or pass print raise return try yield while';
  36. var funcs = '__import__ abs all any apply basestring bin bool buffer callable ' +
  37. 'chr classmethod cmp coerce compile complex delattr dict dir ' +
  38. 'divmod enumerate eval execfile file filter float format frozenset ' +
  39. 'getattr globals hasattr hash help hex id input int intern ' +
  40. 'isinstance issubclass iter len list locals long map max min next ' +
  41. 'object oct open ord pow print property range raw_input reduce ' +
  42. 'reload repr reversed round set setattr slice sorted staticmethod ' +
  43. 'str sum super tuple type type unichr unicode vars xrange zip';
  44. var special = 'None True False self cls class_';
  45. this.regexList = [
  46. { regex: SyntaxHighlighter.regexLib.singleLinePerlComments, css: 'comments' },
  47. { regex: /^\s*@\w+/gm, css: 'decorator' },
  48. { regex: /(['\"]{3})([^\1])*?\1/gm, css: 'comments' },
  49. { regex: /"(?!")(?:\.|\\\"|[^\""\n])*"/gm, css: 'string' },
  50. { regex: /'(?!')(?:\.|(\\\')|[^\''\n])*'/gm, css: 'string' },
  51. { regex: /\+|\-|\*|\/|\%|=|==/gm, css: 'keyword' },
  52. { regex: /\b\d+\.?\w*/g, css: 'value' },
  53. { regex: new RegExp(this.getKeywords(funcs), 'gmi'), css: 'functions' },
  54. { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' },
  55. { regex: new RegExp(this.getKeywords(special), 'gm'), css: 'color1' }
  56. ];
  57. this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
  58. };
  59. SyntaxHighlighter.brushes.Python.prototype = new SyntaxHighlighter.Highlighter();
  60. SyntaxHighlighter.brushes.Python.aliases = ['py', 'python'];