django.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. Language: Django
  3. Description: Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.
  4. Requires: xml.js
  5. Author: Ivan Sagalaev <maniac@softwaremaniacs.org>
  6. Contributors: Ilya Baryshev <baryshev@gmail.com>
  7. Website: https://www.djangoproject.com
  8. Category: template
  9. */
  10. /** @type LanguageFn */
  11. function django(hljs) {
  12. const FILTER = {
  13. begin: /\|[A-Za-z]+:?/,
  14. keywords: {
  15. name:
  16. 'truncatewords removetags linebreaksbr yesno get_digit timesince random striptags ' +
  17. 'filesizeformat escape linebreaks length_is ljust rjust cut urlize fix_ampersands ' +
  18. 'title floatformat capfirst pprint divisibleby add make_list unordered_list urlencode ' +
  19. 'timeuntil urlizetrunc wordcount stringformat linenumbers slice date dictsort ' +
  20. 'dictsortreversed default_if_none pluralize lower join center default ' +
  21. 'truncatewords_html upper length phone2numeric wordwrap time addslashes slugify first ' +
  22. 'escapejs force_escape iriencode last safe safeseq truncatechars localize unlocalize ' +
  23. 'localtime utc timezone'
  24. },
  25. contains: [
  26. hljs.QUOTE_STRING_MODE,
  27. hljs.APOS_STRING_MODE
  28. ]
  29. };
  30. return {
  31. name: 'Django',
  32. aliases: ['jinja'],
  33. case_insensitive: true,
  34. subLanguage: 'xml',
  35. contains: [
  36. hljs.COMMENT(/\{%\s*comment\s*%\}/, /\{%\s*endcomment\s*%\}/),
  37. hljs.COMMENT(/\{#/, /#\}/),
  38. {
  39. className: 'template-tag',
  40. begin: /\{%/,
  41. end: /%\}/,
  42. contains: [{
  43. className: 'name',
  44. begin: /\w+/,
  45. keywords: {
  46. name:
  47. 'comment endcomment load templatetag ifchanged endifchanged if endif firstof for ' +
  48. 'endfor ifnotequal endifnotequal widthratio extends include spaceless ' +
  49. 'endspaceless regroup ifequal endifequal ssi now with cycle url filter ' +
  50. 'endfilter debug block endblock else autoescape endautoescape csrf_token empty elif ' +
  51. 'endwith static trans blocktrans endblocktrans get_static_prefix get_media_prefix ' +
  52. 'plural get_current_language language get_available_languages ' +
  53. 'get_current_language_bidi get_language_info get_language_info_list localize ' +
  54. 'endlocalize localtime endlocaltime timezone endtimezone get_current_timezone ' +
  55. 'verbatim'
  56. },
  57. starts: {
  58. endsWithParent: true,
  59. keywords: 'in by as',
  60. contains: [FILTER],
  61. relevance: 0
  62. }
  63. }]
  64. },
  65. {
  66. className: 'template-variable',
  67. begin: /\{\{/,
  68. end: /\}\}/,
  69. contains: [FILTER]
  70. }
  71. ]
  72. };
  73. }
  74. module.exports = django;