You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

2002 lines
84 KiB

  1. function parse_wikitext(id) {
  2. if (ckgedit_dwedit_reject) {
  3. var dom = GetE('ebut_cancel');
  4. dom.click();
  5. return true;
  6. }
  7. var useComplexTables = getComplexTables();
  8. function fontConflict() {
  9. var regex = /\>\s+(\*\*|__|\/\/|'')\s+_\s+\1\s+<\/font>/gm;
  10. results = results.replace(regex, function(m) {
  11. m = m.replace(/\s+/g, "");
  12. return m;
  13. });
  14. regex = new RegExp("\\>(.*?)(\\]\\]\\<\\/font\\>)|(\\<\\/font\\>\\]\\])", "gm");
  15. if (results.match(regex)) return true;
  16. regex = new RegExp("(\\{\\{(.*?)\\.\\w{2,4})\\|\\<font");
  17. if (results.match(regex)) return true;
  18. regex = new RegExp("\\{\\{(.*?)\\.\\w{2,4}\\|[:\\w\\-\\.\\s]+\\<\\/font");
  19. if (results.match(regex)) return true;
  20. regex = new RegExp('\\>\\{\\{(.*?)\\.\\w+\\<\\/font\\>\\b', 'gm');
  21. if (results.match(regex)) return true;
  22. return false;
  23. }
  24. /**
  25. table debugging code;
  26. */
  27. function check_rowspans(rows, start_row, ini) {
  28. var tmp = new Array();
  29. for (var i = start_row; i < rows.length; i++) {
  30. for (var col = 0; col < rows[i].length; col++) {
  31. if (rows[i][col].rowspan > 0) {
  32. var _text = rows[i][col].text;
  33. tmp.push({
  34. row: i,
  35. column: col,
  36. spans: rows[i][col].rowspan,
  37. text: _text
  38. });
  39. if (!ini) break;
  40. }
  41. }
  42. }
  43. return tmp;
  44. }
  45. function insert_rowspan(row, col, spans, rows, shift) {
  46. var prev_colspans = rows[row][col].colspan ? rows[row][col].colspan : 0;
  47. rows[row][col].rowspan = 0;
  48. for (i = 0; i < spans - 1; i++) {
  49. //debug_row(rows,row,col,"insert_rowspan start");
  50. rows[++row].splice(col, 0, {
  51. type: 'td',
  52. rowspan: 0,
  53. colspan: prev_colspans,
  54. prev_colspan: prev_colspans,
  55. text: " ::: "
  56. });
  57. }
  58. }
  59. function reorder_span_rows(rows) {
  60. var tmp_start = check_rowspans(rows, 0, true);
  61. var num_spans = tmp_start.length;
  62. if (!num_spans) return false;
  63. var row = tmp_start[0].row;
  64. var col = tmp_start[0].column;
  65. insert_rowspan(row, col, tmp_start[0].spans, rows);
  66. num_spans--;
  67. for (var i = 0; i < num_spans; i++) {
  68. row++;
  69. var tmp = check_rowspans(rows, row, false);
  70. if (tmp.length) {
  71. insert_rowspan(tmp[0].row, tmp[0].column, tmp[0].spans, rows);
  72. }
  73. }
  74. return true;
  75. }
  76. function insert_table(rows) {
  77. if (!useComplexTables) return;
  78. for (var i = 0; i < rows.length; i++) {
  79. if (!reorder_span_rows(rows)) break;;
  80. }
  81. results += "\n";
  82. for (var i = 0; i < rows.length; i++) {
  83. results += "\n";
  84. for (var col = 0; col < rows[i].length; col++) {
  85. var type = rows[i][col].type == 'td' ? '|' : '^';
  86. results += type;
  87. var align = rows[i][col].align ? rows[i][col].align : false;
  88. if (align == 'center' || align == 'right') {
  89. results += " ";
  90. }
  91. results += rows[i][col].text;
  92. if (align == 'center' || align == 'left') {
  93. results += " ";
  94. }
  95. if (rows[i][col].colspan) {
  96. for (var n = 0; n < rows[i][col].colspan - 1; n++) {
  97. results += type;
  98. }
  99. }
  100. }
  101. results += '|';
  102. }
  103. }
  104. window.dwfckTextChanged = false;
  105. if (id != 'bakup') draft_delete();
  106. var line_break = "\nL_BR_K \n";
  107. var markup = {
  108. 'b': '**',
  109. 'i': '//',
  110. 'em': '//',
  111. 'u': '__',
  112. 'br': line_break,
  113. 'strike': '<del>',
  114. 'del': '<del>',
  115. 's': '<del>',
  116. p: "\n\n",
  117. 'a': '[[',
  118. 'img': '\{\{',
  119. 'strong': '**',
  120. 'h1': "\n====== ",
  121. 'h2': "\n===== ",
  122. 'h3': "\n==== ",
  123. 'h4': "\n=== ",
  124. 'h5': "\n== ",
  125. 'td': "|",
  126. 'th': "^",
  127. 'tr': " ",
  128. 'table': "\n\n",
  129. 'ol': " - ",
  130. 'ul': " * ",
  131. 'li': "",
  132. 'code': "\'\'",
  133. 'pre': "\n<",
  134. 'hr': "\n\n----\n\n",
  135. 'sub': '<sub>',
  136. 'font': "",
  137. 'blockquote': '<blockquote>',
  138. 'sup': '<sup>',
  139. 'div': "\n\n",
  140. 'span': "\n",
  141. 'dl': "\n",
  142. 'dd': "\n",
  143. 'dt': "\n"
  144. };
  145. var markup_end = {
  146. 'del': '</del>',
  147. 's': '</del>',
  148. 'strike': '</del>',
  149. 'p': " ",
  150. 'br': " ",
  151. 'a': ']]',
  152. 'img': '\}\}',
  153. 'h1': " ======\n",
  154. 'h2': " =====\n",
  155. 'h3': " ====\n",
  156. 'h4': " ===\n",
  157. 'h5': " ==\n",
  158. 'td': " ",
  159. 'th': " ",
  160. 'tr': "|\n",
  161. 'ol': " ",
  162. 'ul': " ",
  163. 'li': "\n",
  164. 'pre': "\n</",
  165. 'sub': '</sub>',
  166. 'sup': '</sup> ',
  167. 'div': "\n\n",
  168. 'p': "\n\n",
  169. 'font': "</font>",
  170. 'span': " ",
  171. 'blockquote': '</blockquote>',
  172. };
  173. markup['temp_u'] = "CKGE_TMP_u";
  174. markup['temp_strong'] = "CKGE_TMP_strong";
  175. markup['temp_em'] = "CKGE_TMP_em";
  176. markup['temp_i'] = "CKGE_TMP_i";
  177. markup['temp_b'] = "CKGE_TMP_b";
  178. markup['temp_del'] = "CKGE_TMP_del";
  179. markup['temp_strike'] = "CKGE_TMP_strike";
  180. markup['temp_code'] = "CKGE_TMP_code";
  181. markup['temp_sup'] = "CKGE_TMP_sup";
  182. markup['temp_csup'] = "CKGE_TMP_csup";
  183. markup['temp_sub'] = "CKGE_TMP_sub";
  184. markup['temp_csub'] = "CKGE_TMP_csub";
  185. markup['temp_del'] = "CKGE_TMP_del";
  186. markup['temp_cdel'] = "CKGE_TMP_cdel";
  187. markup['temp_strike'] = "CKGE_TMP_del";
  188. markup['temp_cstrike'] = "CKGE_TMP_cdel";
  189. markup['temp_s'] = "CKGE_TMP_del";
  190. markup['temp_cs'] = "CKGE_TMP_cdel";
  191. var $FORMAT_SUBST = {
  192. 'CKGE_TMP_b': '**',
  193. 'CKGE_TMP_strong': '**',
  194. 'CKGE_TMP_em': '\/\/',
  195. 'CKGE_TMP_u': '__',
  196. 'CKGE_TMP_sup': '<sup>',
  197. 'CKGE_TMP_sub': '<sub>',
  198. 'CKGE_TMP_cdel': '</del>',
  199. 'CKGE_TMP_csub': '</sub>',
  200. 'CKGE_TMP_csup': '</sup>',
  201. 'CKGE_TMP_del': '<del>',
  202. 'CKGE_TMP_strike': '<del>',
  203. 'CKGE_TMP_code': "\'\'"
  204. };
  205. markup['blank'] = "";
  206. markup['fn_start'] = '((';
  207. markup['fn_end'] = '))';
  208. markup['row_span'] = ":::";
  209. markup['p_insert'] = '_PARA__TABLE_INS_';
  210. markup['format_space'] = '_FORMAT_SPACE_';
  211. markup['pre_td'] = '<'; //removes newline from before < which corrupts table
  212. var format_chars = {
  213. 'strong': true,
  214. 'b': true,
  215. 'i': true,
  216. 'em': true,
  217. 'u': true,
  218. 'del': true,
  219. 'strike': true,
  220. 'code': true,
  221. 'sup': true,
  222. 'sub': true,
  223. 's': true
  224. };
  225. var results = "";
  226. var HTMLParser_LBR = false;
  227. var HTMLParser_PRE = false;
  228. var HTMLParser_Geshi = false;
  229. var HTMLParser_TABLE = false;
  230. var HTMLParser_COLSPAN = false;
  231. var HTMLParser_FORMAT_SPACE = false;
  232. var HTMLParser_MULTI_LINE_PLUGIN = false;
  233. var HTMLParser_NOWIKI = false;
  234. var HTMLFormatInList = false;
  235. var HTMLAcroInList = false;
  236. var HTML_InterWiki = false;
  237. var HTMLParserFont = false;
  238. HTMLLinkInList = false;
  239. var HTMLParserFontInfix = false;
  240. var CurrentTable;
  241. var HTMLParserTopNotes = new Array();
  242. var HTMLParserBottomNotes = new Array();
  243. var HTMLParserOpenAngleBracket = false;
  244. var HTMLParserParaInsert = markup['p_insert'];
  245. var geshi_classes = '(br|co|coMULTI|es|kw|me|nu|re|st|sy)[0-9]';
  246. String.prototype.splice = function(idx, rem, s) {
  247. return (this.slice(0, idx) + s + this.slice(idx + Math.abs(rem)));
  248. };
  249. String.frasl = new RegExp("⁄\|&frasl;\|&#8260;\|&#x2044;", 'g');
  250. geshi_classes = new RegExp(geshi_classes);
  251. HTMLParser(CKEDITOR.instances.wiki__text.getData(), {
  252. attribute: "",
  253. link_title: "",
  254. link_class: "",
  255. image_link_type: "",
  256. td_align: "",
  257. in_td: false,
  258. td_colspan: 0,
  259. td_rowspan: 0,
  260. rowspan_col: 0,
  261. last_column: -1,
  262. row: 0,
  263. col: 0,
  264. td_no: 0,
  265. tr_no: 0,
  266. current_row: false,
  267. in_table: false,
  268. in_multi_plugin: false,
  269. is_rowspan: false,
  270. list_level: 0,
  271. prev_list_level: -1,
  272. list_started: false,
  273. xcl_markup: false,
  274. in_link: false,
  275. link_formats: new Array(),
  276. last_tag: "",
  277. code_type: false,
  278. in_endnotes: false,
  279. is_smiley: false,
  280. geshi: false,
  281. downloadable_code: false,
  282. export_code: false,
  283. code_snippet: false,
  284. downloadable_file: "",
  285. external_mime: false,
  286. in_header: false,
  287. curid: false,
  288. format_in_list: false,
  289. prev_li: new Array(),
  290. link_only: false,
  291. in_font: false,
  292. using_fonts: false,
  293. interwiki: false,
  294. bottom_url: false,
  295. font_family: "inherit",
  296. font_size: "inherit",
  297. font_weight: "inherit",
  298. font_color: "inherit",
  299. font_bgcolor: "inherit",
  300. font_style: "inherit",
  301. is_mediafile: false,
  302. end_nested: false,
  303. mfile: false,
  304. backup: function(c1, c2) {
  305. var c1_inx = results.lastIndexOf(c1); // start position of chars to delete
  306. var c2_inx = results.indexOf(c2, c1_inx); // position of expected next character
  307. if (c1_inx == -1 || c2_inx == -1) return;
  308. if (c1.length + c2_inx == c2_inx) {
  309. var left_side = results.substring(0, c1_inx); //from 0 up to but not including c1
  310. var right_side = results.substring(c2_inx); //from c2 to end of string
  311. results = left_side + right_side;
  312. return true;
  313. }
  314. return false;
  315. },
  316. is_iwiki: function(class_name, title) {
  317. var iw_type = class_name.match(/iw_(\w+\.?\w{0,12})/);
  318. var iw_title = title.split(/\/\//);
  319. var interwiki_label = iw_title[iw_title.length - 1];
  320. if (!interwiki_label.match(/oIWIKIo.*?cIWIKIc/)) {
  321. interwiki_label = 'oIWIKIo' + interwiki_label + 'cIWIKIc';
  322. }
  323. interwiki_label = interwiki_label.replace(/^.*?oIWIKIo/, 'oIWIKIo');
  324. interwiki_label = interwiki_label.replace(/cIWIKIc.*/, 'cIWIKIc');
  325. iw_type[1] = iw_type[1].replace(/_(\w{2})/g, "." + "$1");
  326. this.attr = iw_type[1] + '>' + decodeURIComponent(interwiki_label);
  327. HTML_InterWiki = true;
  328. this.interwiki = true;
  329. },
  330. start: function(tag, attrs, unary) {
  331. /** if table debugging code:
  332. this_debug = this.dbg;
  333. */
  334. if (markup[tag]) {
  335. if (format_chars[tag] && this.in_link) {
  336. this.link_formats.push(tag);
  337. return;
  338. }
  339. if (format_chars[tag] && (this.in_font || this.in_header)) {
  340. results += " ";
  341. var t = 'temp_' + tag;
  342. results += markup[t];
  343. results += " ";
  344. return;
  345. } else if (tag == 'acronym') {
  346. return;
  347. }
  348. if (format_chars[tag] && this.in_endnotes) {
  349. if (tag == 'sup') return;
  350. }
  351. if (tag == 'ol' || tag == 'ul') {
  352. if(this.in_table) {
  353. markup_end['li'] = "\\\\";
  354. this.list_level = 0;
  355. jQuery('#dw__editform').append('<input type="hidden" id="linkintbl" name="linkintbl" value="del" />');
  356. }
  357. else markup_end['li'] = "\n";
  358. this.prev_list_level = this.list_level;
  359. this.list_level++;
  360. if (this.list_level == 1) this.list_started = false;
  361. if (this.list_started) this.prev_li.push(markup['li']);
  362. markup['li'] = markup[tag];
  363. return;
  364. } else if (!this.list_level) {
  365. markup['li'] = "";
  366. this.prev_li = new Array();
  367. }
  368. this.is_mediafile = false;
  369. if (tag == 'img') {
  370. var img_size = "?";
  371. var width;
  372. var height;
  373. var style = false;
  374. var img_align = '';
  375. var alt = "";
  376. var from_clipboard = false;
  377. this.is_smiley = false;
  378. this.in_link = false;
  379. }
  380. if (tag == 'a') {
  381. var local_image = true;
  382. var type = "";
  383. this.xcl_markup = false; // set to false in end() as well, double sure
  384. this.in_link = true;
  385. this.link_pos = results.length;
  386. this.link_formats = new Array();
  387. this.footnote = false;
  388. var bottom_note = false;
  389. this.id = "";
  390. this.external_mime = false;
  391. var media_class = false;
  392. this.export_code = false;
  393. this.code_snippet = false;
  394. this.downloadable_file = "";
  395. var qs_set = false;
  396. this.link_only = false;
  397. save_url = "";
  398. this.interwiki = false;
  399. this.bottom_url = false;
  400. this.link_title = false;
  401. var interwiki_title = "";
  402. var interwiki_class = "";
  403. }
  404. if (tag == 'p') {
  405. this.in_link = false;
  406. if (this.in_table) {
  407. tag = 'p_insert';
  408. HTMLParser_TABLE = true;
  409. }
  410. }
  411. if (tag == 'table') {
  412. this.td_no = 0;
  413. this.tr_no = 0;
  414. this.in_table = true;
  415. this.is_rowspan = false;
  416. this.row = -1;
  417. this.rows = new Array();
  418. CurrentTable = this.rows;
  419. this.table_start = results.length;
  420. } else if (tag == 'tr') {
  421. this.tr_no++;
  422. this.td_no = 0;
  423. this.col = -1;
  424. this.row++;
  425. this.rows[this.row] = new Array();
  426. this.current_row = this.rows[this.row];
  427. } else if (tag == 'td' || tag == 'th') {
  428. this.td_no++;
  429. this.col++;
  430. this.current_row[this.col] = {
  431. type: tag,
  432. rowspan: 0,
  433. colspan: 0,
  434. text: ""
  435. };
  436. this.cell_start = results.length;
  437. this.current_cell = this.current_row[this.col];
  438. if (this.td_rowspan && this.rowspan_col == this.td_no && this.td_no != this.last_column) {
  439. this.is_rowspan = true;
  440. this.td_rowspan--;
  441. } else {
  442. this.is_rowspan = false;
  443. }
  444. }
  445. var matches;
  446. this.attr = false;
  447. this.format_tag = false;
  448. if (format_chars[tag]) this.format_tag = true;
  449. var dwfck_note = false;
  450. for (var i = 0; i < attrs.length; i++) {
  451. // if(!confirm(tag + ' ' + attrs[i].name + '="' + attrs[i].escaped + '"')) exit;
  452. if (tag == 'td' || tag == 'th') {
  453. if (attrs[i].name == 'colspan') {
  454. this.current_row[this.col].colspan = attrs[i].value;
  455. }
  456. if (attrs[i].name == 'class') {
  457. if ((matches = attrs[i].value.match(/(left|center|right)/))) {
  458. this.current_row[this.col].align = matches[1];
  459. }
  460. }
  461. if (attrs[i].name == 'rowspan') {
  462. this.current_row[this.col].rowspan = attrs[i].value
  463. }
  464. }
  465. if (attrs[i].escaped == 'u' && tag == 'em') {
  466. tag = 'u';
  467. this.attr = 'u'
  468. break;
  469. }
  470. if (tag == 'div') {
  471. if (attrs[i].name == 'class' && attrs[i].value == 'footnotes') {
  472. tag = 'blank';
  473. this.in_endnotes = true;
  474. }
  475. break;
  476. }
  477. if (tag == 'dl' && attrs[i].name == 'class' && attrs[i].value == 'file') {
  478. this.downloadable_code = true;
  479. HTMLParser_Geshi = true;
  480. return;
  481. }
  482. if (tag == 'span' && attrs[i].name == 'class') {
  483. if (attrs[i].value == 'np_break') return;
  484. }
  485. if (tag == 'span' && attrs[i].name == 'class') {
  486. if (attrs[i].value == 'curid') {
  487. this.curid = true;
  488. return;
  489. }
  490. if (attrs[i].value == 'multi_p_open') {
  491. this.in_multi_plugin = true;
  492. HTMLParser_MULTI_LINE_PLUGIN = true;
  493. return;
  494. }
  495. if (attrs[i].value == 'multi_p_close') {
  496. this.in_multi_plugin = false;
  497. return;
  498. }
  499. if (attrs[i].value.match(geshi_classes)) {
  500. tag = 'blank';
  501. this.geshi = true;
  502. break;
  503. }
  504. }
  505. if (tag == 'span' && !ckgedit_xcl_styles) {
  506. if (attrs[i].name == 'style') {
  507. if (!this.in_font) results += "__STYLE__";
  508. this.in_font = true;
  509. this.using_fonts = true;
  510. matches = attrs[i].value.match(/font-family:\s*([\w\-\s,]+);?/);
  511. if (matches) {
  512. this.font_family = matches[1];
  513. }
  514. //matches = attrs[i].value.match(/font-size:\s*(\d+(\w+|%));?/);
  515. matches = attrs[i].value.match(/font-size:\s*(.*)/);
  516. if (matches) {
  517. matches[1] = matches[1].replace(/;/, "");
  518. this.font_size = matches[1];
  519. }
  520. matches = attrs[i].value.match(/font-weight:\s*(\w+);?/);
  521. if (matches) {
  522. this.font_weight = matches[1];
  523. }
  524. matches = attrs[i].value.match(/.*?color:\s*(.*)/);
  525. var bgcolor_found = false;
  526. if (matches) {
  527. matches[1] = matches[1].replace(/;/, "");
  528. if (matches[0].match(/background/)) {
  529. this.font_bgcolor = matches[1];
  530. } else {
  531. this.font_color = matches[1];
  532. }
  533. }
  534. if (!bgcolor_found) { //catch MS Word which uses background:color-name instead of background-color:color-name
  535. matches = attrs[i].value.match(/background:\s*(\w+)/);
  536. if (matches && matches[0].match(/background/)) {
  537. this.font_bgcolor = matches[1];
  538. }
  539. }
  540. }
  541. }
  542. if (tag == 'td' || tag == 'th') {
  543. if (tag == 'td') {
  544. results = results.replace(/\^$/, '|');
  545. }
  546. this.in_td = true;
  547. if (attrs[i].name == 'align') {
  548. this.td_align = attrs[i].escaped;
  549. } else if (attrs[i].name == 'class') {
  550. matches = attrs[i].value.match(/\s*(\w+)align/);
  551. if (matches) {
  552. this.td_align = matches[1];
  553. }
  554. } else if (attrs[i].name == 'colspan') {
  555. HTMLParser_COLSPAN = true;
  556. this.td_colspan = attrs[i].escaped;
  557. } else if (attrs[i].name == 'rowspan') {
  558. this.td_rowspan = attrs[i].escaped - 1;
  559. this.rowspan_col = this.td_no;
  560. }
  561. HTMLParser_TABLE = true;
  562. }
  563. if (tag == 'a') {
  564. // if(!confirm(attrs[i].name + '="' + attrs[i].escaped + '"')) exit;
  565. if (attrs[i].name == 'title') {
  566. this.link_title = attrs[i].escaped;
  567. if (interwiki_class) {
  568. interwiki_title = attrs[i].escaped;
  569. } else this.link_title = this.link_title.replace(/\s+.*$/, "");
  570. } else if (attrs[i].name == 'class') {
  571. if (attrs[i].value.match(/fn_top/)) {
  572. this.footnote = true;
  573. } else if (attrs[i].value.match(/fn_bot/)) {
  574. bottom_note = true;
  575. } else if (attrs[i].value.match(/mf_(png|gif|jpg|jpeg)/i)) {
  576. this.link_only = true;
  577. } else if (attrs[i].value.match(/interwiki/)) {
  578. attrs[i].value = attrs[i].value.replace(/\./g, '_');
  579. this.link_class = attrs[i].value;
  580. continue;
  581. }
  582. this.link_class = attrs[i].escaped;
  583. media_class = this.link_class.match(/mediafile/);
  584. } else if (attrs[i].name == 'id') {
  585. this.id = attrs[i].value;
  586. } else if (attrs[i].name == 'type') {
  587. type = attrs[i].value;
  588. } else if (attrs[i].name == 'href' && !this.code_type) {
  589. var http = attrs[i].escaped.match(/https*:\/\//) ? true : false;
  590. if (http) save_url = attrs[i].escaped;
  591. if (attrs[i].escaped.match(/\/lib\/exe\/detail.php/)) {
  592. this.image_link_type = 'detail';
  593. } else if (attrs[i].escaped.match(/exe\/fetch.php/)) {
  594. this.image_link_type = 'direct';
  595. }
  596. if (this.link_class && this.link_class.match(/media/) && !this.link_title) {
  597. var link_find = attrs[i].escaped.match(/media=(.*)/);
  598. if (link_find) this.link_title = link_find[1];
  599. }
  600. // required to distinguish external images from external mime types
  601. // that are on the wiki which also use {{url}}
  602. var media_type = attrs[i].escaped.match(/fetch\.php.*?media=.*?\.(png|gif|jpg|jpeg)$/i);
  603. if (media_type) media_type = media_type[1];
  604. if (attrs[i].escaped.match(/^https*:/)) {
  605. this.attr = attrs[i].escaped;
  606. local_image = false;
  607. }
  608. if (attrs[i].escaped.match(/^ftp:/)) {
  609. this.attr = attrs[i].escaped;
  610. local_image = false;
  611. } else if (attrs[i].escaped.match(/do=export_code/)) {
  612. this.export_code = true;
  613. } else if (attrs[i].escaped.match(/^nntp:/)) {
  614. this.attr = attrs[i].escaped;
  615. local_image = false;
  616. } else if (attrs[i].escaped.match(/^mailto:/)) {
  617. this.attr = attrs[i].escaped.replace(/mailto:/, "");
  618. local_image = false;
  619. } else if (attrs[i].escaped.match(/m-files/)) {
  620. this.attr = attrs[i].escaped;
  621. this.mfile = attrs[i].escaped;
  622. local_image = false;
  623. } else if (attrs[i].escaped.match(/^file:/)) { //samba share
  624. var url = attrs[i].value.replace(/file:[\/]+/, "");
  625. url = url.replace(/[\/]/g, '\\');
  626. url = '\\\\' + url;
  627. this.attr = url;
  628. local_image = false;
  629. }
  630. // external mime types after they've been saved first time
  631. else if (http && !media_type && (matches = attrs[i].escaped.match(/fetch\.php(.*)/))) {
  632. if (matches[1].match(/media=/)) {
  633. elems = matches[1].split(/=/);
  634. this.attr = elems[1];
  635. } else { // nice urls
  636. matches[1] = matches[1].replace(/^\//, "");
  637. this.attr = matches[1];
  638. }
  639. if (typeof config_animal !== 'undefined') {
  640. var regex = new RegExp(config_animal + '\/file\/(.*)');
  641. matches = attrs[i].escaped.match(regex);
  642. if (matches && matches[1]) this.attr = matches[1];
  643. if (this.attr) this.attr = this.attr.replace(/\//g, ':');
  644. }
  645. local_image = false;
  646. this.attr = decodeURIComponent ? decodeURIComponent(this.attr) : unescape(this.attr);
  647. if (!this.attr.match(/^:/)) {
  648. this.attr = ':' + this.attr;
  649. }
  650. this.external_mime = true;
  651. } else {
  652. local_image = false;
  653. matches = attrs[i].escaped.match(/doku.php\?id=(.*)/);
  654. if (matches && save_url) {
  655. var rx = DOKU_BASE + 'doku.php';
  656. if (!attrs[i].escaped.match(rx)) {
  657. this.link_class == 'urlextern';
  658. this.attr = save_url;
  659. matches = null;
  660. }
  661. }
  662. if (!matches) {
  663. matches = attrs[i].escaped.match(/doku.php\/(.*)/);
  664. }
  665. /* previously saved internal link with query string
  666. requires initial ? to be recognized by DW. In Anteater and later */
  667. if (matches) {
  668. if (!matches[1].match(/\?/) && matches[1].match(/&amp;/)) {
  669. qs_set = true;
  670. matches[1] = matches[1].replace(/&amp;/, '?')
  671. }
  672. }
  673. if (matches && matches[1]) {
  674. if (!matches[1].match(/^:/)) {
  675. this.attr = ':' + matches[1];
  676. } else {
  677. this.attr = matches[1];
  678. }
  679. if (this.attr.match(/\.\w+$/)) { // external mime's first access
  680. if (type && type == 'other_mime') {
  681. this.external_mime = true;
  682. } else {
  683. for (var n = i + 1; n < attrs.length; n++) {
  684. if (attrs[n].value.match(/other_mime/))
  685. this.external_mime = true;
  686. break;
  687. }
  688. }
  689. }
  690. } else {
  691. matches = attrs[i].value.match(/\\\\/); // Windows share
  692. if (matches) {
  693. this.attr = attrs[i].escaped;
  694. local_image = false;
  695. }
  696. }
  697. }
  698. if (this.link_class == 'media') {
  699. if (attrs[i].value.match(/http:/)) {
  700. local_image = false;
  701. }
  702. }
  703. if (!this.attr && this.link_title) {
  704. if (matches = this.link_class.match(/media(.*)/)) {
  705. this.link_title = decodeURIComponent(safe_convert(this.link_title));
  706. this.attr = this.link_title;
  707. var m = matches[1].split(/_/);
  708. if (m && m[1]) {
  709. media_type = m[1];
  710. } else if (m) {
  711. media_type = m[0];
  712. } else media_type = 'mf';
  713. if (!this.attr.match(/^:/) && !this.attr.match(/^https?\:/)) {
  714. this.attr = ':' + this.attr.replace(/^\s+/, "");
  715. }
  716. this.external_mime = true;
  717. local_image = false;
  718. }
  719. }
  720. if (this.attr.match && this.attr.match(/%[a-fA-F0-9]{2}/) && (matches = this.attr.match(/userfiles\/file\/(.*)/))) {
  721. matches[1] = matches[1].replace(/\//g, ':');
  722. if (!matches[1].match(/^:/)) {
  723. matches[1] = ':' + matches[1];
  724. }
  725. this.attr = decodeURIComponent ? decodeURIComponent(matches[1]) : unescape(matches[1]);
  726. this.attr = decodeURIComponent ? decodeURIComponent(this.attr) : unescape(this.attr);
  727. this.external_mime = true;
  728. } else if (this.attr && this.attr.match(/%[a-fA-F0-9]{2}/)) {
  729. this.attr = decodeURIComponent(this.attr);
  730. this.attr = decodeURIComponent(this.attr);
  731. }
  732. // alert('title: ' + this.link_title + ' class: ' + this.link_class + ' export: ' +this.export_code);
  733. if (this.link_title && this.link_title.match(/Snippet/)) this.code_snippet = true;
  734. /* anchors to current page without prefixing namespace:page */
  735. if (attrs[i].value.match(/^#/) && this.link_class.match(/wikilink/)) {
  736. this.attr = attrs[i].value;
  737. this.link_title = false;
  738. }
  739. /* These two conditions catch user_rewrite not caught above */
  740. if (this.link_class.match(/wikilink/) && this.link_title) {
  741. this.external_mime = false;
  742. if (!this.attr) {
  743. this.attr = this.link_title;
  744. }
  745. if (!this.attr.match(/^:/)) {
  746. this.attr = ':' + this.attr;
  747. }
  748. if (this.attr.match(/\?.*?=/)) {
  749. var elems = this.attr.split(/\?/);
  750. elems[0] = elems[0].replace(/\//g, ':');
  751. this.attr = elems[0] + '?' + elems[1];
  752. } else {
  753. this.attr = this.attr.replace(/\//g, ':');
  754. }
  755. /* catch query strings attached to internal links for .htacess nice urls */
  756. if (!qs_set && attrs[i].name == 'href') {
  757. if (!this.attr.match(/\?.*?=/) && !attrs[i].value.match(/doku.php/)) {
  758. var qs = attrs[i].value.match(/(\?.*)$/);
  759. if (qs && qs[1]) this.attr += qs[1];
  760. }
  761. }
  762. } else if (this.link_class.match(/mediafile/) && this.link_title && !this.attr) {
  763. this.attr = this.link_title;
  764. this.external_mime = true;
  765. if (!this.attr.match(/^:/)) {
  766. this.attr = ':' + this.attr;
  767. }
  768. } else if (this.link_class.match(/interwiki/)) {
  769. interwiki_class = this.link_class;
  770. }
  771. if (this.link_class == 'urlextern' && !this.mfile && save_url) {
  772. this.attr = save_url;
  773. this.external_mime = false; // prevents external links to images from being converted to image links
  774. }
  775. if (this.in_endnotes) {
  776. if (this.link_title) {
  777. this.bottom_url = this.link_title; //save for bottom urls
  778. } else if (this.attr) {
  779. this.bottom_url = this.attr;
  780. }
  781. }
  782. this.link_title = "";
  783. this.link_class = "";
  784. // break;
  785. }
  786. }
  787. if (interwiki_class && interwiki_title) {
  788. this.is_iwiki(interwiki_class, interwiki_title);
  789. interwiki_class = "";
  790. interwiki_title = "";
  791. }
  792. if (tag == 'sup') {
  793. if (attrs[i].name == 'class') {
  794. matches = attrs[i].value.split(/\s+/);
  795. if (matches[0] == 'dwfcknote') {
  796. this.attr = matches[0];
  797. tag = 'blank';
  798. if (oDokuWiki_FCKEditorInstance.oinsertHtmlCodeObj.notes[matches[1]]) {
  799. dwfck_note = '((' + oDokuWiki_FCKEditorInstance.oinsertHtmlCodeObj.notes[matches[1]] + '))';
  800. }
  801. break;
  802. }
  803. }
  804. }
  805. if (tag == 'pre') {
  806. if (attrs[i].name == 'class') {
  807. var elems = attrs[i].escaped.split(/\s+/);
  808. if (elems.length > 1) {
  809. this.attr = attrs[i].value;
  810. this.code_type = elems[0];
  811. } else {
  812. this.attr = attrs[i].escaped;
  813. this.code_type = this.attr;
  814. }
  815. if (this.downloadable_code) {
  816. this.attr = this.attr.replace(/\s*code\s*/, "");
  817. this.code_type = 'file';
  818. }
  819. HTMLParser_PRE = true;
  820. if (this.in_table) tag = 'pre_td';
  821. break;
  822. }
  823. } else if (tag == 'img') {
  824. if (attrs[i].name == 'alt') {
  825. alt = attrs[i].value;
  826. }
  827. if (attrs[i].name == 'type') {
  828. this.image_link_type = attrs[i].value;
  829. }
  830. if (attrs[i].name == 'src') {
  831. // alert(attrs[i].name + ' = ' + attrs[i].value + ', fnencode=' + oDokuWiki_FCKEditorInstance.dwiki_fnencode);
  832. var src = "";
  833. // fetched by fetch.php
  834. if (matches = attrs[i].escaped.match(/fetch\.php.*?(media=.*)/)) {
  835. var elems = matches[1].split('=');
  836. src = elems[1];
  837. if (matches = attrs[i].escaped.match(/(media.*)/)) {
  838. var elems = matches[1].split('=');
  839. var uri = elems[1];
  840. src = decodeURIComponent ? decodeURIComponent(uri) : unescape(uri);
  841. }
  842. if (!src.match(/https?:/) && !src.match(/^:/)) src = ':' + src;
  843. } else if (attrs[i].escaped.match(/https?:\/\//)) {
  844. src = attrs[i].escaped;
  845. src = src.replace(/\?.*?$/, "");
  846. }
  847. // url rewrite 1
  848. else if (matches = attrs[i].escaped.match(/\/_media\/(.*)/)) {
  849. var elems = matches[1].split(/\?/);
  850. src = elems[0];
  851. src = src.replace(/\//g, ':');
  852. if (!src.match(/^:/)) src = ':' + src;
  853. }
  854. // url rewrite 2
  855. else if (matches = attrs[i].escaped.match(/\/lib\/exe\/fetch.php\/(.*)/)) {
  856. var elems = matches[1].split(/\?/);
  857. src = elems[0];
  858. if (!src.match(/^:/)) src = ':' + src;
  859. } else {
  860. // first insertion from media mananger
  861. matches = attrs[i].escaped.match(/^.*?\/userfiles\/image\/(.*)/);
  862. if (!matches && typeof config_animal !== 'undefined') {
  863. var regex = new RegExp(config_animal + '\/image\/(.*)$');
  864. matches = attrs[i].escaped.match(regex);
  865. }
  866. if (!matches) { // windows style
  867. var regex = doku_base + 'data/media/';
  868. regex = regex.replace(/([\/\\])/g, "\\$1");
  869. regex = '^.*?' + regex + '(.*)';
  870. regex = new RegExp(regex);
  871. matches = attrs[i].escaped.match(regex);
  872. }
  873. if (matches && matches[1]) {
  874. src = matches[1].replace(/\//g, ':');
  875. src = ':' + src;
  876. } else {
  877. src = decodeURIComponent ? decodeURIComponent(attrs[i].escaped) : unescape(attrs[i].escaped);
  878. if (src.search(/data:image.*?;base64/) > -1) {
  879. from_clipboard = true;
  880. }
  881. }
  882. }
  883. if (src && src.match(/lib\/images\/smileys/)) {
  884. // src = 'http://' + window.location.host + src;
  885. this.is_smiley = true;
  886. }
  887. this.attr = src;
  888. if (this.attr && this.attr.match && this.attr.match(/%[a-fA-F0-9]{2}/)) {
  889. this.attr = decodeURIComponent(safe_convert(this.attr));
  890. this.attr = decodeURIComponent(safe_convert(this.attr));
  891. }
  892. } // src end
  893. else if (attrs[i].name == 'width' && !style) {
  894. width = attrs[i].value;
  895. } else if (attrs[i].name == 'height' && !style) {
  896. height = attrs[i].value;
  897. } else if (attrs[i].name == 'style') {
  898. var match = attrs[i].escaped.match(/width:\s*(\d+)/);
  899. if (match) {
  900. width = match[1];
  901. var match = attrs[i].escaped.match(/height:\s*(\d+)/);
  902. if (match) height = match[1];
  903. }
  904. } else if (attrs[i].name == 'align' || attrs[i].name == 'class') {
  905. if (attrs[i].escaped.match(/(center|middle)/)) {
  906. img_align = 'center';
  907. } else if (attrs[i].escaped.match(/right/)) {
  908. img_align = 'right';
  909. } else if (attrs[i].escaped.match(/left/)) {
  910. img_align = 'left';
  911. } else {
  912. img_align = '';
  913. }
  914. }
  915. } // End img
  916. } // End Attributes Loop
  917. if (this.is_smiley) {
  918. if (alt) {
  919. results += alt + ' ';
  920. alt = "";
  921. }
  922. this.is_smiley = false;
  923. return;
  924. }
  925. if (this.link_only) tag = 'img';
  926. if (tag == 'br') {
  927. if (this.in_multi_plugin) {
  928. results += "\n";
  929. return;
  930. }
  931. if (!this.code_type) {
  932. HTMLParser_LBR = true;
  933. } else if (this.code_type) {
  934. results += "\n";
  935. return;
  936. }
  937. if (this.in_table) {
  938. results += HTMLParserParaInsert;
  939. return;
  940. }
  941. if (this.list_started) {
  942. results += '_LIST_EOFL_'; /* enables newlines in lists: abc \\def */
  943. } else {
  944. results += '\\\\ ';
  945. return;
  946. }
  947. } else if (tag.match(/^h(\d+|r)/)) {
  948. var str_len = results.length;
  949. if (tag.match(/h(\d+)/)) {
  950. this.in_header = true;
  951. }
  952. if (str_len) {
  953. if (results.charCodeAt(str_len - 1) == 32) {
  954. results = results.replace(/\x20+$/, "");
  955. }
  956. }
  957. } else if (this.last_col_pipes) {
  958. if (format_chars[tag]) results += markup[tag];
  959. tag = 'blank';
  960. } else if (dwfck_note) {
  961. results += dwfck_note;
  962. return;
  963. }
  964. if (tag == 'b' || tag == 'i' && this.list_level) {
  965. if (results.match(/(\/\/|\*)(\x20)+/)) {
  966. results = results.replace(/(\/\/|\*)(\x20+)\-/, "$1\n" + "$2-");
  967. }
  968. }
  969. if(this.in_table && tag == 'li') {
  970. // alert(tag);
  971. }
  972. if (tag == 'li' && this.list_level) {
  973. if (this.list_level == 1 & !this.list_started) {
  974. results += "\n";
  975. this.list_started = true;
  976. }
  977. results = results.replace(/[\x20]+$/, "");
  978. for (var s = 0; s < this.list_level; s++) {
  979. // this handles format characters at the ends of list lines
  980. if (results.match(/_FORMAT_SPACE_\s*$/)) {
  981. results = results.replace(/_FORMAT_SPACE_\s*$/, "\n");
  982. }
  983. if (this.list_level > 1) {
  984. results += ' ';
  985. }
  986. }
  987. if (this.prev_list_level > 0 && markup['li'] == markup['ol']) {
  988. this.prev_list_level = -1;
  989. }
  990. }
  991. if (tag == 'a' && this.list_level) {
  992. HTMLLinkInList = true;
  993. }
  994. if (tag == 'a' && local_image) {
  995. this.xcl_markup = true;
  996. return;
  997. } else if (tag == 'a' && (this.export_code || this.code_snippet)) {
  998. return;
  999. } else if (tag == 'a' && this.footnote) {
  1000. tag = 'fn_start';
  1001. } else if (tag == 'a' && bottom_note) {
  1002. HTMLParserTopNotes.push(this.id);
  1003. } else if (tag == 'a' && this.external_mime) {
  1004. if (this.in_endnotes) {
  1005. this.link_class = 'media';
  1006. return;
  1007. }
  1008. if (media_class && media_class == 'mediafile') {
  1009. results += markup['img'];
  1010. results += this.attr + '|';
  1011. this.is_mediafile = true;
  1012. }
  1013. return;
  1014. } else if (this.in_font) {
  1015. if (tag == 'a') {
  1016. results = results.replace(/__STYLE__/, '[[' + this.attr + '|');
  1017. this.in_font = false;
  1018. }
  1019. return;
  1020. /* <font 18pt:bold,italic/garamond;;color;;background_color> */
  1021. }
  1022. if (this.in_endnotes && tag == 'a') return;
  1023. if (this.code_type && tag == 'span') tag = 'blank';
  1024. if (this.mfile && !this.attr) {
  1025. this.attr = this.mfile;
  1026. }
  1027. results += markup[tag]; // Set tag
  1028. if (tag == 'td' || tag == 'th' || (this.last_col_pipes && this.td_align == 'center')) {
  1029. if (this.is_rowspan) {
  1030. results += markup['row_span'] + ' | ';
  1031. this.is_rowspan = false;
  1032. }
  1033. if (this.td_align == 'center' || this.td_align == 'right') {
  1034. results += ' ';
  1035. }
  1036. } else if (tag == 'a' && this.attr) {
  1037. this.attr = this.attr.replace(/%7c/, '%257c');
  1038. results += this.attr + '|';
  1039. } else if (tag == 'img') {
  1040. var link_type = this.image_link_type;
  1041. this.image_link_type = "";
  1042. if (this.link_only) link_type = 'link_only';
  1043. if (!link_type || from_clipboard) {
  1044. link_type = 'nolink';
  1045. } else if (link_type == 'detail') {
  1046. link_type = "";
  1047. }
  1048. if (link_type == 'link_only') {
  1049. img_size = '?linkonly';
  1050. } else if (link_type) {
  1051. img_size += link_type + '&';
  1052. }
  1053. if (width && height) {
  1054. img_size += width + 'x' + height;
  1055. } else if (width) {
  1056. img_size += width;
  1057. } else if (!link_type) {
  1058. img_size = "";
  1059. }
  1060. if (img_align && img_align != 'left') {
  1061. results += ' ';
  1062. }
  1063. this.attr += img_size;
  1064. if (img_align == 'center' || img_align == 'left') {
  1065. this.attr += ' ';
  1066. }
  1067. if (alt) {
  1068. results += this.attr + '|' + alt + '}}';
  1069. } else results += this.attr + '}}';
  1070. this.attr = 'src';
  1071. } else if (tag == 'pre' || tag == 'pre_td') {
  1072. if (this.downloadable_file) this.attr += ' ' + this.downloadable_file;
  1073. if (!this.attr) this.attr = 'code';
  1074. results += this.attr + '>';
  1075. this.downloadable_file = "";
  1076. this.downloadable_code = false;
  1077. }
  1078. } // if markup tag
  1079. },
  1080. end: function(tag) {
  1081. if (format_chars[tag] && (this.in_font || this.in_header)) {
  1082. results += " ";
  1083. if (tag == 'sup' || tag == 'sub' || tag == 'del' || tag == 'strike' || tag == 's') {
  1084. var t = 'temp_c' + tag;
  1085. } else var t = 'temp_' + tag;
  1086. results += markup[t];
  1087. results += " ";
  1088. return;
  1089. }
  1090. if (this.in_endnotes && tag == 'a') return;
  1091. if (this.in_link && format_chars[current_tag] && this.link_formats.length) {
  1092. return;
  1093. } else if (tag == 'a' && !this.link_formats.length) this.in_link = false;
  1094. if (this.link_only) {
  1095. this.link_only = false;
  1096. return;
  1097. }
  1098. if (!markup[tag]) return;
  1099. if (tag == 'sup' && this.attr == 'dwfcknote') {
  1100. return;
  1101. }
  1102. if (this.is_smiley) {
  1103. this.is_smiley = false;
  1104. if (tag != 'li') return;
  1105. }
  1106. if (tag == 'span' && this.in_font && !ckgedit_xcl_styles) {
  1107. tag = 'font';
  1108. //<font 18pt/garamond;;color;;background_color>
  1109. var font_str = '<font ' + this.font_size + '/' + this.font_family + ';;' + this.font_color + ';;' + this.font_bgcolor + ">";
  1110. var inherits = font_str.match(/(inherit)/g);
  1111. if (inherits && inherits.length < 3) HTMLParserFontInfix = true;
  1112. var font_start = results.lastIndexOf('__STYLE__');
  1113. results = results.splice(font_start, 9, font_str);
  1114. results = results.replace(/_FORMAT_SPACE_<font/m, "<font");
  1115. this.font_size = 'inherit';
  1116. this.font_family = 'inherit';
  1117. this.font_color = 'inherit';
  1118. this.font_bgcolor = 'inherit';
  1119. this.in_font = false;
  1120. HTMLParserFont = true;
  1121. results = results.replace(/__STYLE__/g, "");
  1122. }
  1123. if (tag == 'span' && this.curid) {
  1124. this.curid = false;
  1125. return;
  1126. }
  1127. if (tag == 'dl' && this.downloadable_code) {
  1128. this.downloadable_code = false;
  1129. return;
  1130. }
  1131. if (useComplexTables && (tag == 'td' || tag == 'th')) {
  1132. this.current_cell.text = results.substring(this.cell_start);
  1133. this.current_cell.text = this.current_cell.text.replace(/:::/gm, "");
  1134. this.current_cell.text = this.current_cell.text.replace(/^[\s\|\^]+/, "");
  1135. }
  1136. if (tag == 'a' && (this.export_code || this.code_snippet)) {
  1137. this.export_code = false;
  1138. this.code_snippet = false;
  1139. return;
  1140. }
  1141. if (this.code_type && tag == 'span') tag = 'blank';
  1142. var current_tag = tag;
  1143. if (this.footnote) {
  1144. tag = 'fn_end';
  1145. this.footnote = false;
  1146. } else if (tag == 'a' && this.xcl_markup) {
  1147. this.xcl_markup = false;
  1148. return;
  1149. } else if (tag == 'table') {
  1150. this.in_table = false;
  1151. if (useComplexTables) {
  1152. results = results.substring(0, this.table_start);
  1153. insert_table(this.rows);
  1154. }
  1155. }
  1156. if (tag == 'p' && this.in_table) {
  1157. tag = 'p_insert';
  1158. HTMLParser_TABLE = true;
  1159. }
  1160. if (this.geshi) {
  1161. this.geshi = false;
  1162. return;
  1163. }
  1164. if (tag == 'code' && !this.list_started) { // empty code markup corrupts results
  1165. if (results.match(/''\s*$/m)) {
  1166. results = results.replace(/''\s*$/, "\n");
  1167. return;
  1168. }
  1169. } else if (tag == 'a' && this.attr == 'src') {
  1170. // if local image without link content, as in <a . . .></a>, delete link markup
  1171. if (this.backup('\[\[', '\{')) return;
  1172. }
  1173. if (this.end_nested) {
  1174. this.end_nested = false;
  1175. return; // prevent newline from being inserted between end of nested list and return to previous nested level
  1176. }
  1177. if ((tag == 'ol' || tag == 'ul') && !this.in_table) {
  1178. this.list_level--;
  1179. if (!this.list_level) this.format_in_list = false;
  1180. if (this.prev_li.length) {
  1181. markup['li'] = this.prev_li.pop();
  1182. this.end_nested = true;
  1183. return;
  1184. }
  1185. tag = "\n\n";
  1186. } else if (tag == 'a' && this.external_mime) {
  1187. this.external_mime = false;
  1188. if (this.is_mediafile) {
  1189. tag = '}} ';
  1190. } else return;
  1191. } else if (tag == 'pre') {
  1192. tag = markup_end[tag];
  1193. if (this.code_type) {
  1194. tag += this.code_type + ">";
  1195. } else {
  1196. var codeinx = results.lastIndexOf('code');
  1197. var fileinx = results.lastIndexOf('file');
  1198. if (fileinx > codeinx) {
  1199. this.code_type = 'file';
  1200. } else this.code_type = 'code';
  1201. tag += this.code_type + ">";
  1202. }
  1203. this.code_type = false;
  1204. } else if (markup_end[tag]) {
  1205. tag = markup_end[tag];
  1206. } else if (this.attr == 'u' && tag == 'em') {
  1207. tag = 'u';
  1208. } else if (tag == 'acronym') {} else {
  1209. tag = markup[tag];
  1210. }
  1211. if (current_tag == 'tr') {
  1212. if (this.last_col_pipes) {
  1213. tag = "\n";
  1214. this.last_col_pipes = "";
  1215. }
  1216. if (this.td_rowspan && this.rowspan_col == this.td_no + 1) {
  1217. this.is_rowspan = false;
  1218. this.last_column = this.td_no;
  1219. this.td_rowspan--;
  1220. tag = '|' + markup['row_span'] + "|\n";
  1221. }
  1222. } else if (current_tag == 'td' || current_tag == 'th') {
  1223. this.last_col_pipes = "";
  1224. this.in_td = false;
  1225. } else if (current_tag.match(/h\d+/)) {
  1226. this.in_header = false;
  1227. }
  1228. if (markup['li']) {
  1229. if (results.match(/\n$/) && !this.list_level) {
  1230. tag = "";
  1231. }
  1232. }
  1233. if (this.in_endnotes && current_tag == 'sup') {
  1234. return
  1235. }
  1236. results += tag;
  1237. if (format_chars[current_tag]) {
  1238. if (this.list_level) {
  1239. this.format_in_list = true;
  1240. HTMLFormatInList = true;
  1241. }
  1242. results += markup['format_space'];
  1243. HTMLParser_FORMAT_SPACE = markup['format_space'];
  1244. }
  1245. this.last_tag = current_tag;
  1246. if (this.td_colspan && !useComplexTables) {
  1247. if (this.td_align == 'center') results += ' ';
  1248. var _colspan = "|";
  1249. if (current_tag == 'th')
  1250. _colspan = '^';
  1251. var colspan = _colspan;
  1252. for (var i = 1; i < this.td_colspan; i++) {
  1253. colspan += _colspan;
  1254. }
  1255. this.last_col_pipes = colspan;
  1256. results += colspan;
  1257. this.td_colspan = false;
  1258. } else if (this.td_align == 'center') {
  1259. results += ' ';
  1260. this.td_align = '';
  1261. }
  1262. if (current_tag == 'a' && this.link_formats.length) {
  1263. var end_str = results.substring(this.link_pos);
  1264. var start_str = results.substring(0, this.link_pos);
  1265. var start_format = "";
  1266. var end_format = "";
  1267. for (var i = 0; i < this.link_formats.length; i++) {
  1268. var fmt = markup[this.link_formats[i]];
  1269. var endfmt = markup_end[this.link_formats[i]] ? markup_end[this.link_formats[i]] : fmt;
  1270. start_format += markup[this.link_formats[i]];
  1271. end_format = endfmt + end_format;
  1272. }
  1273. start_str += start_format;
  1274. end_str += end_format;
  1275. results = start_str + end_str;
  1276. this.link_formats = new Array();
  1277. this.in_link = false;
  1278. } else if (current_tag == 'a') {
  1279. this.link_formats = new Array();
  1280. this.in_link = false;
  1281. }
  1282. },
  1283. chars: function(text) {
  1284. text = text.replace(/\t/g, " ");
  1285. if (this.code_type == 'code') {
  1286. text = text.replace(/(\n?|\s+)\\/gm, "$1CBL__Bksl");
  1287. }
  1288. if (text.match(/~~START_HTML_BLOCK~~/)) {
  1289. text = text.replace(/~~START_HTML_BLOCK~~\n*/, "~~START_HTML_BLOCK~~\n<code>\n");
  1290. }
  1291. if (text.match(/~~CLOSE_HTML_BLOCK~~/)) {
  1292. text = text.replace(/~~CLOSE_HTML_BLOCK~~\n*/gm, "\n</code>\n\n~~CLOSE_HTML_BLOCK~~\n\n");
  1293. }
  1294. /*interwiki frasl refactoring*/
  1295. if (this.interwiki) {
  1296. // text = text.replace(String.frasl,"\/");
  1297. }
  1298. if (this.interwiki && results.match(/>\w+\s*\|$/)) {
  1299. this.interwiki = false;
  1300. if (this.attr) {
  1301. results += text;
  1302. } else {
  1303. results = results.replace(/>\w+\s*\|$/, '>' + text);
  1304. }
  1305. return;
  1306. }
  1307. if (this.in_multi_plugin) {
  1308. text = text.replace('&lt; ', '&lt;');
  1309. }
  1310. text = text.replace(/&#39;/g, "'"); //replace single quote entities with single quotes
  1311. text = text.replace(/^(&gt;)+/, function(match, quotes) {
  1312. return (match.replace(/(&gt;)/g, "\__QUOTE__"));
  1313. });
  1314. text = text.replace(/&not;ags/g, '&notags'); //replace &not entity in include notags param
  1315. //adjust spacing on multi-formatted strings
  1316. results = results.replace(/([\/\*_])_FORMAT_SPACE_([\/\*_]{2})_FORMAT_SPACE_$/, "$1$2@@_SP_@@");
  1317. if (text.match(/^&\w+;/)) {
  1318. results = results.replace(/_FORMAT_SPACE_\s*$/, ""); // remove unwanted space after character entity
  1319. }
  1320. if (this.link_only) {
  1321. if (text) {
  1322. replacement = '|' + text + '}} ';
  1323. results = results.replace(/\}\}\s*$/, replacement);
  1324. }
  1325. return;
  1326. }
  1327. if (!this.code_type) {
  1328. if (!this.last_col_pipes) {
  1329. text = text.replace(/\x20{6,}/, " ");
  1330. text = text.replace(/^(&nbsp;)+\s*$/, '_FCKG_BLANK_TD_');
  1331. text = text.replace(/(&nbsp;)+/, ' ');
  1332. }
  1333. if (this.format_tag) {
  1334. if (!this.list_started || this.in_table) text = text.replace(/^\s+/, '@@_SP_@@');
  1335. } else if (this.last_tag == 'a') {
  1336. text = text.replace(/^\s{2,}/, " ");
  1337. } else if (!this.using_fonts) text = text.replace(/^\s+/, '');
  1338. if (text.match(/nowiki&gt;/)) {
  1339. HTMLParser_NOWIKI = true;
  1340. }
  1341. if (this.format_in_list || (HTMLParserFont && this.list_started)) {
  1342. text = text.replace(/^[\n\s]+$/g, '');
  1343. if (text.match(/\n{2,}\s{1,}/)) {
  1344. text = text.replace(/\n{2,}/, "\n");
  1345. }
  1346. }
  1347. if (this.in_td && !text) {
  1348. // text = "_FCKG_BLANK_TD_";
  1349. this.in_td = false;
  1350. }
  1351. } else {
  1352. text = text.replace(/&lt;\s/g, '<');
  1353. text = text.replace(/\s&gt;/g, '>');
  1354. var geshi = text.match(/^\s*geshi:\s+(.*)$/m);
  1355. if (geshi) {
  1356. results = results.replace(/<(code|file)>\s*$/, '<' + "$1" + ' ' + geshi[1] + '>');
  1357. text = text.replace(geshi[0], "");
  1358. }
  1359. }
  1360. if (this.attr && this.attr == 'dwfcknote') {
  1361. if (text.match(/fckgL\d+/)) {
  1362. return;
  1363. }
  1364. if (text.match(/^[\-,:;!_]/)) {
  1365. results += text;
  1366. } else {
  1367. results += ' ' + text;
  1368. }
  1369. return;
  1370. }
  1371. if (this.downloadable_code && (this.export_code || this.code_snippet)) {
  1372. this.downloadable_file = text;
  1373. return;
  1374. }
  1375. /* remove space between link end markup and following punctuation */
  1376. if (this.last_tag == 'a' && text.match(/^[\.,;\:\!]/)) {
  1377. results = results.replace(/\s$/, "");
  1378. }
  1379. if (this.in_header) {
  1380. text = text.replace(/---/g, '&mdash;');
  1381. text = text.replace(/--/g, '&ndash;');
  1382. }
  1383. if (this.list_started) {
  1384. results = results.replace(/_LIST_EOFL_\s*L_BR_K\s*$/, '_LIST_EOFL_');
  1385. }
  1386. if (!this.code_type) { // keep special character literals outside of code block
  1387. // don't touch samba share or Windows path backslashes
  1388. if (!results.match(/\[\[\\\\.*?\|$/) && !text.match(/\w:(\\(\w?))+/)) {
  1389. if (!text.match(/\\\\[\w\.\-\_]+\\[\w\.\-\_]+/)) {
  1390. text = text.replace(/([\\])/g, '%%$1%%');
  1391. }
  1392. text = text.replace(/([\*])/g, '_CKG_ASTERISK_');
  1393. }
  1394. }
  1395. if (this.in_endnotes && HTMLParserTopNotes.length) {
  1396. if (text.match(/\w/) && !text.match(/^\s*\d\)\s*$/)) {
  1397. text = text.replace(/\)\s*$/, "_FN_PAREN_C_");
  1398. var index = HTMLParserTopNotes.length - 1;
  1399. if (this.bottom_url) {
  1400. if (this.link_class && this.link_class == 'media') {
  1401. text = '{{' + this.bottom_url + '|' + text + '}}';
  1402. } else text = '[[' + this.bottom_url + '|' + text + ']]';
  1403. }
  1404. if (HTMLParserBottomNotes[HTMLParserTopNotes[index]]) {
  1405. text = text.replace('(', 'L_PARgr');
  1406. text = text.replace(')', 'R_PARgr');
  1407. HTMLParserBottomNotes[HTMLParserTopNotes[index]] += ' ' + text;
  1408. } else {
  1409. text = text.replace('(', 'L_PARgr');
  1410. text = text.replace(')', 'R_PARgr');
  1411. HTMLParserBottomNotes[HTMLParserTopNotes[index]] = text;
  1412. }
  1413. }
  1414. this.bottom_url = false;
  1415. return;
  1416. }
  1417. if (text && text.length) {
  1418. results += text;
  1419. }
  1420. // remove space between formatted character entity and following character string
  1421. results = results.replace(/(&\w+;)\s*([\*\/_]{2})_FORMAT_SPACE_(\w+)/, "$1$2$3");
  1422. if (this.list_level && this.list_level > 1) {
  1423. results = results.replace(/(\[\[.*?\]\])([ ]+[\*\-].*)$/, " $1\n$2");
  1424. }
  1425. try { // in case regex throws error on dynamic regex creation
  1426. var regex = new RegExp('([\*\/\_]{2,})_FORMAT_SPACE_([\*\/\_]{2,})(' + RegExp.escape(text) + ')$');
  1427. if (results.match(regex)) {
  1428. // remove left-over space inside multiple format sequences
  1429. results = results.replace(regex, "$1$2$3");
  1430. }
  1431. } catch (ex) {}
  1432. if (!HTMLParserOpenAngleBracket) {
  1433. if (text.match(/&lt;/)) {
  1434. HTMLParserOpenAngleBracket = true;
  1435. }
  1436. }
  1437. },
  1438. comment: function(text) {
  1439. // results += "<!--" + text + "-->";
  1440. },
  1441. dbg: function(text, heading) {
  1442. if (text.replace) {
  1443. text = text.replace(/^\s+/g, "");
  1444. text = text.replace(/^\n$/g, "");
  1445. text = text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
  1446. if (!text) return;
  1447. }
  1448. if (heading) {
  1449. heading = '<b>' + heading + "</b>\n";
  1450. }
  1451. HTMLParser_DEBUG += heading + text + "\n__________\n";
  1452. }
  1453. });
  1454. /*
  1455. we allow escaping of troublesome characters in plugins by enclosing them withinback slashes, as in \*\
  1456. the escapes are removed here together with any DW percent escapes
  1457. */
  1458. results = results.replace(/(\[\[\\\\)(.*?)\]\]/gm, function(match, brackets, block) {
  1459. block = block.replace(/\\/g, "_SMB_");
  1460. return brackets + block + ']]';
  1461. });
  1462. results = results.replace(/%%\\%%/g, '_ESC_BKSLASH_');
  1463. results = results.replace(/%*\\%*([^\w\\]{1})%*\\%*/g, "$1");
  1464. results = results.replace(/_SMB_/g, "\\");
  1465. results = results.replace(/(\s*={2,}).*?CKGE_TMP_(\w+)(.*?).*?CKGE_TMP_c?\2.*?\1/gm, function(m, tag) { //remove formats from headers
  1466. m = m.replace(/CKGE_TMP_\w+/gm, "");
  1467. var v = jQuery("#formatdel").val();
  1468. if (!v) {
  1469. jQuery('#dw__editform').append('<input type="hidden" id="formatdel" name="formatdel" value="del" />');
  1470. }
  1471. return m;
  1472. });
  1473. results = results.replace(/\s?(CKGE_TMP_\w+)\s?/gm, function(m, tag) {
  1474. if ($FORMAT_SUBST[tag]) return $FORMAT_SUBST[tag];
  1475. return m;
  1476. });
  1477. results = results.replace(/(\s*={2,})(.*?)(\[\[|\{\{)(.*?)(\]\]|\}\})(.*?)\1/gm, function(m, h_markup, whatever, bracket_1, inner, bracket_2, end_str) {
  1478. end_str = end_str.replace(/\[\[(.*?)\|(.*?)\]\]/g, "$2");
  1479. end_str = end_str.replace(/\{\{(.*?)\|(.*?)\}\}/g, "$2");
  1480. m = h_markup + " " + whatever + " " + inner.replace(/.*?\|(.*?)/, "$1") + " " + end_str + " " + h_markup;
  1481. var v = jQuery("#formatdel").val();
  1482. if (!v) {
  1483. jQuery('#dw__editform').append('<input type="hidden" id="formatdel" name="formatdel" value="del" />');
  1484. }
  1485. return m;
  1486. });
  1487. if (id == 'test') {
  1488. if (!HTMLParser_test_result(results)) return;
  1489. }
  1490. results = results.replace(/\{ \{ rss&gt;Feed:/mg, '{{rss&gt;http://');
  1491. results = results.replace(/\{ \{ rss&gt;sFeed:/mg, '{{rss&gt;https://')
  1492. results = results.replace(/~ ~ (NOCACHE|NOTOC)~ ~/mg, '~~' + "$1" + '~~');
  1493. if (HTML_InterWiki) {
  1494. var ReplaceLinkMatch = function(tag, link) {
  1495. tag_1 = tag.replace(/oIWIKIo(.*)cIWIKIc/, "$1");
  1496. if (tag_1 == link) return true;
  1497. link = link.replace(/\s/, '%20');
  1498. return (link == tag_1);
  1499. };
  1500. results = results.replace(/\[\[(\w+\.?\w{0,12})>(.*?)\|(.*?)\]\]/gm, function(match, id, iw_replace, link_text) {
  1501. if (iw_replace == 'oIWIKIocIWIKIc') iw_replace = link_text;
  1502. if ((iw_replace == 'oIWIKIo' + link_text.replace(/\s/, '%20') + 'cIWIKIc') || (iw_replace == link_text) || ReplaceLinkMatch(iw_replace, link_text)) {
  1503. link_text = "";
  1504. } else {
  1505. link_text = "|" + link_text;
  1506. }
  1507. return ('[[' + id + '>' + iw_replace + link_text + ']]');
  1508. });
  1509. }
  1510. results = results.replace(/>.*?oIWIKIo(.*?)cIWIKIc/mg, '>' + "$1");
  1511. if (HTMLParser_FORMAT_SPACE) {
  1512. if (HTMLParser_COLSPAN) {
  1513. results = results.replace(/\s*([\|\^]+)((\W\W_FORMAT_SPACE_)+)/gm, function(match, pipes, format) {
  1514. format = format.replace(/_FORMAT_SPACE_/g, "");
  1515. return (format + pipes);
  1516. });
  1517. }
  1518. results = results.replace(/&quot;/g, '"');
  1519. var regex = new RegExp(HTMLParser_FORMAT_SPACE + '([\\-]{2,})', "g");
  1520. results = results.replace(regex, " $1");
  1521. results = results.replace(/\]\](\*\*|\/\/|\'\'|__|<\/del>)_FORMAT_SPACE_/, "]]$1@@_SP_@@");
  1522. var regex = new RegExp("(&amp;|\\W|\\w|\\d)(\\*\\*|\\/\\/|\\'\\'|__|<\/del>)+" + HTMLParser_FORMAT_SPACE + '(\\w|\\d)', "g");
  1523. results = results.replace(regex, "$1$2$3");
  1524. var regex = new RegExp(HTMLParser_FORMAT_SPACE + '@@_SP_@@', "g");
  1525. results = results.replace(regex, ' ');
  1526. //spacing around entities with double format characters
  1527. results = results.replace(/([\*\/_]{2})@@_SP_@@(&\w+;)/g, "$1 $2");
  1528. results = results.replace(/\n@@_SP_@@\n/g, '');
  1529. results = results.replace(/@@_SP_@@\n/g, '');
  1530. results = results.replace(/@@_SP_@@/g, ' ');
  1531. var regex = new RegExp(HTMLParser_FORMAT_SPACE + '([^\\)\\]\\}\\{\\-\\.,;:\\!\?"\x94\x92\u201D\u2019' + "'" + '])', "g");
  1532. results = results.replace(regex, " $1");
  1533. regex = new RegExp(HTMLParser_FORMAT_SPACE, "g");
  1534. results = results.replace(regex, '');
  1535. if (HTMLFormatInList) {
  1536. /* removes extra newlines from lists */
  1537. results = results.replace(/^(\s+[\-\*_]\s*)([\*\/_\']{2})(.*?)(\2)([^\n]*)\n+/gm,
  1538. function(match, list_type, format, text, list_type_close, rest) {
  1539. return (list_type + format + text + list_type_close + rest + "\n");
  1540. });
  1541. }
  1542. }
  1543. /* Fixes for links in lists*/
  1544. if (HTMLLinkInList) {
  1545. /*fix for links in lists at ends of lines, which cause loss of line-feeds
  1546. results = results.replace(/(\]\]|\}\})(\s+)(\*|-)/mg,
  1547. function(match,link,spaces,type) {
  1548. spaces = spaces.replace(/\n/,"");
  1549. return (link + "\n" + spaces+type);
  1550. });
  1551. /*fix for links in lists before ends of lines, which cause extra line-feeds */
  1552. results = results.replace(/(\*|-).*?(\[\[|\{\{).*?(\]\]|\}\})([\s\w\/\-\x3A-\x40\x5B-\x60\x7B-\x7F,;\>\<\&]+)\n\n/mg,
  1553. function(all, type, b, c, tail) {
  1554. all = all.replace(/[\n]$/, "");
  1555. return (all);
  1556. });
  1557. }
  1558. var line_break_final = "\\\\";
  1559. if (HTMLParser_LBR) {
  1560. results = results.replace(/(L_BR_K)+/g, line_break_final);
  1561. results = results.replace(/L_BR_K/gm, line_break_final);
  1562. results = results.replace(/(\\\\)\s+/gm, "$1 \n");
  1563. }
  1564. if (HTMLParser_PRE) {
  1565. results = results.replace(/\s+<\/(code|file)>/g, "\n</" + "$1" + ">");
  1566. if (HTMLParser_Geshi) {
  1567. results = results.replace(/\s+;/mg, ";");
  1568. results = results.replace(/&lt;\s+/mg, "<");
  1569. results = results.replace(/\s+&gt;/mg, ">");
  1570. }
  1571. }
  1572. if (HTMLParser_TABLE) {
  1573. results += "\n" + line_break_final + "\n";
  1574. var regex = new RegExp(HTMLParserParaInsert, "g");
  1575. results = results.replace(regex, ' ' + line_break_final + ' ');
  1576. // fix for colspans which have had text formatting which cause extra empty cells to be created
  1577. results = results.replace(/(\||\^)[ ]+(\||\^)\s$/g, "$1\n");
  1578. results = results.replace(/(\||\^)[ ]+(\||\^)/g, "$1");
  1579. }
  1580. // prevents valid empty td/th cells from being removed above
  1581. results = results.replace(/_FCKG_BLANK_TD_/g, " ");
  1582. if (HTMLParserOpenAngleBracket) {
  1583. results = results.replace(/\/\/&lt;\/\/\s*/g, '&lt;');
  1584. }
  1585. if (HTMLParserFont) // HTMLParserFont start
  1586. {
  1587. String.prototype.font_link_reconcile = function(v) {
  1588. if (v == 1) {
  1589. regex = /\[\[(.*?)(<font[^\>]+>)([^<]+(\]\])?)[^\>]+\/font>\s*(\]\])/gm;
  1590. } else regex = /(<font[^\>\{]+>)\{\{(:?.*?)\|(:?.*?)<\/font>/gm;
  1591. return (
  1592. this.replace(
  1593. regex,
  1594. function(m, a, b, c) {
  1595. a = a.replace(/\n/gm, "");
  1596. a = a.replace(/\s/gm, "");
  1597. a = a.replace(/[\[\]\{\}]/g, "");
  1598. a = a.replace(/\|/g, "");
  1599. c = c.replace(/\n/gm, "");
  1600. // c = c.replace(/\s/gm, "");
  1601. c = c.replace(/[\[\]\}\{]/g, "");
  1602. if (v == 1)
  1603. c = '[[' + a + '|' + c + ']]';
  1604. else c = '{{' + b + '|' + c + '}}';
  1605. var val = prompt(LANG.plugins.ckgedit.font_err_1 + "\n" + c + "\n" + LANG.plugins.ckgedit.font_err_2);
  1606. if (val == null) {
  1607. if (ckgedit_to_dwedit) {
  1608. ckgedit_to_dwedit = false;
  1609. return c;
  1610. } else throw new Error(LANG.plugins.ckgedit.font_err_throw);
  1611. }
  1612. if (val) return val;
  1613. return c;
  1614. }
  1615. )
  1616. );
  1617. }
  1618. if (HTMLParserFontInfix) {
  1619. results = results.replace(/<\/font>\s{1}/gm, "</font>");
  1620. }
  1621. if (fontConflict()) {
  1622. if (confirm(LANG.plugins.ckgedit.font_conflict)) return;
  1623. var v = jQuery("#fontdel").val();
  1624. if (!v) {
  1625. jQuery('#dw__editform').append('<input type="hidden" id="fontdel" name="fontdel" value="del" />');
  1626. }
  1627. }
  1628. results = results.font_link_reconcile(1);
  1629. results = results.font_link_reconcile(2);
  1630. var regex = /\>\s+(\*\*|__|\/\/|'')\s+_\s+\1\s+<\/font>/gm;
  1631. results = results.replace(regex, function(m) {
  1632. m = m.replace(/\s+/g, "");
  1633. return m;
  1634. });
  1635. results = results.replace(/\[\[(.*?)\|(<font[^\>]+>)(.*?)(<\/font>)\s*(\]\])\s*/gm, function(match, a, b, c) {
  1636. match = '[[' + a + '|' + c + ']]';
  1637. var v = jQuery("#fontdel").val();
  1638. if (!v) {
  1639. jQuery('#dw__editform').append('<input type="hidden" id="fontdel" name="fontdel" value="del" />');
  1640. }
  1641. return match;
  1642. });
  1643. results = results.replace(/(\s*={2,})\s*(.*?)(<font[^\>]+>)(.*?)(<\/font>)(.*?)\s*\1/gm, function(match) {
  1644. match = match.replace(/<\/font>/g, " ");
  1645. match = match.replace(/<font.*?>/g, " ");
  1646. var v = jQuery("#formatdel").val();
  1647. if (!v) {
  1648. jQuery('#dw__editform').append('<input type="hidden" id="formatdel" name="formatdel" value="del" />');
  1649. }
  1650. return match;
  1651. });
  1652. } // HTMLParserFont end
  1653. if (HTMLParserTopNotes.length) {
  1654. results = results.replace(/<sup>\(\(\){2,}\s*<\/sup>/g, "");
  1655. results = results.replace(/\(\(+(\d+)\)\)+/, "(($1))");
  1656. for (var i in HTMLParserBottomNotes) { // re-insert DW's bottom notes at text level
  1657. var matches = i.match(/_(\d+)/);
  1658. var pattern = new RegExp('(\<sup\>)*[\(]+' + matches[1] + '[\)]+(<\/sup>)*');
  1659. HTMLParserBottomNotes[i] = HTMLParserBottomNotes[i].replace(/(\d+)_FN_PAREN_C_/, "");
  1660. results = results.replace(pattern, '((' + HTMLParserBottomNotes[i].replace(/_FN_PAREN_C_/g, ") ") + '))');
  1661. }
  1662. results = results.replace(/<sup><\/sup>/g, "");
  1663. results = results.replace(/((<sup>\(\(\d+\)\)\)?<\/sup>))/mg, function(fn) {
  1664. if (!fn.match(/p>\(\(\d+/)) {
  1665. return "";
  1666. }
  1667. return fn;
  1668. });
  1669. }
  1670. results = results.replace(/(={3,}.*?)(\{\{.*?\}\})(.*?={3,})/g, "$1$3\n\n$2");
  1671. // remove any empty footnote markup left after section re-edits
  1672. results = results.replace(/(<sup>)*\s*\[\[\s*\]\]\s*(<\/sup>)*\n*/g, "");
  1673. // remove piled up sups with ((notes))
  1674. results = results.replace(/<sup>\s*\(\(\d+\)\)\s*<\/sup>/mg, "");
  1675. if (HTMLParser_MULTI_LINE_PLUGIN) {
  1676. results = results.replace(/<\s+/g, '<');
  1677. results = results.replace(/&lt;\s+/g, '<');
  1678. }
  1679. if (HTMLParser_NOWIKI) {
  1680. /* any characters escaped by DW %%<char>%% are replaced by NOWIKI_<char>
  1681. <char> is restored in save.php
  1682. */
  1683. var nowiki_escapes = '%'; //this technique allows for added chars to attach to NOWIKI_$1_
  1684. var regex = new RegExp('([' + nowiki_escapes + '])', "g");
  1685. results = results.replace(/(&lt;nowiki&gt;)(.*?)(&lt;\/nowiki&gt;)/mg,
  1686. function(all, start, mid, close) {
  1687. mid = mid.replace(/%%(.)%%/mg, "NOWIKI_$1_");
  1688. return start + mid.replace(regex, "NOWIKI_$1_") + close;
  1689. });
  1690. }
  1691. results = results.replace(/__SWF__(\s*)\[*/g, "{{$1");
  1692. results = results.replace(/\|.*?\]*(\s*)__FWS__/g, "$1}}");
  1693. results = results.replace(/(\s*)__FWS__/g, "$1}}");
  1694. results = results.replace(/\n{3,}/g, '\n\n');
  1695. results = results.replace(/_LIST_EOFL_/gm, " " + line_break_final + " ");
  1696. if (useComplexTables) {
  1697. if (results.indexOf('~~COMPLEX_TABLES~~') == -1) {
  1698. results += "~~COMPLEX_TABLES~~\n";
  1699. }
  1700. }
  1701. if (!useComplexTables) {
  1702. results = results.replace(/~~COMPLEX_TABLES~~/gm, "");
  1703. }
  1704. results = results.replace(/_CKG_ASTERISK_/gm, '*');
  1705. results = results.replace(/_ESC_BKSLASH_/g, '\\');
  1706. results = results.replace(/divalNLine/gm, "\n");
  1707. if (id == 'test') {
  1708. if (HTMLParser_test_result(results)) {
  1709. alert(results);
  1710. }
  1711. return;
  1712. }
  1713. var dwform = GetE('dw__editform');
  1714. dwform.elements.fck_wikitext.value = results;
  1715. if (id == 'bakup') {
  1716. return;
  1717. }
  1718. if (id) {
  1719. var dom = GetE(id);
  1720. dom.click();
  1721. return true;
  1722. }
  1723. }
  1724. jQuery(document).ready(function() {
  1725. var edit__summary = false;
  1726. jQuery(document).on("keydown", "input#edit__summary", function(e) {
  1727. if (e.which == 13) {
  1728. edit__summary = true;
  1729. jQuery("#save_button").trigger("mousedown");
  1730. }
  1731. });
  1732. jQuery("#ebut_test").mousedown(function() {
  1733. parse_wikitext('test');
  1734. });
  1735. jQuery("#ebtn__delete").click(function() {
  1736. if (edit__summary) {
  1737. edit__summary = false;
  1738. return;
  1739. }
  1740. return confirm(JSINFO['confirm_delete']);
  1741. });
  1742. jQuery("#ebtn__delete").mouseup(function() {
  1743. draft_delete();
  1744. });
  1745. jQuery("#ebtn__dwedit").click(function() {
  1746. ckgedit_to_dwedit = true;
  1747. setDWEditCookie(2, this);
  1748. parse_wikitext('edbtn__save');
  1749. this.form.submit();
  1750. });
  1751. jQuery("#ebtn__fbswitch").click(function() {
  1752. if (getCookie('ckgFbOpt') == 'dokuwiki') {
  1753. document.cookie = 'ckgFbOpt=ckgedit;SameSite=Lax';
  1754. } else {
  1755. document.cookie = 'ckgFbOpt=dokuwiki;SameSite=Lax';
  1756. }
  1757. parse_wikitext('edbtn__save');
  1758. this.form.submit();
  1759. });
  1760. jQuery("#ckgedit_draft_btn").click(function() {
  1761. ckgedit_get_draft();
  1762. });
  1763. jQuery("#backup_button").click(function() {
  1764. renewLock(true);
  1765. });
  1766. jQuery("#revert_to_prev_btn").click(function() {
  1767. revert_to_prev();
  1768. });
  1769. jQuery("#no_styling_btn").click(function() {
  1770. this.form.styling.value = "no_styles";
  1771. this.form.prefix.value = "";
  1772. this.form.suffix.value = "";
  1773. this.form.rev.value = "";
  1774. });
  1775. jQuery("#ebut_cancel").mouseup(function() {
  1776. if (this.form.template && this.form.template.value == 'tpl') return;
  1777. if (window.dwfckTextChanged) return;
  1778. draft_delete();
  1779. });
  1780. jQuery("#save_button").mousedown(function() {
  1781. if (this.form.template && this.form.template.value == 'tpl') window.dwfckTextChanged = true;
  1782. if (!window.dwfckTextChanged && !JSINFO['cg_rev']) {
  1783. ckgedit_dwedit_reject = true;
  1784. parse_wikitext('ebut_cancel');
  1785. } else {
  1786. parse_wikitext('edbtn__save');
  1787. }
  1788. });
  1789. });