prism-wiki.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Prism.languages.wiki = Prism.languages.extend('markup', {
  2. 'block-comment': {
  3. pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
  4. lookbehind: true,
  5. alias: 'comment'
  6. },
  7. 'heading': {
  8. pattern: /^(=+)[^=\r\n].*?\1/m,
  9. inside: {
  10. 'punctuation': /^=+|=+$/,
  11. 'important': /.+/
  12. }
  13. },
  14. 'emphasis': {
  15. // TODO Multi-line
  16. pattern: /('{2,5}).+?\1/,
  17. inside: {
  18. 'bold-italic': {
  19. pattern: /(''''').+?(?=\1)/,
  20. lookbehind: true,
  21. alias: ['bold', 'italic']
  22. },
  23. 'bold': {
  24. pattern: /(''')[^'](?:.*?[^'])?(?=\1)/,
  25. lookbehind: true
  26. },
  27. 'italic': {
  28. pattern: /('')[^'](?:.*?[^'])?(?=\1)/,
  29. lookbehind: true
  30. },
  31. 'punctuation': /^''+|''+$/
  32. }
  33. },
  34. 'hr': {
  35. pattern: /^-{4,}/m,
  36. alias: 'punctuation'
  37. },
  38. 'url': [
  39. /ISBN +(?:97[89][ -]?)?(?:\d[ -]?){9}[\dx]\b|(?:PMID|RFC) +\d+/i,
  40. /\[\[.+?\]\]|\[.+?\]/
  41. ],
  42. 'variable': [
  43. /__[A-Z]+__/,
  44. // FIXME Nested structures should be handled
  45. // {{formatnum:{{#expr:{{{3}}}}}}}
  46. /\{{3}.+?\}{3}/,
  47. /\{\{.+?\}\}/
  48. ],
  49. 'symbol': [
  50. /^#redirect/im,
  51. /~{3,5}/
  52. ],
  53. // Handle table attrs:
  54. // {|
  55. // ! style="text-align:left;"| Item
  56. // |}
  57. 'table-tag': {
  58. pattern: /((?:^|[|!])[|!])[^|\r\n]+\|(?!\|)/m,
  59. lookbehind: true,
  60. inside: {
  61. 'table-bar': {
  62. pattern: /\|$/,
  63. alias: 'punctuation'
  64. },
  65. rest: Prism.languages.markup['tag'].inside
  66. }
  67. },
  68. 'punctuation': /^(?:\{\||\|\}|\|-|[*#:;!|])|\|\||!!/m
  69. });
  70. Prism.languages.insertBefore('wiki', 'tag', {
  71. // Prevent highlighting inside <nowiki>, <source> and <pre> tags
  72. 'nowiki': {
  73. pattern: /<(nowiki|pre|source)\b[^>]*>[\s\S]*?<\/\1>/i,
  74. inside: {
  75. 'tag': {
  76. pattern: /<(?:nowiki|pre|source)\b[^>]*>|<\/(?:nowiki|pre|source)>/i,
  77. inside: Prism.languages.markup['tag'].inside
  78. }
  79. }
  80. }
  81. });