markdown.js 2.3 KB

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