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