mode-mediawiki.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. ace.define("ace/mode/mediawiki_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var MediaWikiHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. include: "#switch"
  9. }, {
  10. include: "#redirect"
  11. }, {
  12. include: "#variable"
  13. }, {
  14. include: "#comment"
  15. }, {
  16. include: "#entity"
  17. }, {
  18. include: "#emphasis"
  19. }, {
  20. include: "#tag"
  21. }, {
  22. include: "#table"
  23. }, {
  24. include: "#hr"
  25. }, {
  26. include: "#heading"
  27. }, {
  28. include: "#link"
  29. }, {
  30. include: "#list"
  31. }, {
  32. include: "#template"
  33. }],
  34. "#hr": [{
  35. token: "markup.bold",
  36. regex: /^[-]{4,}/
  37. }],
  38. "#switch": [{
  39. token: "constant.language",
  40. regex: /(__NOTOC__|__FORCETOC__|__TOC__|__NOEDITSECTION__|__NEWSECTIONLINK__|__NONEWSECTIONLINK__|__NOWYSIWYG__|__NOGALLERY__|__HIDDENCAT__|__EXPECTUNUSEDCATEGORY__|__NOCONTENTCONVERT__|__NOCC__|__NOTITLECONVERT__|__NOTC__|__START__|__END__|__INDEX__|__NOINDEX__|__STATICREDIRECT__|__NOGLOBAL__|__DISAMBIG__)/
  41. }],
  42. "#redirect": [{
  43. token: [
  44. "keyword.control.redirect",
  45. "meta.keyword.control"
  46. ],
  47. regex: /(^#REDIRECT|^#redirect|^#Redirect)(\s+)/
  48. }],
  49. "#variable": [{
  50. token: "storage.type.variable",
  51. regex: /{{{/,
  52. push: [{
  53. token: "storage.type.variable",
  54. regex: /}}}/,
  55. next: "pop"
  56. }, {
  57. token: [
  58. "text",
  59. "variable.other",
  60. "text",
  61. "keyword.operator"
  62. ],
  63. regex: /(\s*)(\w+)(\s*)((?:\|)?)/
  64. }, {
  65. defaultToken: "storage.type.variable"
  66. }]
  67. }],
  68. "#entity": [{
  69. token: "constant.character.entity",
  70. regex: /&\w+;/
  71. }],
  72. "#list": [{
  73. token: "markup.bold",
  74. regex: /^[#*;:]+/,
  75. push: [{
  76. token: "markup.list",
  77. regex: /$/,
  78. next: "pop"
  79. }, {
  80. include: "$self"
  81. }, {
  82. defaultToken: "markup.list"
  83. }]
  84. }],
  85. "#template": [{
  86. token: [
  87. "storage.type.function",
  88. "meta.template",
  89. "entity.name.function",
  90. "meta.template"
  91. ],
  92. regex: /({{)(\s*)([#\w: ]+)(\s*)/,
  93. push: [{
  94. token: "storage.type.function",
  95. regex: /}}/,
  96. next: "pop"
  97. }, {
  98. token: [
  99. "storage",
  100. "meta.structure.dictionary",
  101. "support.type.property-name",
  102. "meta.structure.dictionary",
  103. "punctuation.separator.dictionary.key-value",
  104. "meta.structure.dictionary",
  105. "meta.structure.dictionary.value"
  106. ],
  107. regex: /(\|)(\s*)([a-zA-Z-]*)(\s*)(=)(\s*)([^|}]*)/,
  108. push: [{
  109. token: "meta.structure.dictionary",
  110. regex: /(?=}}|[|])/,
  111. next: "pop"
  112. }, {
  113. defaultToken: "meta.structure.dictionary"
  114. }]
  115. }, {
  116. token: ["storage", "meta.template.value"],
  117. regex: /(\|)(.*?)/,
  118. push: [{
  119. token: [],
  120. regex: /(?=}}|[|])/,
  121. next: "pop"
  122. }, {
  123. include: "$self"
  124. }, {
  125. defaultToken: "meta.template.value"
  126. }]
  127. }, {
  128. defaultToken: "meta.template"
  129. }]
  130. }],
  131. "#link": [{
  132. token: [
  133. "punctuation.definition.tag.begin",
  134. "meta.tag.link.internal",
  135. "entity.name.tag",
  136. "meta.tag.link.internal",
  137. "string.other.link.title",
  138. "meta.tag.link.internal",
  139. "punctuation.definition.tag"
  140. ],
  141. regex: /(\[\[)(\s*)((?:Category|Wikipedia)?)(:?)([^\]\]\|]+)(\s*)((?:\|)*)/,
  142. push: [{
  143. token: "punctuation.definition.tag.end",
  144. regex: /\]\]/,
  145. next: "pop"
  146. }, {
  147. include: "$self"
  148. }, {
  149. defaultToken: "meta.tag.link.internal"
  150. }]
  151. }, {
  152. token: [
  153. "punctuation.definition.tag.begin",
  154. "meta.tag.link.external",
  155. "meta.tag.link.external",
  156. "string.unquoted",
  157. "punctuation.definition.tag.end"
  158. ],
  159. regex: /(\[)(.*?)([\s]+)(.*?)(\])/
  160. }],
  161. "#comment": [{
  162. token: "punctuation.definition.comment.html",
  163. regex: /<!--/,
  164. push: [{
  165. token: "punctuation.definition.comment.html",
  166. regex: /-->/,
  167. next: "pop"
  168. }, {
  169. defaultToken: "comment.block.html"
  170. }]
  171. }],
  172. "#emphasis": [{
  173. token: [
  174. "punctuation.definition.tag.begin",
  175. "markup.italic.bold",
  176. "punctuation.definition.tag.end"
  177. ],
  178. regex: /(''''')(?!')(.*?)('''''|$)/
  179. }, {
  180. token: [
  181. "punctuation.definition.tag.begin",
  182. "markup.bold",
  183. "punctuation.definition.tag.end"
  184. ],
  185. regex: /(''')(?!')(.*?)('''|$)/
  186. }, {
  187. token: [
  188. "punctuation.definition.tag.begin",
  189. "markup.italic",
  190. "punctuation.definition.tag.end"
  191. ],
  192. regex: /('')(?!')(.*?)(''|$)/
  193. }],
  194. "#heading": [{
  195. token: [
  196. "punctuation.definition.heading",
  197. "entity.name.section",
  198. "punctuation.definition.heading"
  199. ],
  200. regex: /(={1,6})(.+?)(\1)(?!=)/
  201. }],
  202. "#tag": [{
  203. token: [
  204. "punctuation.definition.tag.begin",
  205. "entity.name.tag",
  206. "meta.tag.block.ref",
  207. "punctuation.definition.tag.end"
  208. ],
  209. regex: /(<)(ref)((?:\s+.*?)?)(>)/,
  210. caseInsensitive: true,
  211. push: [{
  212. token: [
  213. "punctuation.definition.tag.begin",
  214. "entity.name.tag",
  215. "meta.tag.block.ref",
  216. "punctuation.definition.tag.end"
  217. ],
  218. regex: /(<\/)(ref)(\s*)(>)/,
  219. caseInsensitive: true,
  220. next: "pop"
  221. }, {
  222. include: "$self"
  223. }, {
  224. defaultToken: "meta.tag.block.ref"
  225. }]
  226. },
  227. {
  228. token: [
  229. "punctuation.definition.tag.begin",
  230. "entity.name.tag",
  231. "meta.tag.block.nowiki",
  232. "punctuation.definition.tag.end"
  233. ],
  234. regex: /(<)(nowiki)((?:\s+.*?)?)(>)/,
  235. caseInsensitive: true,
  236. push: [{
  237. token: [
  238. "punctuation.definition.tag.begin",
  239. "entity.name.tag",
  240. "meta.tag.block.nowiki",
  241. "punctuation.definition.tag.end"
  242. ],
  243. regex: /(<\/)(nowiki)(\s*)(>)/,
  244. caseInsensitive: true,
  245. next: "pop"
  246. }, {
  247. defaultToken: "meta.tag.block.nowiki"
  248. }]
  249. }, {
  250. token: [
  251. "punctuation.definition.tag.begin",
  252. "entity.name.tag"
  253. ],
  254. regex: /(<\/?)(noinclude|includeonly|onlyinclude)(?=\W)/,
  255. caseInsensitive: true,
  256. push: [{
  257. token: [
  258. "invalid.illegal",
  259. "punctuation.definition.tag.end"
  260. ],
  261. regex: /((?:\/)?)(>)/,
  262. next: "pop"
  263. }, {
  264. include: "#attribute"
  265. }, {
  266. defaultToken: "meta.tag.block.any"
  267. }]
  268. }, {
  269. token: [
  270. "punctuation.definition.tag.begin",
  271. "entity.name.tag"
  272. ],
  273. regex: /(<)(br|wbr|hr|meta|link)(?=\W)/,
  274. caseInsensitive: true,
  275. push: [{
  276. token: "punctuation.definition.tag.end",
  277. regex: /\/?>/,
  278. next: "pop"
  279. }, {
  280. include: "#attribute"
  281. }, {
  282. defaultToken: "meta.tag.other"
  283. }]
  284. }, {
  285. token: [
  286. "punctuation.definition.tag.begin",
  287. "entity.name.tag"
  288. ],
  289. regex: /(<\/?)(div|center|span|h1|h2|h3|h4|h5|h6|bdo|em|strong|cite|dfn|code|samp|kbd|var|abbr|blockquote|q|sub|sup|p|pre|ins|del|ul|ol|li|dl|dd|dt|table|caption|thead|tfoot|tbody|colgroup|col|tr|td|th|a|img|video|source|track|tt|b|i|big|small|strike|s|u|font|ruby|rb|rp|rt|rtc|math|figure|figcaption|bdi|data|time|mark|html)(?=\W)/,
  290. caseInsensitive: true,
  291. push: [{
  292. token: [
  293. "invalid.illegal",
  294. "punctuation.definition.tag.end"
  295. ],
  296. regex: /((?:\/)?)(>)/,
  297. next: "pop"
  298. }, {
  299. include: "#attribute"
  300. }, {
  301. defaultToken: "meta.tag.block"
  302. }]
  303. }, {
  304. token: [
  305. "punctuation.definition.tag.begin",
  306. "invalid.illegal"
  307. ],
  308. regex: /(<\/)(br|wbr|hr|meta|link)(?=\W)/,
  309. caseInsensitive: true,
  310. push: [{
  311. token: "punctuation.definition.tag.end",
  312. regex: /\/?>/,
  313. next: "pop"
  314. }, {
  315. include: "#attribute"
  316. }, {
  317. defaultToken: "meta.tag.other"
  318. }]
  319. }],
  320. "#caption": [{
  321. token: [
  322. "meta.tag.block.table-caption",
  323. "punctuation.definition.tag.begin"
  324. ],
  325. regex: /^(\s*)(\|\+)/,
  326. push: [{
  327. token: "meta.tag.block.table-caption",
  328. regex: /$/,
  329. next: "pop"
  330. }, {
  331. defaultToken: "meta.tag.block.table-caption"
  332. }]
  333. }],
  334. "#tr": [{
  335. token: [
  336. "meta.tag.block.tr",
  337. "punctuation.definition.tag.begin",
  338. "meta.tag.block.tr",
  339. "invalid.illegal"
  340. ],
  341. regex: /^(\s*)(\|\-)([\s]*)(.*)/
  342. }],
  343. "#th": [{
  344. token: [
  345. "meta.tag.block.th.heading",
  346. "punctuation.definition.tag.begin",
  347. "meta.tag.block.th.heading",
  348. "punctuation.definition.tag",
  349. "markup.bold"
  350. ],
  351. regex: /^(\s*)(!)(?:(.*?)(\|))?(.*?)(?=!!|$)/,
  352. push: [{
  353. token: "meta.tag.block.th.heading",
  354. regex: /$/,
  355. next: "pop"
  356. }, {
  357. token: [
  358. "punctuation.definition.tag.begin",
  359. "meta.tag.block.th.inline",
  360. "punctuation.definition.tag",
  361. "markup.bold"
  362. ],
  363. regex: /(!!)(?:(.*?)(\|))?(.*?)(?=!!|$)/
  364. }, {
  365. include: "$self"
  366. }, {
  367. defaultToken: "meta.tag.block.th.heading"
  368. }]
  369. }],
  370. "#td": [{
  371. token: [
  372. "meta.tag.block.td",
  373. "punctuation.definition.tag.begin"
  374. ],
  375. regex: /^(\s*)(\|)/,
  376. push: [{
  377. token: "meta.tag.block.td",
  378. regex: /$/,
  379. next: "pop"
  380. }, {
  381. include: "$self"
  382. }, {
  383. defaultToken: "meta.tag.block.td"
  384. }]
  385. }],
  386. "#table": [{
  387. patterns: [{
  388. name: "meta.tag.block.table",
  389. begin: "^\\s*({\\|)(.*?)$",
  390. end: "^\\s*\\|}",
  391. beginCaptures: {
  392. 1: {
  393. name: "punctuation.definition.tag.begin"
  394. },
  395. 2: {
  396. patterns: [{
  397. include: "#attribute"
  398. }]
  399. },
  400. 3: {
  401. name: "invalid.illegal"
  402. }
  403. },
  404. endCaptures: {
  405. 0: {
  406. name: "punctuation.definition.tag.end"
  407. }
  408. },
  409. patterns: [{
  410. include: "#comment"
  411. }, {
  412. include: "#template"
  413. }, {
  414. include: "#caption"
  415. }, {
  416. include: "#tr"
  417. }, {
  418. include: "#th"
  419. }, {
  420. include: "#td"
  421. }]
  422. }],
  423. repository: {
  424. caption: {
  425. name: "meta.tag.block.table-caption",
  426. begin: "^\\s*(\\|\\+)",
  427. end: "$",
  428. beginCaptures: {
  429. 1: {
  430. name: "punctuation.definition.tag.begin"
  431. }
  432. }
  433. },
  434. tr: {
  435. name: "meta.tag.block.tr",
  436. match: "^\\s*(\\|\\-)[\\s]*(.*)",
  437. captures: {
  438. 1: {
  439. name: "punctuation.definition.tag.begin"
  440. },
  441. 2: {
  442. name: "invalid.illegal"
  443. }
  444. }
  445. },
  446. th: {
  447. name: "meta.tag.block.th.heading",
  448. begin: "^\\s*(!)((.*?)(\\|))?(.*?)(?=(!!)|$)",
  449. end: "$",
  450. beginCaptures: {
  451. 1: {
  452. name: "punctuation.definition.tag.begin"
  453. },
  454. 3: {
  455. patterns: [{
  456. include: "#attribute"
  457. }]
  458. },
  459. 4: {
  460. name: "punctuation.definition.tag"
  461. },
  462. 5: {
  463. name: "markup.bold"
  464. }
  465. },
  466. patterns: [{
  467. name: "meta.tag.block.th.inline",
  468. match: "(!!)((.*?)(\\|))?(.*?)(?=(!!)|$)",
  469. captures: {
  470. 1: {
  471. name: "punctuation.definition.tag.begin"
  472. },
  473. 3: {
  474. patterns: [{
  475. include: "#attribute"
  476. }]
  477. },
  478. 4: {
  479. name: "punctuation.definition.tag"
  480. },
  481. 5: {
  482. name: "markup.bold"
  483. }
  484. }
  485. }, {
  486. include: "$self"
  487. }]
  488. },
  489. td: {
  490. name: "meta.tag.block.td",
  491. begin: "^\\s*(\\|)",
  492. end: "$",
  493. beginCaptures: {
  494. 1: {
  495. name: "punctuation.definition.tag.begin"
  496. },
  497. 2: {
  498. patterns: [{
  499. include: "#attribute"
  500. }]
  501. },
  502. 3: {
  503. name: "punctuation.definition.tag"
  504. }
  505. },
  506. patterns: [{
  507. include: "$self"
  508. }]
  509. }
  510. }
  511. }],
  512. "#attribute": [{
  513. include: "#string"
  514. }, {
  515. token: "entity.other.attribute-name",
  516. regex: /\w+/
  517. }],
  518. "#string": [{
  519. token: "string.quoted.double",
  520. regex: /\"/,
  521. push: [{
  522. token: "string.quoted.double",
  523. regex: /\"/,
  524. next: "pop"
  525. }, {
  526. defaultToken: "string.quoted.double"
  527. }]
  528. }, {
  529. token: "string.quoted.single",
  530. regex: /\'/,
  531. push: [{
  532. token: "string.quoted.single",
  533. regex: /\'/,
  534. next: "pop"
  535. }, {
  536. defaultToken: "string.quoted.single"
  537. }]
  538. }],
  539. "#url": [{
  540. token: "markup.underline.link",
  541. regex: /(?:http(?:s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:\/?#\[\]@!\$&'\(\)\*\+,;=.]+/
  542. }, {
  543. token: "invalid.illegal",
  544. regex: /.*/
  545. }]
  546. };
  547. this.normalizeRules();
  548. };
  549. MediaWikiHighlightRules.metaData = {
  550. name: "MediaWiki",
  551. scopeName: "text.html.mediawiki",
  552. fileTypes: ["mediawiki", "wiki"]
  553. };
  554. oop.inherits(MediaWikiHighlightRules, TextHighlightRules);
  555. exports.MediaWikiHighlightRules = MediaWikiHighlightRules;
  556. });
  557. ace.define("ace/mode/mediawiki",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/mediawiki_highlight_rules"], function(require, exports, module) {
  558. "use strict";
  559. var oop = require("../lib/oop");
  560. var TextMode = require("./text").Mode;
  561. var MediaWikiHighlightRules = require("./mediawiki_highlight_rules").MediaWikiHighlightRules;
  562. var Mode = function() {
  563. this.HighlightRules = MediaWikiHighlightRules;
  564. };
  565. oop.inherits(Mode, TextMode);
  566. (function() {
  567. this.type = "text";
  568. this.blockComment = {start: "<!--", end: "-->"};
  569. this.$id = "ace/mode/mediawiki";
  570. }).call(Mode.prototype);
  571. exports.Mode = Mode;
  572. }); (function() {
  573. ace.require(["ace/mode/mediawiki"], function(m) {
  574. if (typeof module == "object" && typeof exports == "object" && module) {
  575. module.exports = m;
  576. }
  577. });
  578. })();