prism-wiki.js 1.5 KB

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