asciidoc.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. module.exports = function(hljs) {
  2. return {
  3. aliases: ['adoc'],
  4. contains: [
  5. // block comment
  6. hljs.COMMENT(
  7. '^/{4,}\\n',
  8. '\\n/{4,}$',
  9. // can also be done as...
  10. //'^/{4,}$',
  11. //'^/{4,}$',
  12. {
  13. relevance: 10
  14. }
  15. ),
  16. // line comment
  17. hljs.COMMENT(
  18. '^//',
  19. '$',
  20. {
  21. relevance: 0
  22. }
  23. ),
  24. // title
  25. {
  26. className: 'title',
  27. begin: '^\\.\\w.*$'
  28. },
  29. // example, admonition & sidebar blocks
  30. {
  31. begin: '^[=\\*]{4,}\\n',
  32. end: '\\n^[=\\*]{4,}$',
  33. relevance: 10
  34. },
  35. // headings
  36. {
  37. className: 'section',
  38. relevance: 10,
  39. variants: [
  40. {begin: '^(={1,5}) .+?( \\1)?$'},
  41. {begin: '^[^\\[\\]\\n]+?\\n[=\\-~\\^\\+]{2,}$'},
  42. ]
  43. },
  44. // document attributes
  45. {
  46. className: 'meta',
  47. begin: '^:.+?:',
  48. end: '\\s',
  49. excludeEnd: true,
  50. relevance: 10
  51. },
  52. // block attributes
  53. {
  54. className: 'meta',
  55. begin: '^\\[.+?\\]$',
  56. relevance: 0
  57. },
  58. // quoteblocks
  59. {
  60. className: 'quote',
  61. begin: '^_{4,}\\n',
  62. end: '\\n_{4,}$',
  63. relevance: 10
  64. },
  65. // listing and literal blocks
  66. {
  67. className: 'code',
  68. begin: '^[\\-\\.]{4,}\\n',
  69. end: '\\n[\\-\\.]{4,}$',
  70. relevance: 10
  71. },
  72. // passthrough blocks
  73. {
  74. begin: '^\\+{4,}\\n',
  75. end: '\\n\\+{4,}$',
  76. contains: [
  77. {
  78. begin: '<', end: '>',
  79. subLanguage: 'xml',
  80. relevance: 0
  81. }
  82. ],
  83. relevance: 10
  84. },
  85. // lists (can only capture indicators)
  86. {
  87. className: 'bullet',
  88. begin: '^(\\*+|\\-+|\\.+|[^\\n]+?::)\\s+'
  89. },
  90. // admonition
  91. {
  92. className: 'symbol',
  93. begin: '^(NOTE|TIP|IMPORTANT|WARNING|CAUTION):\\s+',
  94. relevance: 10
  95. },
  96. // inline strong
  97. {
  98. className: 'strong',
  99. // must not follow a word character or be followed by an asterisk or space
  100. begin: '\\B\\*(?![\\*\\s])',
  101. end: '(\\n{2}|\\*)',
  102. // allow escaped asterisk followed by word char
  103. contains: [
  104. {
  105. begin: '\\\\*\\w',
  106. relevance: 0
  107. }
  108. ]
  109. },
  110. // inline emphasis
  111. {
  112. className: 'emphasis',
  113. // must not follow a word character or be followed by a single quote or space
  114. begin: '\\B\'(?![\'\\s])',
  115. end: '(\\n{2}|\')',
  116. // allow escaped single quote followed by word char
  117. contains: [
  118. {
  119. begin: '\\\\\'\\w',
  120. relevance: 0
  121. }
  122. ],
  123. relevance: 0
  124. },
  125. // inline emphasis (alt)
  126. {
  127. className: 'emphasis',
  128. // must not follow a word character or be followed by an underline or space
  129. begin: '_(?![_\\s])',
  130. end: '(\\n{2}|_)',
  131. relevance: 0
  132. },
  133. // inline smart quotes
  134. {
  135. className: 'string',
  136. variants: [
  137. {begin: "``.+?''"},
  138. {begin: "`.+?'"}
  139. ]
  140. },
  141. // inline code snippets (TODO should get same treatment as strong and emphasis)
  142. {
  143. className: 'code',
  144. begin: '(`.+?`|\\+.+?\\+)',
  145. relevance: 0
  146. },
  147. // indented literal block
  148. {
  149. className: 'code',
  150. begin: '^[ \\t]',
  151. end: '$',
  152. relevance: 0
  153. },
  154. // horizontal rules
  155. {
  156. begin: '^\'{3,}[ \\t]*$',
  157. relevance: 10
  158. },
  159. // images and links
  160. {
  161. begin: '(link:)?(http|https|ftp|file|irc|image:?):\\S+\\[.*?\\]',
  162. returnBegin: true,
  163. contains: [
  164. {
  165. begin: '(link|image:?):',
  166. relevance: 0
  167. },
  168. {
  169. className: 'link',
  170. begin: '\\w',
  171. end: '[^\\[]+',
  172. relevance: 0
  173. },
  174. {
  175. className: 'string',
  176. begin: '\\[',
  177. end: '\\]',
  178. excludeBegin: true,
  179. excludeEnd: true,
  180. relevance: 0
  181. }
  182. ],
  183. relevance: 10
  184. }
  185. ]
  186. };
  187. };