markdown.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. Language: Markdown
  3. Requires: xml.js
  4. Author: John Crepezzi <[email protected]>
  5. Website: http://seejohncode.com/
  6. Category: common, markup
  7. */
  8. function(hljs) {
  9. return {
  10. aliases: ['md', 'mkdown', 'mkd'],
  11. contains: [
  12. // highlight headers
  13. {
  14. className: 'section',
  15. variants: [
  16. { begin: '^#{1,6}', end: '$' },
  17. { begin: '^.+?\\n[=-]{2,}$' }
  18. ]
  19. },
  20. // inline html
  21. {
  22. begin: '<', end: '>',
  23. subLanguage: 'xml',
  24. relevance: 0
  25. },
  26. // lists (indicators only)
  27. {
  28. className: 'bullet',
  29. begin: '^([*+-]|(\\d+\\.))\\s+'
  30. },
  31. // strong segments
  32. {
  33. className: 'strong',
  34. begin: '[*_]{2}.+?[*_]{2}'
  35. },
  36. // emphasis segments
  37. {
  38. className: 'emphasis',
  39. variants: [
  40. { begin: '\\*.+?\\*' },
  41. { begin: '_.+?_'
  42. , relevance: 0
  43. }
  44. ]
  45. },
  46. // blockquotes
  47. {
  48. className: 'quote',
  49. begin: '^>\\s+', end: '$'
  50. },
  51. // code snippets
  52. {
  53. className: 'code',
  54. variants: [
  55. {
  56. begin: '^```\w*\s*$', end: '^```\s*$'
  57. },
  58. {
  59. begin: '`.+?`'
  60. },
  61. {
  62. begin: '^( {4}|\t)', end: '$',
  63. relevance: 0
  64. }
  65. ]
  66. },
  67. // horizontal rules
  68. {
  69. begin: '^[-\\*]{3,}', end: '$'
  70. },
  71. // using links - title and link
  72. {
  73. begin: '\\[.+?\\][\\(\\[].*?[\\)\\]]',
  74. returnBegin: true,
  75. contains: [
  76. {
  77. className: 'string',
  78. begin: '\\[', end: '\\]',
  79. excludeBegin: true,
  80. returnEnd: true,
  81. relevance: 0
  82. },
  83. {
  84. className: 'link',
  85. begin: '\\]\\(', end: '\\)',
  86. excludeBegin: true, excludeEnd: true
  87. },
  88. {
  89. className: 'symbol',
  90. begin: '\\]\\[', end: '\\]',
  91. excludeBegin: true, excludeEnd: true
  92. }
  93. ],
  94. relevance: 10
  95. },
  96. {
  97. begin: /^\[[^\n]+\]:/,
  98. returnBegin: true,
  99. contains: [
  100. {
  101. className: 'symbol',
  102. begin: /\[/, end: /\]/,
  103. excludeBegin: true, excludeEnd: true
  104. },
  105. {
  106. className: 'link',
  107. begin: /:\s*/, end: /$/,
  108. excludeBegin: true
  109. }
  110. ]
  111. }
  112. ]
  113. };
  114. }