├── .gitignore ├── README.md ├── css ├── print_style.css ├── style.css └── theme-balupton.css ├── icon_128.png ├── index.html ├── issues.html ├── js ├── functions.js └── jquery.syntaxhighlighter.min.js ├── manifest.json ├── screenshot.png └── wmd ├── showdown.js ├── wmd-toolbar.png ├── wmd.css └── wmd.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## What is it? 2 | 3 | This is a Markdown editor, which is based on [WMD](http://github.com/innocead/wmd), the editor from the [Stack Exchange](stackexchange.com) sites. It uses jQuery and the [jQuery Syntax Highlighter by balupton](http://balupton.com/projects/jquery-syntaxhighlighter). 4 | 5 | You can see a live version of it [on my homepage](http://homepage.univie.ac.at/werner.robitza/markdown). 6 | 7 | ## Screenshot 8 | 9 |  10 | 11 | ## Issues 12 | 13 | Probably quite a few. Report them on github, please. -------------------------------------------------------------------------------- /css/print_style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin:0; 3 | padding:0; 4 | } 5 | 6 | body { 7 | font-family: "Helvetica Neue", Helvetica, Verdana, sans-serif; 8 | font-size: 12px; 9 | color: #333; 10 | } 11 | 12 | 13 | textarea { 14 | width:580px; 15 | } 16 | 17 | #tools { 18 | margin-top:20px; 19 | } 20 | 21 | #tools .toolbutton { 22 | width: auto; 23 | float:left; 24 | margin-right:5px; 25 | padding: 5px; 26 | border: 1px solid #999; 27 | border-radius:8px; 28 | background-color: #eee; 29 | } 30 | 31 | 32 | 33 | 34 | /* CONTENT STYLING */ 35 | #preview p, dt, dd { 36 | font-size: 12px; 37 | line-height: 15px; 38 | text-align: justify; 39 | margin-bottom:10px; 40 | } 41 | 42 | #preview pre, blockquote { 43 | line-height: 1.714em; 44 | margin-bottom: 1.714em; 45 | } 46 | 47 | #preview h1 { 48 | font-size: 24px; 49 | line-height: 30px; 50 | margin-top: 20px; 51 | margin-bottom: 15px; 52 | } 53 | 54 | #preview h2 { 55 | font-size: 20px; 56 | line-height: 24px; 57 | margin-top: 14px; 58 | margin-bottom: 10px; 59 | } 60 | 61 | #preview h3 { 62 | font-size: 14px; 63 | line-height: 18px; 64 | margin-top: 10px; 65 | margin-bottom: 8px; 66 | } 67 | 68 | #preview h4 { 69 | font-size: 12px; 70 | line-height: 14px; 71 | margin-top: 10px; 72 | margin-bottom: 8px; 73 | } 74 | 75 | #preview hr { 76 | margin-top: 1.6em; 77 | } 78 | 79 | #preview input { 80 | font-size: 1.0em; 81 | } 82 | 83 | #preview ul { 84 | list-style: square; 85 | } 86 | 87 | #preview li { 88 | padding-bottom:10px; 89 | } 90 | #preview a { 91 | color:#069; 92 | text-decoration: none; 93 | } 94 | #preview a:hover { 95 | text-decoration: underline; 96 | } 97 | 98 | #preview blockquote { 99 | margin-left:5px; 100 | padding:1px; 101 | padding-left:10px; 102 | padding-right:10px; 103 | border-left:2px double #999; 104 | color: #C0C0C0; 105 | } 106 | 107 | #preview code, pre { 108 | font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; 109 | color: #808080; 110 | font-size:1.0em; 111 | } 112 | 113 | #preview pre { 114 | padding:5px; 115 | margin-left:5px; 116 | display:block; 117 | width:auto; 118 | border-left:1px dotted #999; 119 | overflow: wrap; 120 | white-space: pre-wrap; /* css-3 */ 121 | white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ 122 | white-space: -pre-wrap; /* Opera 4-6 */ 123 | white-space: -o-pre-wrap; /* Opera 7 */ 124 | word-wrap: break-word; /* Internet Explorer 5.5+ */ 125 | } 126 | 127 | /* HAX: Disable all borders from prettify */ 128 | #preview pre *, #preview code { 129 | border:none !important; 130 | } 131 | 132 | #preview code { 133 | display:inline; 134 | } 135 | 136 | #preview ul, #preview ol { 137 | margin-left:20px; 138 | } 139 | 140 | #footer { 141 | height:20px; 142 | width:100%; 143 | 144 | position: fixed; 145 | bottom: 0px; 146 | 147 | padding:10px; 148 | 149 | border-top:1px solid #999; 150 | 151 | background-color:#333; 152 | font-size:0.9em; 153 | color:#aaa; 154 | } 155 | 156 | #footer a { 157 | color: #aaa; 158 | } -------------------------------------------------------------------------------- /css/style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin:0; 3 | padding:0; 4 | } 5 | 6 | body { 7 | font-family: "Helvetica Neue", Helvetica, Verdana, sans-serif; 8 | font-size: 12px; 9 | color: #333; 10 | } 11 | 12 | /* LEFT SIDE: EDITOR */ 13 | #editor { 14 | width:580px; 15 | position:fixed; 16 | left:20px; 17 | top:20px; 18 | } 19 | 20 | textarea { 21 | width:580px; 22 | } 23 | 24 | #tools { 25 | margin-top:20px; 26 | } 27 | 28 | #tools .toolbutton { 29 | width: auto; 30 | float:left; 31 | margin-right:5px; 32 | padding: 5px; 33 | border: 1px solid #999; 34 | border-radius:8px; 35 | background-color: #eee; 36 | } 37 | 38 | 39 | /* RIGHT SIDE: PREVIEW */ 40 | #preview { 41 | min-height:450px; 42 | width:600px; 43 | padding: 20px; 44 | border-left:1px solid #999; 45 | position:relative; 46 | left:620px; 47 | color:#000; 48 | } 49 | 50 | 51 | /* CONTENT STYLING */ 52 | #preview p, dt, dd { 53 | font-size: 12px; 54 | line-height: 15px; 55 | text-align: justify; 56 | margin-bottom:10px; 57 | } 58 | 59 | #preview pre, blockquote { 60 | line-height: 1.714em; 61 | margin-bottom: 1.714em; 62 | } 63 | 64 | #preview h1 { 65 | font-size: 24px; 66 | line-height: 30px; 67 | margin-top: 20px; 68 | margin-bottom: 15px; 69 | } 70 | 71 | #preview h2 { 72 | font-size: 20px; 73 | line-height: 24px; 74 | margin-top: 14px; 75 | margin-bottom: 10px; 76 | } 77 | 78 | #preview h3 { 79 | font-size: 14px; 80 | line-height: 18px; 81 | margin-top: 10px; 82 | margin-bottom: 8px; 83 | } 84 | 85 | #preview h4 { 86 | font-size: 12px; 87 | line-height: 14px; 88 | margin-top: 10px; 89 | margin-bottom: 8px; 90 | } 91 | 92 | #preview hr { 93 | margin-top: 1.6em; 94 | } 95 | 96 | #preview input { 97 | font-size: 1.0em; 98 | } 99 | 100 | #preview ul { 101 | list-style: square; 102 | } 103 | 104 | #preview li { 105 | padding-bottom:10px; 106 | } 107 | #preview a { 108 | color:#069; 109 | text-decoration: none; 110 | } 111 | #preview a:hover { 112 | text-decoration: underline; 113 | } 114 | 115 | #preview blockquote { 116 | margin-left:5px; 117 | padding:1px; 118 | padding-left:10px; 119 | padding-right:10px; 120 | border-left:1px solid #999; 121 | background-color:#eee; 122 | } 123 | 124 | #preview code, pre { 125 | font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; 126 | background-color:#eee; 127 | font-size:1.0em; 128 | } 129 | 130 | #preview pre { 131 | padding:5px; 132 | margin-left:5px; 133 | display:block; 134 | width:auto; 135 | overflow: auto !important; 136 | } 137 | 138 | /* HAX: Disable all borders from prettify */ 139 | #preview pre *, #preview code { 140 | border:none !important; 141 | } 142 | 143 | #preview code { 144 | display:inline; 145 | } 146 | 147 | #preview ul, #preview ol { 148 | margin-left:20px; 149 | } 150 | 151 | #footer { 152 | height:20px; 153 | width:100%; 154 | 155 | position: fixed; 156 | bottom: 0px; 157 | 158 | padding:10px; 159 | 160 | border-top:1px solid #999; 161 | 162 | background-color:#333; 163 | font-size:0.9em; 164 | color:#aaa; 165 | } 166 | 167 | #footer a { 168 | color: #aaa; 169 | } -------------------------------------------------------------------------------- /css/theme-balupton.css: -------------------------------------------------------------------------------- 1 | .prettyprint { 2 | padding: 0px !important; /* Hack for inline code */ 3 | } 4 | .prettyprint.theme-balupton .com { 5 | color: #008200; /* balupton green */ 6 | } 7 | .prettyprint.theme-balupton .lit { 8 | color: #066; /* google green */ 9 | } 10 | .prettyprint.theme-balupton.lang-html .lit { 11 | /* CSS Property Value */ 12 | color: #066; /* google green */ 13 | } 14 | .prettyprint.theme-balupton.lang-html .kwd { 15 | /* CSS Property Value Keyword */ 16 | color: #066; /* google green */ 17 | font-weight:bold; 18 | } 19 | .prettyprint.theme-balupton.lang-html .atv + .pln, 20 | .prettyprint.theme-balupton.lang-html .pun + .pln { 21 | /* CSS Property Name */ 22 | color: blue; 23 | } 24 | .prettyprint.theme-balupton .atv, 25 | .prettyprint.theme-balupton .str { 26 | color: blue; 27 | } 28 | .prettyprint.theme-balupton .atn { 29 | color: gray; 30 | } 31 | .prettyprint.theme-balupton .pln { 32 | color: black; 33 | } 34 | .prettyprint.theme-balupton .pun { 35 | color: #666; 36 | } 37 | .prettyprint.theme-balupton .typ { 38 | color: #606; 39 | } 40 | .prettyprint.theme-balupton .tag, 41 | .prettyprint.theme-balupton .kwd { 42 | color: #006699; 43 | font-weight: bold; 44 | } -------------------------------------------------------------------------------- /icon_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/slhck/online-markdown-editor/dee57008d5e59940c78eb70be07c0893d2779588/icon_128.png -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |Report issues on github please. I don't know if I have time to look into them though.
12 |s around 211 | // "paragraphs" that are wrapped in non-block-level tags, such as anchors, 212 | // phrase emphasis, and spans. The list of tags we're looking for is 213 | // hard-coded: 214 | var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del" 215 | var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math" 216 | 217 | // First, look for nested blocks, e.g.: 218 | //
tags around block-level tags.
365 | text = _HashHTMLBlocks(text);
366 | text = _FormParagraphs(text);
367 |
368 | return text;
369 | }
370 |
371 |
372 | var _RunSpanGamut = function(text) {
373 | //
374 | // These are all the transformations that occur *within* block-level
375 | // tags like paragraphs, headers, and list items.
376 | //
377 |
378 | text = _DoCodeSpans(text);
379 | text = _EscapeSpecialCharsWithinTagAttributes(text);
380 | text = _EncodeBackslashEscapes(text);
381 |
382 | // Process anchor and image tags. Images must come first,
383 | // because ![foo][f] looks like an anchor.
384 | text = _DoImages(text);
385 | text = _DoAnchors(text);
386 |
387 | // Make links out of things like ` Just type tags
1043 | //
1044 |
1045 | // Strip leading and trailing lines:
1046 | text = text.replace(/^\n+/g,"");
1047 | text = text.replace(/\n+$/g,"");
1048 |
1049 | var grafs = text.split(/\n{2,}/g);
1050 | var grafsOut = new Array();
1051 |
1052 | //
1053 | // Wrap tags.
1054 | //
1055 | var end = grafs.length;
1056 | for (var i=0; i ");
1066 | str += "
\n");
396 |
397 | return text;
398 | }
399 |
400 | var _EscapeSpecialCharsWithinTagAttributes = function(text) {
401 | //
402 | // Within tags -- meaning between < and > -- encode [\ ` * _] so they
403 | // don't conflict with their use in Markdown for code, italics and strong.
404 | //
405 |
406 | // Build a regex to find HTML tags and comments. See Friedl's
407 | // "Mastering Regular Expressions", 2nd Ed., pp. 200-201.
408 | var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|)/gi;
409 |
410 | text = text.replace(regex, function(wholeMatch) {
411 | var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");
412 | tag = escapeCharacters(tag,"\\`*_");
413 | return tag;
414 | });
415 |
416 | return text;
417 | }
418 |
419 | var _DoAnchors = function(text) {
420 | //
421 | // Turn Markdown link shortcuts into XHTML tags.
422 | //
423 | //
424 | // First, handle reference-style links: [link text] [id]
425 | //
426 |
427 | /*
428 | text = text.replace(/
429 | ( // wrap whole match in $1
430 | \[
431 | (
432 | (?:
433 | \[[^\]]*\] // allow brackets nested one level
434 | |
435 | [^\[] // or anything else
436 | )*
437 | )
438 | \]
439 |
440 | [ ]? // one optional space
441 | (?:\n[ ]*)? // one optional newline followed by spaces
442 |
443 | \[
444 | (.*?) // id = $3
445 | \]
446 | )()()()() // pad remaining backreferences
447 | /g,_DoAnchors_callback);
448 | */
449 | text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);
450 |
451 | //
452 | // Next, inline-style links: [link text](url "optional title")
453 | //
454 |
455 | /*
456 | text = text.replace(/
457 | ( // wrap whole match in $1
458 | \[
459 | (
460 | (?:
461 | \[[^\]]*\] // allow brackets nested one level
462 | |
463 | [^\[\]] // or anything else
464 | )
465 | )
466 | \]
467 | \( // literal paren
468 | [ \t]*
469 | () // no id, so leave $3 empty
470 | (.*?)>? // href = $4
471 | [ \t]*
472 | ( // $5
473 | (['"]) // quote char = $6
474 | (.*?) // Title = $7
475 | \6 // matching quote
476 | [ \t]* // ignore any spaces/tabs between closing quote and )
477 | )? // title is optional
478 | \)
479 | )
480 | /g,writeAnchorTag);
481 | */
482 | text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);
483 |
484 | //
485 | // Last, handle reference-style shortcuts: [link text]
486 | // These must come last in case you've also got [link test][1]
487 | // or [link test](/foo)
488 | //
489 |
490 | /*
491 | text = text.replace(/
492 | ( // wrap whole match in $1
493 | \[
494 | ([^\[\]]+) // link text = $2; can't contain '[' or ']'
495 | \]
496 | )()()()()() // pad rest of backreferences
497 | /g, writeAnchorTag);
498 | */
499 | text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
500 |
501 | return text;
502 | }
503 |
504 | var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
505 | if (m7 == undefined) m7 = "";
506 | var whole_match = m1;
507 | var link_text = m2;
508 | var link_id = m3.toLowerCase();
509 | var url = m4;
510 | var title = m7;
511 |
512 | if (url == "") {
513 | if (link_id == "") {
514 | // lower-case and turn embedded newlines into spaces
515 | link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
516 | }
517 | url = "#"+link_id;
518 |
519 | if (g_urls[link_id] != undefined) {
520 | url = g_urls[link_id];
521 | if (g_titles[link_id] != undefined) {
522 | title = g_titles[link_id];
523 | }
524 | }
525 | else {
526 | if (whole_match.search(/\(\s*\)$/m)>-1) {
527 | // Special case for explicit empty url
528 | url = "";
529 | } else {
530 | return whole_match;
531 | }
532 | }
533 | }
534 |
535 | url = escapeCharacters(url,"*_");
536 | var result = "" + link_text + "";
545 |
546 | return result;
547 | }
548 |
549 |
550 | var _DoImages = function(text) {
551 | //
552 | // Turn Markdown image shortcuts into tags.
553 | //
554 |
555 | //
556 | // First, handle reference-style labeled images: ![alt text][id]
557 | //
558 |
559 | /*
560 | text = text.replace(/
561 | ( // wrap whole match in $1
562 | !\[
563 | (.*?) // alt text = $2
564 | \]
565 |
566 | [ ]? // one optional space
567 | (?:\n[ ]*)? // one optional newline followed by spaces
568 |
569 | \[
570 | (.*?) // id = $3
571 | \]
572 | )()()()() // pad rest of backreferences
573 | /g,writeImageTag);
574 | */
575 | text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);
576 |
577 | //
578 | // Next, handle inline images: 
579 | // Don't forget: encode * and _
580 |
581 | /*
582 | text = text.replace(/
583 | ( // wrap whole match in $1
584 | !\[
585 | (.*?) // alt text = $2
586 | \]
587 | \s? // One optional whitespace character
588 | \( // literal paren
589 | [ \t]*
590 | () // no id, so leave $3 empty
591 | (\S+?)>? // src url = $4
592 | [ \t]*
593 | ( // $5
594 | (['"]) // quote char = $6
595 | (.*?) // title = $7
596 | \6 // matching quote
597 | [ \t]*
598 | )? // title is optional
599 | \)
600 | )
601 | /g,writeImageTag);
602 | */
603 | text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
604 |
605 | return text;
606 | }
607 |
608 | var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
609 | var whole_match = m1;
610 | var alt_text = m2;
611 | var link_id = m3.toLowerCase();
612 | var url = m4;
613 | var title = m7;
614 |
615 | if (!title) title = "";
616 |
617 | if (url == "") {
618 | if (link_id == "") {
619 | // lower-case and turn embedded newlines into spaces
620 | link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");
621 | }
622 | url = "#"+link_id;
623 |
624 | if (g_urls[link_id] != undefined) {
625 | url = g_urls[link_id];
626 | if (g_titles[link_id] != undefined) {
627 | title = g_titles[link_id];
628 | }
629 | }
630 | else {
631 | return whole_match;
632 | }
633 | }
634 |
635 | alt_text = alt_text.replace(/"/g,""");
636 | url = escapeCharacters(url,"*_");
637 | var result = "
";
649 |
650 | return result;
651 | }
652 |
653 |
654 | var _DoHeaders = function(text) {
655 |
656 | // Setext-style headers:
657 | // Header 1
658 | // ========
659 | //
660 | // Header 2
661 | // --------
662 | //
663 | text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
664 | function(wholeMatch,m1){return hashBlock("
" + _RunSpanGamut(m1) + "
");});
665 |
666 | text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
667 | function(matchFound,m1){return hashBlock("" + _RunSpanGamut(m1) + "
");});
668 |
669 | // atx-style headers:
670 | // # Header 1
671 | // ## Header 2
672 | // ## Header 2 with closing hashes ##
673 | // ...
674 | // ###### Header 6
675 | //
676 |
677 | /*
678 | text = text.replace(/
679 | ^(\#{1,6}) // $1 = string of #'s
680 | [ \t]*
681 | (.+?) // $2 = Header text
682 | [ \t]*
683 | \#* // optional closing #'s (not counted)
684 | \n+
685 | /gm, function() {...});
686 | */
687 |
688 | text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
689 | function(wholeMatch,m1,m2) {
690 | var h_level = m1.length;
691 | return hashBlock("` blocks.
849 | //
850 |
851 | /*
852 | text = text.replace(text,
853 | /(?:\n\n|^)
854 | ( // $1 = the code block -- one or more lines, starting with a space/tab
855 | (?:
856 | (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
857 | .*\n+
858 | )+
859 | )
860 | (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
861 | /g,function(){...});
862 | */
863 |
864 | // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
865 | text += "~0";
866 |
867 | text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
868 | function(wholeMatch,m1,m2) {
869 | var codeblock = m1;
870 | var nextChar = m2;
871 |
872 | codeblock = _EncodeCode( _Outdent(codeblock));
873 | codeblock = _Detab(codeblock);
874 | codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
875 | codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
876 |
877 | codeblock = "
";
878 |
879 | return hashBlock(codeblock) + nextChar;
880 | }
881 | );
882 |
883 | // attacklab: strip sentinel
884 | text = text.replace(/~0/,"");
885 |
886 | return text;
887 | }
888 |
889 | var hashBlock = function(text) {
890 | text = text.replace(/(^\n+|\n+$)/g,"");
891 | return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";
892 | }
893 |
894 |
895 | var _DoCodeSpans = function(text) {
896 | //
897 | // * Backtick quotes are used for " + codeblock + "\n
spans.
898 | //
899 | // * You can use multiple backticks as the delimiters if you want to
900 | // include literal backticks in the code span. So, this input:
901 | //
902 | // Just type ``foo `bar` baz`` at the prompt.
903 | //
904 | // Will translate to:
905 | //
906 | //
foo `bar` baz
at the prompt.`bar`
...
919 | //
920 |
921 | /*
922 | text = text.replace(/
923 | (^|[^\\]) // Character before opening ` can't be a backslash
924 | (`+) // $2 = Opening run of `
925 | ( // $3 = The code block
926 | [^\r]*?
927 | [^`] // attacklab: work around lack of lookbehind
928 | )
929 | \2 // Matching closer
930 | (?!`)
931 | /gm, function(){...});
932 | */
933 |
934 | text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
935 | function(wholeMatch,m1,m2,m3,m4) {
936 | var c = m3;
937 | c = c.replace(/^([ \t]*)/g,""); // leading whitespace
938 | c = c.replace(/[ \t]*$/g,""); // trailing whitespace
939 | c = _EncodeCode(c);
940 | return m1+""+c+"
";
941 | });
942 |
943 | return text;
944 | }
945 |
946 |
947 | var _EncodeCode = function(text) {
948 | //
949 | // Encode/escape certain characters inside Markdown code runs.
950 | // The point is that in code, these characters are literals,
951 | // and lose their special Markdown meanings.
952 | //
953 | // Encode all ampersands; HTML entities are not
954 | // entities within a Markdown code span.
955 | text = text.replace(/&/g,"&");
956 |
957 | // Do the angle bracket song and dance:
958 | text = text.replace(//g,">");
960 |
961 | // Now, escape characters that are magic in Markdown:
962 | text = escapeCharacters(text,"\*_{}[]\\",false);
963 |
964 | // jj the line above breaks this:
965 | //---
966 |
967 | //* Item
968 |
969 | // 1. Subitem
970 |
971 | // special char: *
972 | //---
973 |
974 | return text;
975 | }
976 |
977 |
978 | var _DoItalicsAndBold = function(text) {
979 |
980 | // must go first:
981 | text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\1/g,
982 | "$2");
983 |
984 | text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
985 | "$2");
986 |
987 | return text;
988 | }
989 |
990 |
991 | var _DoBlockQuotes = function(text) {
992 |
993 | /*
994 | text = text.replace(/
995 | ( // Wrap whole match in $1
996 | (
997 | ^[ \t]*>[ \t]? // '>' at the start of a line
998 | .+\n // rest of the first line
999 | (.+\n)* // subsequent consecutive lines
1000 | \n* // blanks
1001 | )+
1002 | )
1003 | /gm, function(){...});
1004 | */
1005 |
1006 | text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
1007 | function(wholeMatch,m1) {
1008 | var bq = m1;
1009 |
1010 | // attacklab: hack around Konqueror 3.5.4 bug:
1011 | // "----------bug".replace(/^-/g,"") == "bug"
1012 |
1013 | bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0"); // trim one level of quoting
1014 |
1015 | // attacklab: clean up hack
1016 | bq = bq.replace(/~0/g,"");
1017 |
1018 | bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines
1019 | bq = _RunBlockGamut(bq); // recurse
1020 |
1021 | bq = bq.replace(/(^|\n)/g,"$1 ");
1022 | // These leading spaces screw with content, so we need to fix that:
1023 | bq = bq.replace(
1024 | /(\s*
[^\r]+?<\/pre>)/gm,
1025 | function(wholeMatch,m1) {
1026 | var pre = m1;
1027 | // attacklab: hack around Konqueror 3.5.4 bug:
1028 | pre = pre.replace(/^ /mg,"~0");
1029 | pre = pre.replace(/~0/g,"");
1030 | return pre;
1031 | });
1032 |
1033 | return hashBlock("
\n" + bq + "\n
");
1034 | });
1035 | return text;
1036 | }
1037 |
1038 |
1039 | var _FormParagraphs = function(text) {
1040 | //
1041 | // Params:
1042 | // $text - string to process with html Ctl+Q",codeTitle:"Code Sample
Ctl+K",imgTitle:"Image
Ctl+G",olTitle:"Numbered List
Ctl+O",ulTitle:"Bulleted List
Ctl+U",hTitle:"Heading
/
Ctl+H",hrTitle:"Horizontal Rule
Ctl+R",strongText:"Bold",emText:"Italic",aText:"Link",blockquoteText:"Blockquote",codeText:"Code",imgText:"Image",olText:"Numbered List",ulText:"Bulleted List",hText:"Heading",hrText:"Horizontal Rule",insertImage:"Insert image",imageURL:"Image URL",enterCodeHere:"enter code here",blockquote:"Blockquote",insertLink:"Insert link",linkURL:"Link URL",submit:"Submit",cancel:"Cancel"};Translator_RU={urlFieldInsertion:'(например, http://google.com)',linkText:"название ссылки",imageAlt:"описание картинки",listItem:"текст",strongTitle:"Жирный Ctl+B",emTitle:"Курсив Ctl+I",aTitle:"Вставить ссылку Ctl+L",blockquoteTitle:"Ыитировать Ctl+Q",codeTitle:"Вставить пример кода
";}element.appendChild(labelElement);}inner=document.createElement("div");if(options.inline){inner.className=options.inlineCss;}element.appendChild(inner);errorElement=document.createElement("div");errorElement.className=options.reasonCss;errorElement.style.display="none";element.appendChild(errorElement);switch(type){case ("empty"):break;case ("checkbox"):case ("radio"):inputs=Field.createInputList(inner,type,options);break;case ("select"):inputs=Field.createSelectList(inner,type,options);setFor=true;break;case ("textarea"):inputs=Field.createTextArea(inner,type,options);setFor=true;break;default:inputs=Field.createInput(inner,type,options);setFor=true;break;}if(typeof inputs==="undefined"){inputs=null;}if(labelElement&&setFor){labelElement.setAttribute("for",Field.getInputId(options));}extend(element,{addEvent:function(event,callback){var c=function(){callback(element);},input,i,n;if(inputs){switch(type){case ("empty"):break;case ("checkbox"):case ("radio"):for(i=0,n=inputs.length;i Ctl+K",imgTitle:"Вставить картинку
Ctl+G",olTitle:"Нумерованный список
Ctl+O",ulTitle:"Маркированный список
Ctl+U",hTitle:"Вставить заголовок
/
Ctl+H",hrTitle:"Горизонтальная черта
Ctl+R",strongText:"Bold",emText:"Italic",aText:"Link",blockquoteText:"Blockquote",codeText:"Code",imgText:"Image",olText:"Numbered List",ulText:"Bulleted List",hText:"Heading",hrText:"Horizontal Rule",insertImage:"Вставить картинку",imageURL:"Адрес картинки",enterCodeHere:"вставьте код сдесь",blockquote:"текст цитаты",insertLink:"Вставить ссылку",linkURL:"Ссылка",submit:"Ок",cancel:"Отмена"};Translator=Translator_EN;function chooseTranslator(lang){if(lang=="RU"){Translator=Translator_RU;}else{Translator=Translator_EN;}Command.builtIn={strong:{text:Translator.strongText,title:Translator.strongTitle,css:"wmd-strong",shortcut:"b"},em:{text:Translator.emText,title:Translator.emTitle,css:"wmd-em",shortcut:"i"},a:{text:Translator.aText,title:Translator.aTitle,css:"wmd-a",shortcut:"l"},blockquote:{text:Translator.blockquoteText,title:Translator.blockquoteTitle,css:"wmd-blockquote",shortcut:"q"},code:{text:Translator.codeText,title:Translator.codeTitle,css:"wmd-code",shortcut:"k"},img:{text:Translator.imgText,title:Translator.imgTitle,css:"wmd-img",shortcut:"g"},ol:{text:Translator.olText,title:Translator.olTitle,css:"wmd-ol",shortcut:"o"},ul:{text:Translator.ulText,title:Translator.ulTitle,css:"wmd-ul",shortcut:"u"},h:{text:Translator.hText,title:Translator.hTitle,css:"wmd-h",shortcut:"h"},hr:{text:Translator.hrText,title:Translator.hrTitle,css:"wmd-hr",shortcut:"r"},spacer:{css:"wmd-spacer",builder:Command.createSpacer}};}
4 | Chunk=function(text,selectionStartIndex,selectionEndIndex,selectionScrollTop){var prefixes="(?:\\s{4,}|\\s*>|\\s*-\\s+|\\s*\\d+\\.|=|\\+|-|_|\\*|#|\\s*\\[[^\n]]+\\]:)",obj={};return extend(obj,{before:fixEol(text.substring(0,selectionStartIndex)),selection:fixEol(text.substring(selectionStartIndex,selectionEndIndex)),after:fixEol(text.substring(selectionEndIndex)),scrollTop:selectionScrollTop,startTag:"",endTag:"",addBlankLines:function(numberBefore,numberAfter,findExtra){var regexText,replacementText,match;numberBefore=(typeof numberBefore==="undefined"||numberBefore===null)?1:numberBefore;numberAfter=(typeof numberAfter==="undefined"||numberAfter===null)?1:numberAfter;numberBefore=numberBefore+1;numberAfter=numberAfter+1;match=/(^\n*)/.exec(this.selection);this.selection=this.selection.replace(/(^\n*)/,"");this.startTag=this.startTag+(match?match[1]:"");match=/(\n*$)/.exec(this.selection);this.selection=this.selection.replace(/(\n*$)/,"");this.endTag=this.endTag+(match?match[1]:"");match=/(^\n*)/.exec(this.startTag);this.startTag=this.startTag.replace(/(^\n*)/,"");this.before=this.before+(match?match[1]:"");match=/(\n*$)/.exec(this.endTag);this.endTag=this.endTag.replace(/(\n*$)/,"");this.after=this.after+(match?match[1]:"");if(this.before){regexText=replacementText="";while(numberBefore>0){regexText=regexText+"\\n?";replacementText=replacementText+"\n";numberBefore=numberBefore-1;}if(findExtra){regexText="\\n*";}this.before=this.before.replace(new RegExp(regexText+"$",""),replacementText);}if(this.after){regexText=replacementText="";while(numberAfter>0){regexText=regexText+"\\n?";replacementText=replacementText+"\n";numberAfter=numberAfter-1;}if(findExtra){regexText="\\n*";}this.after=this.after.replace(new RegExp(regexText,""),replacementText);}return this;},setTags:function(startExp,endExp){var that=this,tempExp;if(startExp){tempExp=extendRegExp(startExp,"","$");this.before=this.before.replace(tempExp,function(match){that.startTag=that.startTag+match;return"";});tempExp=extendRegExp(startExp,"^","");this.selection=this.selection.replace(tempExp,function(match){that.startTag=that.startTag+match;return"";});}if(endExp){tempExp=extendRegExp(endExp,"","$");this.selection=this.selection.replace(tempExp,function(match){that.endTag=match+that.endTag;return"";});tempExp=extendRegExp(endExp,"^","");this.after=this.after.replace(tempExp,function(match){that.endTag=match+that.endTag;return"";});}return this;},trimWhitespace:function(remove){this.selection=this.selection.replace(/^(\s*)/,"");if(!remove){this.before=this.before+RegExp.$1;}this.selection=this.selection.replace(/(\s*)$/,"");if(!remove){this.after=RegExp.$1+this.after;}return this;},unwrap:function(){var text=new RegExp("([^\\n])\\n(?!(\\n|"+prefixes+"))","g");this.selection=this.selection.replace(text,"$1 $2");return this;},wrap:function(len){var regex=new RegExp("(.{1,"+len+"})( +|$\\n?)","gm");this.unwrap();this.selection=this.selection.replace(regex,function(line,marked){if(new RegExp("^"+prefixes,"").test(line)){return line;}return marked+"\n";});this.selection=this.selection.replace(/\s+$/,"");return this;}});};
5 | InputState=function(wmd){var obj={},input=wmd.input;obj=extend(obj,{scrollTop:0,text:"",start:0,end:0,getChunk:function(){return new Chunk(this.text,this.start,this.end,this.scrollTop);},restore:function(){if(this.text!==input.value){input.value=this.text;}this.setInputSelection();input.scrollTop=this.scrollTop;},setChunk:function(chunk){chunk.before=chunk.before+chunk.startTag;chunk.after=chunk.endTag+chunk.after;if(browser.Opera){chunk.before=chunk.before.replace(/\n/g,"\r\n");chunk.selection=chunk.selection.replace(/\n/g,"\r\n");chunk.after=chunk.after.replace(/\n/g,"\r\n");}this.start=chunk.before.length;this.end=chunk.before.length+chunk.selection.length;this.text=chunk.before+chunk.selection+chunk.after;this.scrollTop=chunk.scrollTop;},setInputSelection:function(){var range;if(visible(input)){input.focus();if(input.selectionStart||input.selectionStart===0){input.selectionStart=this.start;input.selectionEnd=this.end;input.scrollTop=this.scrollTop;}else{if(document.selection){if(!document.activeElement||document.activeElement===input){range=input.createTextRange();range.moveStart("character",-1*input.value.length);range.moveEnd("character",-1*input.value.length);range.moveEnd("character",this.end);range.moveStart("character",this.start);range.select();}}}}},setStartEnd:function(){var range,fixedRange,markedRange,rangeText,len,marker="\x07";if(visible(input)){if(input.selectionStart||input.selectionStart===0){this.start=input.selectionStart;this.end=input.selectionEnd;}else{if(document.selection){this.text=fixEol(input.value);if(wmd.ieClicked&&wmd.ieRange){range=wmd.ieRange;wmd.ieClicked=false;}else{range=document.selection.createRange();}fixedRange=fixEol(range.text);markedRange=marker+fixedRange+marker;range.text=markedRange;rangeText=fixEol(input.value);range.moveStart("character",-1*markedRange.length);range.text=fixedRange;this.start=rangeText.indexOf(marker);this.end=rangeText.lastIndexOf(marker)-marker.length;len=this.text.length-fixEol(input.value).length;if(len>0){range.moveStart("character",-1*fixedRange.length);while(len>0){fixedRange=fixedRange+"\n";this.end=this.end+1;len=len-1;}range.text=fixedRange;}this.setInputSelection();}}}}});if(visible(input)){input.focus();obj.setStartEnd();obj.scrollTop=input.scrollTop;if(input.selectionStart||input.selectionStart===0){obj.text=input.value;}}return obj;};
6 | Command=function(wmd,definition,runner,options){options=extend({downCssSuffix:"-down"},options);var element,obj={},downCss=definition.css+options.downCssSuffix;function resetCss(){if(element){element.className=Command.css.base+" "+definition.css;}}return extend(obj,{draw:function(parent){var span,downCss=definition.css+options.downCssSuffix;if(!element){element=document.createElement("li");element.title=definition.title;parent.appendChild(element);span=document.createElement("span");span.innerHTML=definition.text;element.appendChild(span);addEvent(element,"click",function(event){resetCss();obj.run();});addEvent(element,"mouseover",function(event){resetCss();addClassName(element,Command.css.over);});addEvent(element,"mouseout",function(event){resetCss();});addEvent(element,"mousedown",function(event){resetCss();addClassName(element,Command.css.down);addClassName(element,downCss);if(browser.IE){wmd.ieClicked=true;wmd.ieRange=document.selection.createRange();}});}else{parent.appendChild(element);}resetCss();},run:function(){var state=new InputState(wmd),chunk=state.getChunk();runner(wmd,chunk,function(){state.setChunk(chunk);state.restore();});}});};extend(Command,{css:{base:"wmd-command",over:"wmd-command-over",down:"wmd-command-down"},autoIndent:function(wmd,chunk,callback,args){args=extend(args,{preventDefaultText:true});chunk.before=chunk.before.replace(/(\n|^)[ ]{0,3}([*+-]|\d+[.])[ \t]*\n$/,"\n\n");chunk.before=chunk.before.replace(/(\n|^)[ ]{0,3}>[ \t]*\n$/,"\n\n");chunk.before=chunk.before.replace(/(\n|^)[ \t]+\n$/,"\n\n");if(/(\n|^)[ ]{0,3}([*+-])[ \t]+.*\n$/.test(chunk.before)){Command.runners.ul(wmd,chunk,callback,extend(args,{preventDefaultText:false}));}else{if(/(\n|^)[ ]{0,3}(\d+[.])[ \t]+.*\n$/.test(chunk.before)){Command.runners.ol(wmd,chunk,callback,extend(args,{preventDefaultText:false}));}else{if(/(\n|^)[ ]{0,3}>[ \t]+.*\n$/.test(chunk.before)){Command.runners.blockquote(wmd,chunk,callback,args);}else{if(/(\n|^)(\t|[ ]{4,}).*\n$/.test(chunk.before)){Command.runners.code(wmd,chunk,callback,args);}else{if(typeof callback==="function"){callback();}}}}}},create:function(wmd,key,definition){return new Command(wmd,definition,Command.runners[key]);},createSpacer:function(wmd,key,definition){var element=null;return{draw:function(parent){var span;if(!element){element=document.createElement("li");element.className=Command.css.base+" "+definition.css;parent.appendChild(element);span=document.createElement("span");element.appendChild(span);}else{parent.appendChild(element);}return element;},run:function(){}};},createSubmitCancelForm:function(title,onSubmit,onDestroy){var cancel=document.createElement("a"),form=new Form(title,{dialog:true,onSubmit:onSubmit,onDestroy:onDestroy}),submitField=new Field("","submit",{value:Translator.submit});form.addField("submit",submitField);cancel.href="javascript:void(0);";cancel.innerHTML=Translator.cancel;cancel.onclick=function(){form.destroy();};submitField.insert(" or ");submitField.insert(cancel);return form;},runLinkImage:function(wmd,chunk,callback,args){var callback=typeof callback==="function"?callback:function(){};function make(link){var linkDef,num;if(link){chunk.startTag=chunk.endTag="";linkDef=" [999]: "+link;num=LinkHelper.add(chunk,linkDef);chunk.startTag=args.tag==="img"?"![":"[";chunk.endTag="]["+num+"]";if(!chunk.selection){if(args.tag==="img"){chunk.selection=Translator.imageAlt;}else{chunk.selection=Translator.linkText;}}}}chunk.trimWhitespace();chunk.setTags(/\s*!?\[/,/\][ ]?(?:\n[ ]*)?(\[.*?\])?/);if(chunk.endTag.length>1){chunk.startTag=chunk.startTag.replace(/!?\[/,"");chunk.endTag="";LinkHelper.add(chunk);callback();}else{if(/\n\n/.test(chunk.selection)){LinkHelper.add(chunk);callback();}else{if(typeof args.prompt==="function"){args.prompt(function(link){make(link);callback();});}else{make(args.link||null);callback();}}}},runList:function(wmd,chunk,callback,args){var previousItemsRegex=/(\n|^)(([ ]{0,3}([*+-]|\d+[.])[ \t]+.*)(\n.+|\n{2,}([*+-].*|\d+[.])[ \t]+.*|\n{2,}[ \t]+\S.*)*)\n*$/,nextItemsRegex=/^\n*(([ ]{0,3}([*+-]|\d+[.])[ \t]+.*)(\n.+|\n{2,}([*+-].*|\d+[.])[ \t]+.*|\n{2,}[ \t]+\S.*)*)\n*/,finished=false,bullet="-",num=1,hasDigits,nLinesBefore,prefix,nLinesAfter,spaces;callback=typeof callback==="function"?callback:function(){};function getItemPrefix(){var prefix;if(args.tag==="ol"){prefix=" "+num+". ";num=num+1;}else{prefix=" "+bullet+" ";}return prefix;}function getPrefixedItem(itemText){if(args.tag===undefined){args.tag=/^\s*\d/.test(itemText)?"ol":"ul";}itemText=itemText.replace(/^[ ]{0,3}([*+-]|\d+[.])\s/gm,function(_){return getItemPrefix();});return itemText;}chunk.setTags(/(\n|^)*[ ]{0,3}([*+-]|\d+[.])\s+/,null);if(chunk.before&&!/\n$/.test(chunk.before)&&!/^\n/.test(chunk.startTag)){chunk.before=chunk.before+chunk.startTag;chunk.startTag="";}if(chunk.startTag){hasDigits=/\d+[.]/.test(chunk.startTag);chunk.startTag="";chunk.selection=chunk.selection.replace(/\n[ ]{4}/g,"\n");chunk.unwrap();chunk.addBlankLines();if(hasDigits){chunk.after=chunk.after.replace(nextItemsRegex,getPrefixedItem);}if(hasDigits&&args.tag==="ol"){finished=true;}}if(!finished){nLinesBefore=1;chunk.before=chunk.before.replace(previousItemsRegex,function(itemText){if(/^\s*([*+-])/.test(itemText)){bullet=RegExp.$1;}nLinesBefore=/[^\n]\n\n[^\n]/.test(itemText)?1:0;return getPrefixedItem(itemText);});if(!chunk.selection){chunk.selection=args.preventDefaultText?" ":Translator.listItem;}prefix=getItemPrefix();nLinesAfter=1;chunk.after=chunk.after.replace(nextItemsRegex,function(itemText){nLinesAfter=/[^\n]\n\n[^\n]/.test(itemText)?1:0;return getPrefixedItem(itemText);});chunk.trimWhitespace(true);chunk.addBlankLines(nLinesBefore,nLinesAfter,true);chunk.startTag=prefix;spaces=prefix.replace(/./g," ");chunk.wrap(wmd.options.lineLength-spaces.length);chunk.selection=chunk.selection.replace(/\n/g,"\n"+spaces);}callback();},runStrongEm:function(wmd,chunk,callback,args){var starsBefore,starsAfter,prevStars,markup;callback=typeof callback==="function"?callback:function(){};extend({stars:2},args);chunk.trimWhitespace();chunk.selection=chunk.selection.replace(/\n{2,}/g,"\n");chunk.before.search(/(\**$)/);starsBefore=RegExp.$1;chunk.after.search(/(^\**)/);starsAfter=RegExp.$1;prevStars=Math.min(starsBefore.length,starsAfter.length);if((prevStars>=args.stars)&&(prevStars!==2||args.stars!==1)){chunk.before=chunk.before.replace(RegExp("[*]{"+args.stars+"}$",""),"");chunk.after=chunk.after.replace(RegExp("^[*]{"+args.stars+"}",""),"");}else{if(!chunk.selection&&starsAfter){chunk.after=chunk.after.replace(/^([*_]*)/,"");chunk.before=chunk.before.replace(/(\s?)$/,"");chunk.before=chunk.before+starsAfter+RegExp.$1;}else{if(!chunk.selection&&!starsAfter){chunk.selection=args.text||"";}markup=args.stars<=1?"*":"**";chunk.before=chunk.before+markup;chunk.after=markup+chunk.after;}}callback();},runners:{a:function(wmd,chunk,callback,args){Command.runLinkImage(wmd,chunk,callback,extend({tag:"a",prompt:function(onComplete){LinkHelper.createDialog(Translator.insertLink,Translator.linkURL,onComplete);}},args));},blockquote:function(wmd,chunk,callback,args){args=args||{};callback=typeof callback==="function"?callback:function(){};chunk.selection=chunk.selection.replace(/^(\n*)([^\r]+?)(\n*)$/,function(totalMatch,newlinesBefore,text,newlinesAfter){chunk.before+=newlinesBefore;chunk.after=newlinesAfter+chunk.after;return text;});chunk.before=chunk.before.replace(/(>[ \t]*)$/,function(totalMatch,blankLine){chunk.selection=blankLine+chunk.selection;return"";});chunk.selection=chunk.selection.replace(/^(\s|>)+$/,"");chunk.selection=chunk.selection||(args.preventDefaultText?"":Translator.blockquote);if(chunk.before){chunk.before=chunk.before.replace(/\n?$/,"\n");}if(chunk.after){chunk.after=chunk.after.replace(/^\n?/,"\n");}chunk.before=chunk.before.replace(/(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*$)/,function(totalMatch){chunk.startTag=totalMatch;return"";});chunk.after=chunk.after.replace(/^(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*)/,function(totalMatch){chunk.endTag=totalMatch;return"";});function replaceBlanksInTags(useBracket){var replacement=useBracket?"> ":"";if(chunk.startTag){chunk.startTag=chunk.startTag.replace(/\n((>|\s)*)\n$/,function(totalMatch,markdown){return"\n"+markdown.replace(/^[ ]{0,3}>?[ \t]*$/gm,replacement)+"\n";});}if(chunk.endTag){chunk.endTag=chunk.endTag.replace(/^\n((>|\s)*)\n/,function(totalMatch,markdown){return"\n"+markdown.replace(/^[ ]{0,3}>?[ \t]*$/gm,replacement)+"\n";});}}if(/^(?![ ]{0,3}>)/m.test(chunk.selection)){chunk.wrap(wmd.options.lineLength-2);chunk.selection=chunk.selection.replace(/^/gm,"> ");replaceBlanksInTags(true);chunk.addBlankLines();}else{chunk.selection=chunk.selection.replace(/^[ ]{0,3}> ?/gm,"");chunk.unwrap();replaceBlanksInTags(false);if(!/^(\n|^)[ ]{0,3}>/.test(chunk.selection)&&chunk.startTag){chunk.startTag=chunk.startTag.replace(/\n{0,2}$/,"\n\n");}if(!/(\n|^)[ ]{0,3}>.*$/.test(chunk.selection)&&chunk.endTag){chunk.endTag=chunk.endTag.replace(/^\n{0,2}/,"\n\n");}}if(!/\n/.test(chunk.selection)){chunk.selection=chunk.selection.replace(/^(> *)/,function(wholeMatch,blanks){chunk.startTag=chunk.startTag+blanks;return"";});}callback();},code:function(wmd,chunk,callback,args){args=args||{};callback=typeof callback==="function"?callback:function(){};var textBefore=/\S[ ]*$/.test(chunk.before),textAfter=/^[ ]*\S/.test(chunk.after),linesBefore=1,linesAfter=1;if(!(textBefore&&!textAfter)||/\n/.test(chunk.selection)){chunk.before=chunk.before.replace(/[ ]{4}$/,function(totalMatch){chunk.selection=totalMatch+chunk.selection;return"";});if(/\n(\t|[ ]{4,}).*\n$/.test(chunk.before)||chunk.after===""||/^\n(\t|[ ]{4,})/.test(chunk.after)){linesBefore=0;}chunk.addBlankLines(linesBefore,linesAfter);if(!chunk.selection){chunk.startTag=" ";chunk.selection=args.preventDefaultText?"":Translator.enterCodeHere;}else{if(/^[ ]{0,3}\S/m.test(chunk.selection)){chunk.selection=chunk.selection.replace(/^/gm," ");}else{chunk.selection=chunk.selection.replace(/^[ ]{4}/gm,"");}}}else{chunk.trimWhitespace();chunk.setTags(/`/,/`/);if(!chunk.startTag&&!chunk.endTag){chunk.startTag=chunk.endTag="`";if(!chunk.selection){chunk.selection=args.preventDefaultText?"":Translator.enterCodeHere;}}else{if(chunk.endTag&&!chunk.startTag){chunk.before=chunk.before+chunk.endTag;chunk.endTag="";}else{chunk.startTag=chunk.endTag="";}}}callback();},em:function(wmd,chunk,callback,args){Command.runStrongEm(wmd,chunk,callback,extend({stars:1,text:"emphasized text"},args));},h:function(wmd,chunk,callback,args){args=args||{};callback=typeof callback==="function"?callback:function(){};var headerLevel=0,headerLevelToCreate,headerChar,len;chunk.selection=chunk.selection.replace(/\s+/g," ");chunk.selection=chunk.selection.replace(/(^\s+|\s+$)/g,"");if(!chunk.selection){chunk.startTag="## ";chunk.selection="Heading";chunk.endTag=" ##";}else{chunk.setTags(/#+[ ]*/,/[ ]*#+/);if(/#+/.test(chunk.startTag)){headerLevel=RegExp.lastMatch.length;}chunk.startTag=chunk.endTag="";chunk.setTags(null,/\s?(-+|=+)/);if(/=+/.test(chunk.endTag)){headerLevel=1;}else{if(/-+/.test(chunk.endTag)){headerLevel=2;}}chunk.startTag=chunk.endTag="";chunk.addBlankLines(1,1);headerLevelToCreate=headerLevel===0?2:headerLevel-1;if(headerLevelToCreate>0){headerChar=headerLevelToCreate>=2?"-":"=";len=chunk.selection.length;if(len>wmd.options.lineLength){len=wmd.options.lineLength;}chunk.endTag="\n";while(len>0){chunk.endTag=chunk.endTag+headerChar;len=len-1;}}}callback();},hr:function(wmd,chunk,callback,args){args=args||{};callback=typeof callback==="function"?callback:function(){};chunk.startTag="----------\n";chunk.selection="";chunk.addBlankLines(2,1,true);callback();},img:function(wmd,chunk,callback,args){Command.runLinkImage(wmd,chunk,callback,extend({tag:"img",prompt:function(onComplete){LinkHelper.createDialog(Translator.insertImage,Translator.imageURL,onComplete);}},args));},ol:function(wmd,chunk,callback,args){Command.runList(wmd,chunk,callback,extend({tag:"ol"},args));},strong:function(wmd,chunk,callback,args){Command.runStrongEm(wmd,chunk,callback,extend({stars:2,text:"strong text"},args));},ul:function(wmd,chunk,callback,args){Command.runList(wmd,chunk,callback,extend({tag:"ul"},args));}}});Command.builtIn={strong:{text:Translator.strongText,title:Translator.strongTitle,css:"wmd-strong",shortcut:"b"},em:{text:Translator.emText,title:Translator.emTitle,css:"wmd-em",shortcut:"i"},a:{text:Translator.aText,title:Translator.aTitle,css:"wmd-a",shortcut:"l"},blockquote:{text:Translator.blockquoteText,title:Translator.blockquoteTitle,css:"wmd-blockquote",shortcut:"q"},code:{text:Translator.codeText,title:Translator.codeTitle,css:"wmd-code",shortcut:"k"},img:{text:Translator.imgText,title:Translator.imgTitle,css:"wmd-img",shortcut:"g"},ol:{text:Translator.olText,title:Translator.olTitle,css:"wmd-ol",shortcut:"o"},ul:{text:Translator.ulText,title:Translator.ulTitle,css:"wmd-ul",shortcut:"u"},h:{text:Translator.hText,title:Translator.hTitle,css:"wmd-h",shortcut:"h"},hr:{text:Translator.hrText,title:Translator.hrTitle,css:"wmd-hr",shortcut:"r"},spacer:{css:"wmd-spacer",builder:Command.createSpacer}};
7 | Dialog=function(options){var obj,element,overlay,events=[],options=extend({zIndex:10,css:"wmd-dialog",overlayColor:"#FFFFFF",modal:true,closeOnEsc:true,insertion:null,onDestroy:null},options);function build(){if(!element){if(options.modal){overlay=new Overlay({color:options.overlayColor,zIndex:options.zIndex-1});}element=document.createElement("div");document.body.appendChild(element);element.className=options.css;element.style.position="absolute";element.style.zIndex=options.zIndex;element.style.top=(window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop)+"px";if(options.insertion){obj.fill(options.insertion);}if(options.closeOnEsc){addEvent(document,"keypress",function(event){var ev=event||window.event,keyCode=ev.keyCode||ev.which;if(keyCode===27){obj.destroy();}},events);}}}obj=extend(obj,{destroy:function(){while(events.length>0){removeEvent(events[0].element,events[0].event,events[0].callback,events);}if(overlay){overlay.destroy();overlay=null;}if(element){element.parentNode.removeChild(element);element=null;}if(typeof options.onDestroy==="function"){options.onDestroy(this);}},fill:function(insertion){if(element){element.innerHTML="";insertion=insertion||"";if(typeof insertion==="string"){element.innerHTML=insertion;}else{element.appendChild(insertion);}}},hide:function(){if(element){element.style.display="none";}},redraw:function(){var css;if(element){css=element.className;element.className="";element.className=css;}},show:function(){if(element){element.style.display="";}}});build();return obj;};Overlay=function(options){var obj={},events=[],element,iframe,options=extend({color:"#FFFFFF",zIndex:9,scroll:true,opacity:0.3},options);function update(){var scroll,size;if(element){scroll={left:window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft,top:window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop};size=getViewportDimensions();element.style.width=size.width+"px";element.style.height=size.height+"px";element.style.left=scroll.left+"px";element.style.top=scroll.top+"px";if(iframe){iframe.style.width=size.width+"px";iframe.style.height=size.height+"px";iframe.style.left=scroll.left+"px";iframe.style.top=scroll.top+"px";}}}function build(){if(!element){element=document.createElement("div");document.body.appendChild(element);element.style.position="absolute";element.style.background=options.color;element.style.zIndex=options.zIndex;element.style.opacity=options.opacity;if(browser.IE){element.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+(options.opacity*100)+")";iframe=document.createElement("iframe");document.body.appendChild(iframe);iframe.frameBorder="0";iframe.scrolling="no";iframe.style.position="absolute";iframe.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=0)";iframe.style.zIndex=options.zIndex-1;}if(options.scroll){addEvent(window,"resize",update,events);addEvent(window,"load",update,events);addEvent(window,"scroll",update,events);}update();}}obj=extend(obj,{destroy:function(){while(events.length>0){removeEvent(events[0].element,events[0].event,events[0].callback,events);}if(element){element.parentNode.removeChild(element);element=null;}if(iframe){iframe.parentNode.removeChild(iframe);iframe=null;}}});build();return obj;};
8 | Form=function(title,options){title=title||"";options=extend({css:"wmd-form",legendCss:"wmd-legend",errorCss:"wmd-error",requiredReason:"Required",dialogCss:"wmd-dialog",dialog:false,modal:true,dialogZIndex:10,closeOnEsc:true,id:"",onSubmit:null,onDestroy:null},options);var element,events=[],fields=[],fieldset,error,dialog;if(!options.id){options.id=randomString(6,{upper:false});}element=document.createElement("form");element.id=options.id;element.className=options.css;element.onsubmit=function(){if(typeof options.onSubmit==="function"){options.onSubmit(element);}return false;};fieldset=document.createElement("fieldset");element.appendChild(fieldset);legend=document.createElement("div");legend.className=options.legendCss;legend.style.display="none";fieldset.appendChild(legend);error=document.createElement("div");error.className=options.errorCss;error.style.display="none";fieldset.appendChild(error);if(options.dialog){dialog=new Dialog({modal:options.modal,zIndex:options.dialogZIndex,css:options.dialogCss,closeOnEsc:false,insertion:element});}addEvent(document,"keypress",function(event){var e=event||window.event,keyCode=e.keyCode||e.which;switch(keyCode){case (27):if(options.closeOnEsc){element.destroy();}break;default:break;}},events);function findField(key){var field=null,index=-1,i,n;for(i=0,n=fields.length;i