asciidoc.js 4.5 KB

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