asciidoc.js 4.4 KB

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