How to use text.replace method in Cucumber-gherkin

Best JavaScript code snippet using cucumber-gherkin

markdown.converter.js

Source:markdown.converter.js Github

copy

Full Screen

...124 // attacklab: Replace ~ with ~T125 // This lets us use tilde as an escape char to avoid md5 hashes126 // The choice of character is arbitray; anything that isn't127 // magic in Markdown will work.128 text = text.replace(/~/g, "~T");129 // attacklab: Replace $ with ~D130 // RegExp interprets $ as a special character131 // when it's in a replacement string132 text = text.replace(/\$/g, "~D");133 // Standardize line endings134 text = text.replace(/\r\n/g, "\n"); // DOS to Unix135 text = text.replace(/\r/g, "\n"); // Mac to Unix136 // Make sure text begins and ends with a couple of newlines:137 text = "\n\n" + text + "\n\n";138 // Convert all tabs to spaces.139 text = _Detab(text);140 // Strip any lines consisting only of spaces and tabs.141 // This makes subsequent regexen easier to write, because we can142 // match consecutive blank lines with /\n+/ instead of something143 // contorted like /[ \t]*\n+/ .144 text = text.replace(/^[ \t]+$/mg, "");145 // Turn block-level HTML blocks into hash entries146 text = _HashHTMLBlocks(text);147 // Strip link definitions, store in hashes.148 text = _StripLinkDefinitions(text);149 text = _RunBlockGamut(text);150 text = _UnescapeSpecialChars(text);151 // attacklab: Restore dollar signs152 text = text.replace(/~D/g, "$$");153 // attacklab: Restore tildes154 text = text.replace(/~T/g, "~");155 text = pluginHooks.postConversion(text);156 g_html_blocks = g_titles = g_urls = null;157 return text;158 };159 function _StripLinkDefinitions(text) {160 //161 // Strips link definitions from text, stores the URLs and titles in162 // hash references.163 //164 // Link defs are in the form: ^[id]: url "optional title"165 /*166 text = text.replace(/167 ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1168 [ \t]*169 \n? // maybe *one* newline170 [ \t]*171 <?(\S+?)>? // url = $2172 (?=\s|$) // lookahead for whitespace instead of the lookbehind removed below173 [ \t]*174 \n? // maybe one newline175 [ \t]*176 ( // (potential) title = $3177 (\n*) // any lines skipped = $4 attacklab: lookbehind removed178 [ \t]+179 ["(]180 (.+?) // title = $5181 [")]182 [ \t]*183 )? // title is optional184 (?:\n+|$)185 /gm, function(){...});186 */187 text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?(?=\s|$)[ \t]*\n?[ \t]*((\n*)["(](.+?)[")][ \t]*)?(?:\n+)/gm,188 function (wholeMatch, m1, m2, m3, m4, m5) {189 m1 = m1.toLowerCase();190 g_urls.set(m1, _EncodeAmpsAndAngles(m2)); // Link IDs are case-insensitive191 if (m4) {192 // Oops, found blank lines, so it's not a title.193 // Put back the parenthetical statement we stole.194 return m3;195 } else if (m5) {196 g_titles.set(m1, m5.replace(/"/g, "&quot;"));197 }198 // Completely remove the definition from the text199 return "";200 }201 );202 return text;203 }204 function _HashHTMLBlocks(text) {205 // Hashify HTML blocks:206 // We only want to do this for block-level HTML tags, such as headers,207 // lists, and tables. That's because we still want to wrap <p>s around208 // "paragraphs" that are wrapped in non-block-level tags, such as anchors,209 // phrase emphasis, and spans. The list of tags we're looking for is210 // hard-coded:211 var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del"212 var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math"213 // First, look for nested blocks, e.g.:214 // <div>215 // <div>216 // tags for inner block must be indented.217 // </div>218 // </div>219 //220 // The outermost tags must start at the left margin for this to match, and221 // the inner nested divs must be indented.222 // We need to do this before the next, more liberal match, because the next223 // match will start at the first `<div>` and stop at the first `</div>`.224 // attacklab: This regex can be expensive when it fails.225 /*226 text = text.replace(/227 ( // save in $1228 ^ // start of line (with /m)229 <($block_tags_a) // start tag = $2230 \b // word break231 // attacklab: hack around khtml/pcre bug...232 [^\r]*?\n // any number of lines, minimally matching233 </\2> // the matching end tag234 [ \t]* // trailing spaces/tabs235 (?=\n+) // followed by a newline236 ) // attacklab: there are sentinel newlines at end of document237 /gm,function(){...}};238 */239 text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm, hashElement);240 //241 // Now match more liberally, simply from `\n<tag>` to `</tag>\n`242 //243 /*244 text = text.replace(/245 ( // save in $1246 ^ // start of line (with /m)247 <($block_tags_b) // start tag = $2248 \b // word break249 // attacklab: hack around khtml/pcre bug...250 [^\r]*? // any number of lines, minimally matching251 .*</\2> // the matching end tag252 [ \t]* // trailing spaces/tabs253 (?=\n+) // followed by a newline254 ) // attacklab: there are sentinel newlines at end of document255 /gm,function(){...}};256 */257 text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm, hashElement);258 // Special case just for <hr />. It was easier to make a special case than259 // to make the other regex more complicated. 260 /*261 text = text.replace(/262 \n // Starting after a blank line263 [ ]{0,3}264 ( // save in $1265 (<(hr) // start tag = $2266 \b // word break267 ([^<>])*?268 \/?>) // the matching end tag269 [ \t]*270 (?=\n{2,}) // followed by a blank line271 )272 /g,hashElement);273 */274 text = text.replace(/\n[ ]{0,3}((<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, hashElement);275 // Special case for standalone HTML comments:276 /*277 text = text.replace(/278 \n\n // Starting after a blank line279 [ ]{0,3} // attacklab: g_tab_width - 1280 ( // save in $1281 <!282 (--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--) // see http://www.w3.org/TR/html-markup/syntax.html#comments and http://meta.stackoverflow.com/q/95256283 >284 [ \t]*285 (?=\n{2,}) // followed by a blank line286 )287 /g,hashElement);288 */289 text = text.replace(/\n\n[ ]{0,3}(<!(--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>[ \t]*(?=\n{2,}))/g, hashElement);290 // PHP and ASP-style processor instructions (<?...?> and <%...%>)291 /*292 text = text.replace(/293 (?:294 \n\n // Starting after a blank line295 )296 ( // save in $1297 [ ]{0,3} // attacklab: g_tab_width - 1298 (?:299 <([?%]) // $2300 [^\r]*?301 \2>302 )303 [ \t]*304 (?=\n{2,}) // followed by a blank line305 )306 /g,hashElement);307 */308 text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g, hashElement);309 return text;310 }311 function hashElement(wholeMatch, m1) {312 var blockText = m1;313 // Undo double lines314 blockText = blockText.replace(/^\n+/, "");315 // strip trailing blank lines316 blockText = blockText.replace(/\n+$/g, "");317 // Replace the element text with a marker ("~KxK" where x is its key)318 blockText = "\n\n~K" + (g_html_blocks.push(blockText) - 1) + "K\n\n";319 return blockText;320 }321 function _RunBlockGamut(text, doNotUnhash) {322 //323 // These are all the transformations that form block-level324 // tags like paragraphs, headers, and list items.325 //326 text = _DoHeaders(text);327 // Do Horizontal Rules:328 var replacement = "<hr />\n";329 text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, replacement);330 text = text.replace(/^[ ]{0,2}([ ]?-[ ]?){3,}[ \t]*$/gm, replacement);331 text = text.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm, replacement);332 text = _DoLists(text);333 text = _DoCodeBlocks(text);334 text = _DoBlockQuotes(text);335 // We already ran _HashHTMLBlocks() before, in Markdown(), but that336 // was to escape raw HTML in the original Markdown source. This time,337 // we're escaping the markup we've just created, so that we don't wrap338 // <p> tags around block-level tags.339 text = _HashHTMLBlocks(text);340 text = _FormParagraphs(text, doNotUnhash);341 return text;342 }343 function _RunSpanGamut(text) {344 //345 // These are all the transformations that occur *within* block-level346 // tags like paragraphs, headers, and list items.347 //348 text = _DoCodeSpans(text);349 text = _EscapeSpecialCharsWithinTagAttributes(text);350 text = _EncodeBackslashEscapes(text);351 // Process anchor and image tags. Images must come first,352 // because ![foo][f] looks like an anchor.353 text = _DoImages(text);354 text = _DoAnchors(text);355 // Make links out of things like `<http://example.com/>`356 // Must come after _DoAnchors(), because you can use < and >357 // delimiters in inline links like [this](<url>).358 text = _DoAutoLinks(text);359 360 text = text.replace(/~P/g, "://"); // put in place to prevent autolinking; reset now361 362 text = _EncodeAmpsAndAngles(text);363 text = _DoItalicsAndBold(text);364 // Do hard breaks:365 text = text.replace(/ +\n/g, " <br>\n");366 return text;367 }368 function _EscapeSpecialCharsWithinTagAttributes(text) {369 //370 // Within tags -- meaning between < and > -- encode [\ ` * _] so they371 // don't conflict with their use in Markdown for code, italics and strong.372 //373 // Build a regex to find HTML tags and comments. See Friedl's 374 // "Mastering Regular Expressions", 2nd Ed., pp. 200-201.375 // SE: changed the comment part of the regex376 var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>)/gi;377 text = text.replace(regex, function (wholeMatch) {378 var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g, "$1`");379 tag = escapeCharacters(tag, wholeMatch.charAt(1) == "!" ? "\\`*_/" : "\\`*_"); // also escape slashes in comments to prevent autolinking there -- http://meta.stackoverflow.com/questions/95987380 return tag;381 });382 return text;383 }384 function _DoAnchors(text) {385 //386 // Turn Markdown link shortcuts into XHTML <a> tags.387 //388 //389 // First, handle reference-style links: [link text] [id]390 //391 /*392 text = text.replace(/393 ( // wrap whole match in $1394 \[395 (396 (?:397 \[[^\]]*\] // allow brackets nested one level398 |399 [^\[] // or anything else400 )*401 )402 \]403 [ ]? // one optional space404 (?:\n[ ]*)? // one optional newline followed by spaces405 \[406 (.*?) // id = $3407 \]408 )409 ()()()() // pad remaining backreferences410 /g, writeAnchorTag);411 */412 text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeAnchorTag);413 //414 // Next, inline-style links: [link text](url "optional title")415 //416 /*417 text = text.replace(/418 ( // wrap whole match in $1419 \[420 (421 (?:422 \[[^\]]*\] // allow brackets nested one level423 |424 [^\[\]] // or anything else425 )*426 )427 \]428 \( // literal paren429 [ \t]*430 () // no id, so leave $3 empty431 <?( // href = $4432 (?:433 \([^)]*\) // allow one level of (correctly nested) parens (think MSDN)434 |435 [^()]436 )*?437 )>? 438 [ \t]*439 ( // $5440 (['"]) // quote char = $6441 (.*?) // Title = $7442 \6 // matching quote443 [ \t]* // ignore any spaces/tabs between closing quote and )444 )? // title is optional445 \)446 )447 /g, writeAnchorTag);448 */449 text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?((?:\([^)]*\)|[^()])*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeAnchorTag);450 //451 // Last, handle reference-style shortcuts: [link text]452 // These must come last in case you've also got [link test][1]453 // or [link test](/foo)454 //455 /*456 text = text.replace(/457 ( // wrap whole match in $1458 \[459 ([^\[\]]+) // link text = $2; can't contain '[' or ']'460 \]461 )462 ()()()()() // pad rest of backreferences463 /g, writeAnchorTag);464 */465 text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);466 return text;467 }468 function writeAnchorTag(wholeMatch, m1, m2, m3, m4, m5, m6, m7) {469 if (m7 == undefined) m7 = "";470 var whole_match = m1;471 var link_text = m2.replace(/:\/\//g, "~P"); // to prevent auto-linking withing the link. will be converted back after the auto-linker runs472 var link_id = m3.toLowerCase();473 var url = m4;474 var title = m7;475 if (url == "") {476 if (link_id == "") {477 // lower-case and turn embedded newlines into spaces478 link_id = link_text.toLowerCase().replace(/ ?\n/g, " ");479 }480 url = "#" + link_id;481 if (g_urls.get(link_id) != undefined) {482 url = g_urls.get(link_id);483 if (g_titles.get(link_id) != undefined) {484 title = g_titles.get(link_id);485 }486 }487 else {488 if (whole_match.search(/\(\s*\)$/m) > -1) {489 // Special case for explicit empty url490 url = "";491 } else {492 return whole_match;493 }494 }495 }496 url = encodeProblemUrlChars(url);497 url = escapeCharacters(url, "*_");498 var result = "<a href=\"" + url + "\"";499 if (title != "") {500 title = attributeEncode(title);501 title = escapeCharacters(title, "*_");502 result += " title=\"" + title + "\"";503 }504 result += ">" + link_text + "</a>";505 return result;506 }507 function _DoImages(text) {508 //509 // Turn Markdown image shortcuts into <img> tags.510 //511 //512 // First, handle reference-style labeled images: ![alt text][id]513 //514 /*515 text = text.replace(/516 ( // wrap whole match in $1517 !\[518 (.*?) // alt text = $2519 \]520 [ ]? // one optional space521 (?:\n[ ]*)? // one optional newline followed by spaces522 \[523 (.*?) // id = $3524 \]525 )526 ()()()() // pad rest of backreferences527 /g, writeImageTag);528 */529 text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, writeImageTag);530 //531 // Next, handle inline images: ![alt text](url "optional title")532 // Don't forget: encode * and _533 /*534 text = text.replace(/535 ( // wrap whole match in $1536 !\[537 (.*?) // alt text = $2538 \]539 \s? // One optional whitespace character540 \( // literal paren541 [ \t]*542 () // no id, so leave $3 empty543 <?(\S+?)>? // src url = $4544 [ \t]*545 ( // $5546 (['"]) // quote char = $6547 (.*?) // title = $7548 \6 // matching quote549 [ \t]*550 )? // title is optional551 \)552 )553 /g, writeImageTag);554 */555 text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, writeImageTag);556 return text;557 }558 559 function attributeEncode(text) {560 // unconditionally replace angle brackets here -- what ends up in an attribute (e.g. alt or title)561 // never makes sense to have verbatim HTML in it (and the sanitizer would totally break it)562 return text.replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");563 }564 function writeImageTag(wholeMatch, m1, m2, m3, m4, m5, m6, m7) {565 var whole_match = m1;566 var alt_text = m2;567 var link_id = m3.toLowerCase();568 var url = m4;569 var title = m7;570 if (!title) title = "";571 if (url == "") {572 if (link_id == "") {573 // lower-case and turn embedded newlines into spaces574 link_id = alt_text.toLowerCase().replace(/ ?\n/g, " ");575 }576 url = "#" + link_id;577 if (g_urls.get(link_id) != undefined) {578 url = g_urls.get(link_id);579 if (g_titles.get(link_id) != undefined) {580 title = g_titles.get(link_id);581 }582 }583 else {584 return whole_match;585 }586 }587 588 alt_text = escapeCharacters(attributeEncode(alt_text), "*_[]()");589 url = escapeCharacters(url, "*_");590 var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";591 // attacklab: Markdown.pl adds empty title attributes to images.592 // Replicate this bug.593 //if (title != "") {594 title = attributeEncode(title);595 title = escapeCharacters(title, "*_");596 result += " title=\"" + title + "\"";597 //}598 result += " />";599 return result;600 }601 function _DoHeaders(text) {602 // Setext-style headers:603 // Header 1604 // ========605 // 606 // Header 2607 // --------608 //609 text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,610 function (wholeMatch, m1) { return "<h1>" + _RunSpanGamut(m1) + "</h1>\n\n"; }611 );612 text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,613 function (matchFound, m1) { return "<h2>" + _RunSpanGamut(m1) + "</h2>\n\n"; }614 );615 // atx-style headers:616 // # Header 1617 // ## Header 2618 // ## Header 2 with closing hashes ##619 // ...620 // ###### Header 6621 //622 /*623 text = text.replace(/624 ^(\#{1,6}) // $1 = string of #'s625 [ \t]*626 (.+?) // $2 = Header text627 [ \t]*628 \#* // optional closing #'s (not counted)629 \n+630 /gm, function() {...});631 */632 text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,633 function (wholeMatch, m1, m2) {634 var h_level = m1.length;635 return "<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">\n\n";636 }637 );638 return text;639 }640 function _DoLists(text) {641 //642 // Form HTML ordered (numbered) and unordered (bulleted) lists.643 //644 // attacklab: add sentinel to hack around khtml/safari bug:645 // http://bugs.webkit.org/show_bug.cgi?id=11231646 text += "~0";647 // Re-usable pattern to match any entirel ul or ol list:648 /*649 var whole_list = /650 ( // $1 = whole list651 ( // $2652 [ ]{0,3} // attacklab: g_tab_width - 1653 ([*+-]|\d+[.]) // $3 = first list item marker654 [ \t]+655 )656 [^\r]+?657 ( // $4658 ~0 // sentinel for workaround; should be $659 |660 \n{2,}661 (?=\S)662 (?! // Negative lookahead for another list item marker663 [ \t]*664 (?:[*+-]|\d+[.])[ \t]+665 )666 )667 )668 /g669 */670 var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;671 if (g_list_level) {672 text = text.replace(whole_list, function (wholeMatch, m1, m2) {673 var list = m1;674 var list_type = (m2.search(/[*+-]/g) > -1) ? "ul" : "ol";675 var result = _ProcessListItems(list, list_type);676 // Trim any trailing whitespace, to put the closing `</$list_type>`677 // up on the preceding line, to get it past the current stupid678 // HTML block parser. This is a hack to work around the terrible679 // hack that is the HTML block parser.680 result = result.replace(/\s+$/, "");681 result = "<" + list_type + ">" + result + "</" + list_type + ">\n";682 return result;683 });684 } else {685 whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;686 text = text.replace(whole_list, function (wholeMatch, m1, m2, m3) {687 var runup = m1;688 var list = m2;689 var list_type = (m3.search(/[*+-]/g) > -1) ? "ul" : "ol";690 var result = _ProcessListItems(list, list_type);691 result = runup + "<" + list_type + ">\n" + result + "</" + list_type + ">\n";692 return result;693 });694 }695 // attacklab: strip sentinel696 text = text.replace(/~0/, "");697 return text;698 }699 var _listItemMarkers = { ol: "\\d+[.]", ul: "[*+-]" };700 function _ProcessListItems(list_str, list_type) {701 //702 // Process the contents of a single ordered or unordered list, splitting it703 // into individual list items.704 //705 // list_type is either "ul" or "ol".706 // The $g_list_level global keeps track of when we're inside a list.707 // Each time we enter a list, we increment it; when we leave a list,708 // we decrement. If it's zero, we're not in a list anymore.709 //710 // We do this because when we're not inside a list, we want to treat711 // something like this:712 //713 // I recommend upgrading to version714 // 8. Oops, now this line is treated715 // as a sub-list.716 //717 // As a single paragraph, despite the fact that the second line starts718 // with a digit-period-space sequence.719 //720 // Whereas when we're inside a list (or sub-list), that line will be721 // treated as the start of a sub-list. What a kludge, huh? This is722 // an aspect of Markdown's syntax that's hard to parse perfectly723 // without resorting to mind-reading. Perhaps the solution is to724 // change the syntax rules such that sub-lists must start with a725 // starting cardinal number; e.g. "1." or "a.".726 g_list_level++;727 // trim trailing blank lines:728 list_str = list_str.replace(/\n{2,}$/, "\n");729 // attacklab: add sentinel to emulate \z730 list_str += "~0";731 // In the original attacklab showdown, list_type was not given to this function, and anything732 // that matched /[*+-]|\d+[.]/ would just create the next <li>, causing this mismatch:733 //734 // Markdown rendered by WMD rendered by MarkdownSharp735 // ------------------------------------------------------------------736 // 1. first 1. first 1. first737 // 2. second 2. second 2. second738 // - third 3. third * third739 //740 // We changed this to behave identical to MarkdownSharp. This is the constructed RegEx,741 // with {MARKER} being one of \d+[.] or [*+-], depending on list_type:742 743 /*744 list_str = list_str.replace(/745 (^[ \t]*) // leading whitespace = $1746 ({MARKER}) [ \t]+ // list marker = $2747 ([^\r]+? // list item text = $3748 (\n+)749 )750 (?=751 (~0 | \2 ({MARKER}) [ \t]+)752 )753 /gm, function(){...});754 */755 var marker = _listItemMarkers[list_type];756 var re = new RegExp("(^[ \\t]*)(" + marker + ")[ \\t]+([^\\r]+?(\\n+))(?=(~0|\\1(" + marker + ")[ \\t]+))", "gm");757 var last_item_had_a_double_newline = false;758 list_str = list_str.replace(re,759 function (wholeMatch, m1, m2, m3) {760 var item = m3;761 var leading_space = m1;762 var ends_with_double_newline = /\n\n$/.test(item);763 var contains_double_newline = ends_with_double_newline || item.search(/\n{2,}/) > -1;764 if (contains_double_newline || last_item_had_a_double_newline) {765 item = _RunBlockGamut(_Outdent(item), /* doNotUnhash = */true);766 }767 else {768 // Recursion for sub-lists:769 item = _DoLists(_Outdent(item));770 item = item.replace(/\n$/, ""); // chomp(item)771 item = _RunSpanGamut(item);772 }773 last_item_had_a_double_newline = ends_with_double_newline;774 return "<li>" + item + "</li>\n";775 }776 );777 // attacklab: strip sentinel778 list_str = list_str.replace(/~0/g, "");779 g_list_level--;780 return list_str;781 }782 function _DoCodeBlocks(text) {783 //784 // Process Markdown `<pre><code>` blocks.785 // 786 /*787 text = text.replace(/788 (?:\n\n|^)789 ( // $1 = the code block -- one or more lines, starting with a space/tab790 (?:791 (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width792 .*\n+793 )+794 )795 (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width796 /g ,function(){...});797 */798 // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug799 text += "~0";800 text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,801 function (wholeMatch, m1, m2) {802 var codeblock = m1;803 var nextChar = m2;804 codeblock = _EncodeCode(_Outdent(codeblock));805 codeblock = _Detab(codeblock);806 codeblock = codeblock.replace(/^\n+/g, ""); // trim leading newlines807 codeblock = codeblock.replace(/\n+$/g, ""); // trim trailing whitespace808 codeblock = "<pre><code>" + codeblock + "\n</code></pre>";809 return "\n\n" + codeblock + "\n\n" + nextChar;810 }811 );812 // attacklab: strip sentinel813 text = text.replace(/~0/, "");814 return text;815 }816 function hashBlock(text) {817 text = text.replace(/(^\n+|\n+$)/g, "");818 return "\n\n~K" + (g_html_blocks.push(text) - 1) + "K\n\n";819 }820 function _DoCodeSpans(text) {821 //822 // * Backtick quotes are used for <code></code> spans.823 // 824 // * You can use multiple backticks as the delimiters if you want to825 // include literal backticks in the code span. So, this input:826 // 827 // Just type ``foo `bar` baz`` at the prompt.828 // 829 // Will translate to:830 // 831 // <p>Just type <code>foo `bar` baz</code> at the prompt.</p>832 // 833 // There's no arbitrary limit to the number of backticks you834 // can use as delimters. If you need three consecutive backticks835 // in your code, use four for delimiters, etc.836 //837 // * You can use spaces to get literal backticks at the edges:838 // 839 // ... type `` `bar` `` ...840 // 841 // Turns to:842 // 843 // ... type <code>`bar`</code> ...844 //845 /*846 text = text.replace(/847 (^|[^\\]) // Character before opening ` can't be a backslash848 (`+) // $2 = Opening run of `849 ( // $3 = The code block850 [^\r]*?851 [^`] // attacklab: work around lack of lookbehind852 )853 \2 // Matching closer854 (?!`)855 /gm, function(){...});856 */857 text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,858 function (wholeMatch, m1, m2, m3, m4) {859 var c = m3;860 c = c.replace(/^([ \t]*)/g, ""); // leading whitespace861 c = c.replace(/[ \t]*$/g, ""); // trailing whitespace862 c = _EncodeCode(c);863 c = c.replace(/:\/\//g, "~P"); // to prevent auto-linking. Not necessary in code *blocks*, but in code spans. Will be converted back after the auto-linker runs.864 return m1 + "<code>" + c + "</code>";865 }866 );867 return text;868 }869 function _EncodeCode(text) {870 //871 // Encode/escape certain characters inside Markdown code runs.872 // The point is that in code, these characters are literals,873 // and lose their special Markdown meanings.874 //875 // Encode all ampersands; HTML entities are not876 // entities within a Markdown code span.877 text = text.replace(/&/g, "&amp;");878 // Do the angle bracket song and dance:879 text = text.replace(/</g, "&lt;");880 text = text.replace(/>/g, "&gt;");881 // Now, escape characters that are magic in Markdown:882 text = escapeCharacters(text, "\*_{}[]\\", false);883 // jj the line above breaks this:884 //---885 //* Item886 // 1. Subitem887 // special char: *888 //---889 return text;890 }891 function _DoItalicsAndBold(text) {892 // <strong> must go first:893 text = text.replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g,894 "$1<strong>$3</strong>$4");895 text = text.replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g,896 "$1<em>$3</em>$4");897 return text;898 }899 function _DoBlockQuotes(text) {900 /*901 text = text.replace(/902 ( // Wrap whole match in $1903 (904 ^[ \t]*>[ \t]? // '>' at the start of a line905 .+\n // rest of the first line906 (.+\n)* // subsequent consecutive lines907 \n* // blanks908 )+909 )910 /gm, function(){...});911 */912 text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,913 function (wholeMatch, m1) {914 var bq = m1;915 // attacklab: hack around Konqueror 3.5.4 bug:916 // "----------bug".replace(/^-/g,"") == "bug"917 bq = bq.replace(/^[ \t]*>[ \t]?/gm, "~0"); // trim one level of quoting918 // attacklab: clean up hack919 bq = bq.replace(/~0/g, "");920 bq = bq.replace(/^[ \t]+$/gm, ""); // trim whitespace-only lines921 bq = _RunBlockGamut(bq); // recurse922 bq = bq.replace(/(^|\n)/g, "$1 ");923 // These leading spaces screw with <pre> content, so we need to fix that:924 bq = bq.replace(925 /(\s*<pre>[^\r]+?<\/pre>)/gm,926 function (wholeMatch, m1) {927 var pre = m1;928 // attacklab: hack around Konqueror 3.5.4 bug:929 pre = pre.replace(/^ /mg, "~0");930 pre = pre.replace(/~0/g, "");931 return pre;932 });933 return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");934 }935 );936 return text;937 }938 function _FormParagraphs(text, doNotUnhash) {939 //940 // Params:941 // $text - string to process with html <p> tags942 //943 // Strip leading and trailing lines:944 text = text.replace(/^\n+/g, "");945 text = text.replace(/\n+$/g, "");946 var grafs = text.split(/\n{2,}/g);947 var grafsOut = [];948 949 var markerRe = /~K(\d+)K/;950 //951 // Wrap <p> tags.952 //953 var end = grafs.length;954 for (var i = 0; i < end; i++) {955 var str = grafs[i];956 // if this is an HTML marker, copy it957 if (markerRe.test(str)) {958 grafsOut.push(str);959 }960 else if (/\S/.test(str)) {961 str = _RunSpanGamut(str);962 str = str.replace(/^([ \t]*)/g, "<p>");963 str += "</p>"964 grafsOut.push(str);965 }966 }967 //968 // Unhashify HTML blocks969 //970 if (!doNotUnhash) {971 end = grafsOut.length;972 for (var i = 0; i < end; i++) {973 var foundAny = true;974 while (foundAny) { // we may need several runs, since the data may be nested975 foundAny = false;976 grafsOut[i] = grafsOut[i].replace(/~K(\d+)K/g, function (wholeMatch, id) {977 foundAny = true;978 return g_html_blocks[id];979 });980 }981 }982 }983 return grafsOut.join("\n\n");984 }985 function _EncodeAmpsAndAngles(text) {986 // Smart processing for ampersands and angle brackets that need to be encoded.987 // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:988 // http://bumppo.net/projects/amputator/989 text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, "&amp;");990 // Encode naked <'s991 text = text.replace(/<(?![a-z\/?\$!])/gi, "&lt;");992 return text;993 }994 function _EncodeBackslashEscapes(text) {995 //996 // Parameter: String.997 // Returns: The string, with after processing the following backslash998 // escape sequences.999 //1000 // attacklab: The polite way to do this is with the new1001 // escapeCharacters() function:1002 //1003 // text = escapeCharacters(text,"\\",true);1004 // text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);1005 //1006 // ...but we're sidestepping its use of the (slow) RegExp constructor1007 // as an optimization for Firefox. This function gets called a LOT.1008 text = text.replace(/\\(\\)/g, escapeCharacters_callback);1009 text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, escapeCharacters_callback);1010 return text;1011 }1012 function _DoAutoLinks(text) {1013 // note that at this point, all other URL in the text are already hyperlinked as <a href=""></a>1014 // *except* for the <http://www.foo.com> case1015 // automatically add < and > around unadorned raw hyperlinks1016 // must be preceded by space/BOF and followed by non-word/EOF character 1017 text = text.replace(/(^|\s)(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\]])($|\W)/gi, "$1<$2$3>$4");1018 // autolink anything like <http://example.com>1019 1020 var replacer = function (wholematch, m1) { return "<a href=\"" + m1 + "\">" + pluginHooks.plainLinkText(m1) + "</a>"; }1021 text = text.replace(/<((https?|ftp):[^'">\s]+)>/gi, replacer);1022 // Email addresses: <address@domain.foo>1023 /*1024 text = text.replace(/1025 <1026 (?:mailto:)?1027 (1028 [-.\w]+1029 \@1030 [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+1031 )1032 >1033 /gi, _DoAutoLinks_callback());1034 */1035 /* disabling email autolinking, since we don't do that on the server, either1036 text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,1037 function(wholeMatch,m1) {1038 return _EncodeEmailAddress( _UnescapeSpecialChars(m1) );1039 }1040 );1041 */1042 return text;1043 }1044 function _UnescapeSpecialChars(text) {1045 //1046 // Swap back in all the special characters we've hidden.1047 //1048 text = text.replace(/~E(\d+)E/g,1049 function (wholeMatch, m1) {1050 var charCodeToReplace = parseInt(m1);1051 return String.fromCharCode(charCodeToReplace);1052 }1053 );1054 return text;1055 }1056 function _Outdent(text) {1057 //1058 // Remove one level of line-leading tabs or spaces1059 //1060 // attacklab: hack around Konqueror 3.5.4 bug:1061 // "----------bug".replace(/^-/g,"") == "bug"1062 text = text.replace(/^(\t|[ ]{1,4})/gm, "~0"); // attacklab: g_tab_width1063 // attacklab: clean up hack1064 text = text.replace(/~0/g, "")1065 return text;1066 }1067 function _Detab(text) {1068 if (!/\t/.test(text))1069 return text;1070 var spaces = [" ", " ", " ", " "],1071 skew = 0,1072 v;1073 return text.replace(/[\n\t]/g, function (match, offset) {1074 if (match === "\n") {1075 skew = offset + 1;1076 return match;1077 }1078 v = (offset - skew) % 4;1079 skew = offset + 1;1080 return spaces[v];1081 });1082 }1083 //1084 // attacklab: Utility functions1085 //1086 var _problemUrlChars = /(?:["'*()[\]:]|~D)/g;1087 // hex-encodes some unusual "problem" chars in URLs to avoid URL detection problems 1088 function encodeProblemUrlChars(url) {1089 if (!url)1090 return "";1091 var len = url.length;1092 return url.replace(_problemUrlChars, function (match, offset) {1093 if (match == "~D") // escape for dollar1094 return "%24";1095 if (match == ":") {1096 if (offset == len - 1 || /[0-9\/]/.test(url.charAt(offset + 1)))1097 return ":"1098 }1099 return "%" + match.charCodeAt(0).toString(16);1100 });1101 }1102 function escapeCharacters(text, charsToEscape, afterBackslash) {1103 // First we have to escape the escape characters so that1104 // we can build a character class out of them1105 var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g, "\\$1") + "])";1106 if (afterBackslash) {1107 regexString = "\\\\" + regexString;1108 }1109 var regex = new RegExp(regexString, "g");1110 text = text.replace(regex, escapeCharacters_callback);1111 return text;1112 }1113 function escapeCharacters_callback(wholeMatch, m1) {1114 var charCodeToEscape = m1.charCodeAt(0);1115 return "~E" + charCodeToEscape + "E";1116 }1117 }; // end of the Markdown.Converter constructor...

Full Screen

Full Screen

showdown.js

Source:showdown.js Github

copy

Full Screen

...95 // attacklab: Replace ~ with ~T96 // This lets us use tilde as an escape char to avoid md5 hashes97 // The choice of character is arbitray; anything that isn't98 // magic in Markdown will work.99 text = text.replace(/~/g,"~T");100 // attacklab: Replace $ with ~D101 // RegExp interprets $ as a special character102 // when it's in a replacement string103 text = text.replace(/\$/g,"~D");104 // Standardize line endings105 text = text.replace(/\r\n/g,"\n"); // DOS to Unix106 text = text.replace(/\r/g,"\n"); // Mac to Unix107 // Make sure text begins and ends with a couple of newlines:108 text = "\n\n" + text + "\n\n";109 // Convert all tabs to spaces.110 text = _Detab(text);111 // Strip any lines consisting only of spaces and tabs.112 // This makes subsequent regexen easier to write, because we can113 // match consecutive blank lines with /\n+/ instead of something114 // contorted like /[ \t]*\n+/ .115 text = text.replace(/^[ \t]+$/mg,"");116 // Turn block-level HTML blocks into hash entries117 text = _HashHTMLBlocks(text);118 // Strip link definitions, store in hashes.119 text = _StripLinkDefinitions(text);120 text = _RunBlockGamut(text);121 text = _UnescapeSpecialChars(text);122 // attacklab: Restore dollar signs123 text = text.replace(/~D/g,"$$");124 // attacklab: Restore tildes125 text = text.replace(/~T/g,"~");126 return text;127}128var _StripLinkDefinitions = function(text) {129//130// Strips link definitions from text, stores the URLs and titles in131// hash references.132//133 // Link defs are in the form: ^[id]: url "optional title"134 /*135 var text = text.replace(/136 ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 1137 [ \t]*138 \n? // maybe *one* newline139 [ \t]*140 <?(\S+?)>? // url = $2141 [ \t]*142 \n? // maybe one newline143 [ \t]*144 (?:145 (\n*) // any lines skipped = $3 attacklab: lookbehind removed146 ["(]147 (.+?) // title = $4148 [")]149 [ \t]*150 )? // title is optional151 (?:\n+|$)152 /gm,153 function(){...});154 */155 var text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+)/gm,156 function (wholeMatch,m1,m2,m3,m4) {157 m1 = m1.toLowerCase();158 g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive159 if (m3) {160 // Oops, found blank lines, so it's not a title.161 // Put back the parenthetical statement we stole.162 return m3+m4;163 } else if (m4) {164 g_titles[m1] = m4.replace(/"/g,"&quot;");165 }166 167 // Completely remove the definition from the text168 return "";169 }170 );171 return text;172}173var _HashHTMLBlocks = function(text) {174 // attacklab: Double up blank lines to reduce lookaround175 text = text.replace(/\n/g,"\n\n");176 // Hashify HTML blocks:177 // We only want to do this for block-level HTML tags, such as headers,178 // lists, and tables. That's because we still want to wrap <p>s around179 // "paragraphs" that are wrapped in non-block-level tags, such as anchors,180 // phrase emphasis, and spans. The list of tags we're looking for is181 // hard-coded:182 var block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del"183 var block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math"184 // First, look for nested blocks, e.g.:185 // <div>186 // <div>187 // tags for inner block must be indented.188 // </div>189 // </div>190 //191 // The outermost tags must start at the left margin for this to match, and192 // the inner nested divs must be indented.193 // We need to do this before the next, more liberal match, because the next194 // match will start at the first `<div>` and stop at the first `</div>`.195 // attacklab: This regex can be expensive when it fails.196 /*197 var text = text.replace(/198 ( // save in $1199 ^ // start of line (with /m)200 <($block_tags_a) // start tag = $2201 \b // word break202 // attacklab: hack around khtml/pcre bug...203 [^\r]*?\n // any number of lines, minimally matching204 </\2> // the matching end tag205 [ \t]* // trailing spaces/tabs206 (?=\n+) // followed by a newline207 ) // attacklab: there are sentinel newlines at end of document208 /gm,function(){...}};209 */210 text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,hashElement);211 //212 // Now match more liberally, simply from `\n<tag>` to `</tag>\n`213 //214 /*215 var text = text.replace(/216 ( // save in $1217 ^ // start of line (with /m)218 <($block_tags_b) // start tag = $2219 \b // word break220 // attacklab: hack around khtml/pcre bug...221 [^\r]*? // any number of lines, minimally matching222 .*</\2> // the matching end tag223 [ \t]* // trailing spaces/tabs224 (?=\n+) // followed by a newline225 ) // attacklab: there are sentinel newlines at end of document226 /gm,function(){...}};227 */228 text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm,hashElement);229 // Special case just for <hr />. It was easier to make a special case than230 // to make the other regex more complicated. 231 /*232 text = text.replace(/233 ( // save in $1234 \n\n // Starting after a blank line235 [ ]{0,3}236 (<(hr) // start tag = $2237 \b // word break238 ([^<>])*? // 239 \/?>) // the matching end tag240 [ \t]*241 (?=\n{2,}) // followed by a blank line242 )243 /g,hashElement);244 */245 text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,hashElement);246 // Special case for standalone HTML comments:247 /*248 text = text.replace(/249 ( // save in $1250 \n\n // Starting after a blank line251 [ ]{0,3} // attacklab: g_tab_width - 1252 <!253 (--[^\r]*?--\s*)+254 >255 [ \t]*256 (?=\n{2,}) // followed by a blank line257 )258 /g,hashElement);259 */260 text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,hashElement);261 // PHP and ASP-style processor instructions (<?...?> and <%...%>)262 /*263 text = text.replace(/264 (?:265 \n\n // Starting after a blank line266 )267 ( // save in $1268 [ ]{0,3} // attacklab: g_tab_width - 1269 (?:270 <([?%]) // $2271 [^\r]*?272 \2>273 )274 [ \t]*275 (?=\n{2,}) // followed by a blank line276 )277 /g,hashElement);278 */279 text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,hashElement);280 // attacklab: Undo double lines (see comment at top of this function)281 text = text.replace(/\n\n/g,"\n");282 return text;283}284var hashElement = function(wholeMatch,m1) {285 var blockText = m1;286 // Undo double lines287 blockText = blockText.replace(/\n\n/g,"\n");288 blockText = blockText.replace(/^\n/,"");289 290 // strip trailing blank lines291 blockText = blockText.replace(/\n+$/g,"");292 293 // Replace the element text with a marker ("~KxK" where x is its key)294 blockText = "\n\n~K" + (g_html_blocks.push(blockText)-1) + "K\n\n";295 296 return blockText;297};298var _RunBlockGamut = function(text) {299//300// These are all the transformations that form block-level301// tags like paragraphs, headers, and list items.302//303 text = _DoHeaders(text);304 // Do Horizontal Rules:305 var key = hashBlock("<hr />");306 text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);307 text = text.replace(/^[ ]{0,2}([ ]?-[ ]?){3,}[ \t]*$/gm,key);308 text = text.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm,key);309 text = _DoLists(text);310 text = _DoCodeBlocks(text);311 text = _DoBlockQuotes(text);312 // We already ran _HashHTMLBlocks() before, in Markdown(), but that313 // was to escape raw HTML in the original Markdown source. This time,314 // we're escaping the markup we've just created, so that we don't wrap315 // <p> tags around block-level tags.316 text = _HashHTMLBlocks(text);317 text = _FormParagraphs(text);318 return text;319}320var _RunSpanGamut = function(text) {321//322// These are all the transformations that occur *within* block-level323// tags like paragraphs, headers, and list items.324//325 text = _DoCodeSpans(text);326 text = _EscapeSpecialCharsWithinTagAttributes(text);327 text = _EncodeBackslashEscapes(text);328 // Process anchor and image tags. Images must come first,329 // because ![foo][f] looks like an anchor.330 text = _DoImages(text);331 text = _DoAnchors(text);332 // Make links out of things like `<http://example.com/>`333 // Must come after _DoAnchors(), because you can use < and >334 // delimiters in inline links like [this](<url>).335 text = _DoAutoLinks(text);336 text = _EncodeAmpsAndAngles(text);337 text = _DoItalicsAndBold(text);338 // Do hard breaks:339 text = text.replace(/ +\n/g," <br />\n");340 return text;341}342var _EscapeSpecialCharsWithinTagAttributes = function(text) {343//344// Within tags -- meaning between < and > -- encode [\ ` * _] so they345// don't conflict with their use in Markdown for code, italics and strong.346//347 // Build a regex to find HTML tags and comments. See Friedl's 348 // "Mastering Regular Expressions", 2nd Ed., pp. 200-201.349 var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;350 text = text.replace(regex, function(wholeMatch) {351 var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");352 tag = escapeCharacters(tag,"\\`*_");353 return tag;354 });355 return text;356}357var _DoAnchors = function(text) {358//359// Turn Markdown link shortcuts into XHTML <a> tags.360//361 //362 // First, handle reference-style links: [link text] [id]363 //364 /*365 text = text.replace(/366 ( // wrap whole match in $1367 \[368 (369 (?:370 \[[^\]]*\] // allow brackets nested one level371 |372 [^\[] // or anything else373 )*374 )375 \]376 [ ]? // one optional space377 (?:\n[ ]*)? // one optional newline followed by spaces378 \[379 (.*?) // id = $3380 \]381 )()()()() // pad remaining backreferences382 /g,_DoAnchors_callback);383 */384 text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);385 //386 // Next, inline-style links: [link text](url "optional title")387 //388 /*389 text = text.replace(/390 ( // wrap whole match in $1391 \[392 (393 (?:394 \[[^\]]*\] // allow brackets nested one level395 |396 [^\[\]] // or anything else397 )398 )399 \]400 \( // literal paren401 [ \t]*402 () // no id, so leave $3 empty403 <?(.*?)>? // href = $4404 [ \t]*405 ( // $5406 (['"]) // quote char = $6407 (.*?) // Title = $7408 \6 // matching quote409 [ \t]* // ignore any spaces/tabs between closing quote and )410 )? // title is optional411 \)412 )413 /g,writeAnchorTag);414 */415 text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);416 //417 // Last, handle reference-style shortcuts: [link text]418 // These must come last in case you've also got [link test][1]419 // or [link test](/foo)420 //421 /*422 text = text.replace(/423 ( // wrap whole match in $1424 \[425 ([^\[\]]+) // link text = $2; can't contain '[' or ']'426 \]427 )()()()()() // pad rest of backreferences428 /g, writeAnchorTag);429 */430 text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);431 return text;432}433var writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {434 if (m7 == undefined) m7 = "";435 var whole_match = m1;436 var link_text = m2;437 var link_id = m3.toLowerCase();438 var url = m4;439 var title = m7;440 441 if (url == "") {442 if (link_id == "") {443 // lower-case and turn embedded newlines into spaces444 link_id = link_text.toLowerCase().replace(/ ?\n/g," ");445 }446 url = "#"+link_id;447 448 if (g_urls[link_id] != undefined) {449 url = g_urls[link_id];450 if (g_titles[link_id] != undefined) {451 title = g_titles[link_id];452 }453 }454 else {455 if (whole_match.search(/\(\s*\)$/m)>-1) {456 // Special case for explicit empty url457 url = "";458 } else {459 return whole_match;460 }461 }462 } 463 464 url = escapeCharacters(url,"*_");465 var result = "<a href=\"" + url + "\"";466 467 if (title != "") {468 title = title.replace(/"/g,"&quot;");469 title = escapeCharacters(title,"*_");470 result += " title=\"" + title + "\"";471 }472 473 result += ">" + link_text + "</a>";474 475 return result;476}477var _DoImages = function(text) {478//479// Turn Markdown image shortcuts into <img> tags.480//481 //482 // First, handle reference-style labeled images: ![alt text][id]483 //484 /*485 text = text.replace(/486 ( // wrap whole match in $1487 !\[488 (.*?) // alt text = $2489 \]490 [ ]? // one optional space491 (?:\n[ ]*)? // one optional newline followed by spaces492 \[493 (.*?) // id = $3494 \]495 )()()()() // pad rest of backreferences496 /g,writeImageTag);497 */498 text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);499 //500 // Next, handle inline images: ![alt text](url "optional title")501 // Don't forget: encode * and _502 /*503 text = text.replace(/504 ( // wrap whole match in $1505 !\[506 (.*?) // alt text = $2507 \]508 \s? // One optional whitespace character509 \( // literal paren510 [ \t]*511 () // no id, so leave $3 empty512 <?(\S+?)>? // src url = $4513 [ \t]*514 ( // $5515 (['"]) // quote char = $6516 (.*?) // title = $7517 \6 // matching quote518 [ \t]*519 )? // title is optional520 \)521 )522 /g,writeImageTag);523 */524 text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);525 return text;526}527var writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {528 var whole_match = m1;529 var alt_text = m2;530 var link_id = m3.toLowerCase();531 var url = m4;532 var title = m7;533 if (!title) title = "";534 535 if (url == "") {536 if (link_id == "") {537 // lower-case and turn embedded newlines into spaces538 link_id = alt_text.toLowerCase().replace(/ ?\n/g," ");539 }540 url = "#"+link_id;541 542 if (g_urls[link_id] != undefined) {543 url = g_urls[link_id];544 if (g_titles[link_id] != undefined) {545 title = g_titles[link_id];546 }547 }548 else {549 return whole_match;550 }551 } 552 553 alt_text = alt_text.replace(/"/g,"&quot;");554 url = escapeCharacters(url,"*_");555 var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";556 // attacklab: Markdown.pl adds empty title attributes to images.557 // Replicate this bug.558 //if (title != "") {559 title = title.replace(/"/g,"&quot;");560 title = escapeCharacters(title,"*_");561 result += " title=\"" + title + "\"";562 //}563 564 result += " />";565 566 return result;567}568var _DoHeaders = function(text) {569 // Setext-style headers:570 // Header 1571 // ========572 // 573 // Header 2574 // --------575 //576 text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,577 function(wholeMatch,m1){return hashBlock("<h1>" + _RunSpanGamut(m1) + "</h1>");});578 text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,579 function(matchFound,m1){return hashBlock("<h2>" + _RunSpanGamut(m1) + "</h2>");});580 // atx-style headers:581 // # Header 1582 // ## Header 2583 // ## Header 2 with closing hashes ##584 // ...585 // ###### Header 6586 //587 /*588 text = text.replace(/589 ^(\#{1,6}) // $1 = string of #'s590 [ \t]*591 (.+?) // $2 = Header text592 [ \t]*593 \#* // optional closing #'s (not counted)594 \n+595 /gm, function() {...});596 */597 text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,598 function(wholeMatch,m1,m2) {599 var h_level = m1.length;600 return hashBlock("<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">");601 });602 return text;603}604// This declaration keeps Dojo compressor from outputting garbage:605var _ProcessListItems;606var _DoLists = function(text) {607//608// Form HTML ordered (numbered) and unordered (bulleted) lists.609//610 // attacklab: add sentinel to hack around khtml/safari bug:611 // http://bugs.webkit.org/show_bug.cgi?id=11231612 text += "~0";613 // Re-usable pattern to match any entirel ul or ol list:614 /*615 var whole_list = /616 ( // $1 = whole list617 ( // $2618 [ ]{0,3} // attacklab: g_tab_width - 1619 ([*+-]|\d+[.]) // $3 = first list item marker620 [ \t]+621 )622 [^\r]+?623 ( // $4624 ~0 // sentinel for workaround; should be $625 |626 \n{2,}627 (?=\S)628 (?! // Negative lookahead for another list item marker629 [ \t]*630 (?:[*+-]|\d+[.])[ \t]+631 )632 )633 )/g634 */635 var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;636 if (g_list_level) {637 text = text.replace(whole_list,function(wholeMatch,m1,m2) {638 var list = m1;639 var list_type = (m2.search(/[*+-]/g)>-1) ? "ul" : "ol";640 // Turn double returns into triple returns, so that we can make a641 // paragraph for the last item in a list, if necessary:642 list = list.replace(/\n{2,}/g,"\n\n\n");;643 var result = _ProcessListItems(list);644 645 // Trim any trailing whitespace, to put the closing `</$list_type>`646 // up on the preceding line, to get it past the current stupid647 // HTML block parser. This is a hack to work around the terrible648 // hack that is the HTML block parser.649 result = result.replace(/\s+$/,"");650 result = "<"+list_type+">" + result + "</"+list_type+">\n";651 return result;652 });653 } else {654 whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;655 text = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {656 var runup = m1;657 var list = m2;658 var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";659 // Turn double returns into triple returns, so that we can make a660 // paragraph for the last item in a list, if necessary:661 var list = list.replace(/\n{2,}/g,"\n\n\n");;662 var result = _ProcessListItems(list);663 result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n"; 664 return result;665 });666 }667 // attacklab: strip sentinel668 text = text.replace(/~0/,"");669 return text;670}671_ProcessListItems = function(list_str) {672//673// Process the contents of a single ordered or unordered list, splitting it674// into individual list items.675//676 // The $g_list_level global keeps track of when we're inside a list.677 // Each time we enter a list, we increment it; when we leave a list,678 // we decrement. If it's zero, we're not in a list anymore.679 //680 // We do this because when we're not inside a list, we want to treat681 // something like this:682 //683 // I recommend upgrading to version684 // 8. Oops, now this line is treated685 // as a sub-list.686 //687 // As a single paragraph, despite the fact that the second line starts688 // with a digit-period-space sequence.689 //690 // Whereas when we're inside a list (or sub-list), that line will be691 // treated as the start of a sub-list. What a kludge, huh? This is692 // an aspect of Markdown's syntax that's hard to parse perfectly693 // without resorting to mind-reading. Perhaps the solution is to694 // change the syntax rules such that sub-lists must start with a695 // starting cardinal number; e.g. "1." or "a.".696 g_list_level++;697 // trim trailing blank lines:698 list_str = list_str.replace(/\n{2,}$/,"\n");699 // attacklab: add sentinel to emulate \z700 list_str += "~0";701 /*702 list_str = list_str.replace(/703 (\n)? // leading line = $1704 (^[ \t]*) // leading whitespace = $2705 ([*+-]|\d+[.]) [ \t]+ // list marker = $3706 ([^\r]+? // list item text = $4707 (\n{1,2}))708 (?= \n* (~0 | \2 ([*+-]|\d+[.]) [ \t]+))709 /gm, function(){...});710 */711 list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,712 function(wholeMatch,m1,m2,m3,m4){713 var item = m4;714 var leading_line = m1;715 var leading_space = m2;716 if (leading_line || (item.search(/\n{2,}/)>-1)) {717 item = _RunBlockGamut(_Outdent(item));718 }719 else {720 // Recursion for sub-lists:721 item = _DoLists(_Outdent(item));722 item = item.replace(/\n$/,""); // chomp(item)723 item = _RunSpanGamut(item);724 }725 return "<li>" + item + "</li>\n";726 }727 );728 // attacklab: strip sentinel729 list_str = list_str.replace(/~0/g,"");730 g_list_level--;731 return list_str;732}733var _DoCodeBlocks = function(text) {734//735// Process Markdown `<pre><code>` blocks.736// 737 /*738 text = text.replace(text,739 /(?:\n\n|^)740 ( // $1 = the code block -- one or more lines, starting with a space/tab741 (?:742 (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width743 .*\n+744 )+745 )746 (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width747 /g,function(){...});748 */749 // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug750 text += "~0";751 752 text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,753 function(wholeMatch,m1,m2) {754 var codeblock = m1;755 var nextChar = m2;756 757 codeblock = _EncodeCode( _Outdent(codeblock));758 codeblock = _Detab(codeblock);759 codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines760 codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace761 codeblock = "<pre><code>" + codeblock + "\n</code></pre>";762 return hashBlock(codeblock) + nextChar;763 }764 );765 // attacklab: strip sentinel766 text = text.replace(/~0/,"");767 return text;768}769var hashBlock = function(text) {770 text = text.replace(/(^\n+|\n+$)/g,"");771 return "\n\n~K" + (g_html_blocks.push(text)-1) + "K\n\n";772}773var _DoCodeSpans = function(text) {774//775// * Backtick quotes are used for <code></code> spans.776// 777// * You can use multiple backticks as the delimiters if you want to778// include literal backticks in the code span. So, this input:779// 780// Just type ``foo `bar` baz`` at the prompt.781// 782// Will translate to:783// 784// <p>Just type <code>foo `bar` baz</code> at the prompt.</p>785// 786// There's no arbitrary limit to the number of backticks you787// can use as delimters. If you need three consecutive backticks788// in your code, use four for delimiters, etc.789//790// * You can use spaces to get literal backticks at the edges:791// 792// ... type `` `bar` `` ...793// 794// Turns to:795// 796// ... type <code>`bar`</code> ...797//798 /*799 text = text.replace(/800 (^|[^\\]) // Character before opening ` can't be a backslash801 (`+) // $2 = Opening run of `802 ( // $3 = The code block803 [^\r]*?804 [^`] // attacklab: work around lack of lookbehind805 )806 \2 // Matching closer807 (?!`)808 /gm, function(){...});809 */810 text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,811 function(wholeMatch,m1,m2,m3,m4) {812 var c = m3;813 c = c.replace(/^([ \t]*)/g,""); // leading whitespace814 c = c.replace(/[ \t]*$/g,""); // trailing whitespace815 c = _EncodeCode(c);816 return m1+"<code>"+c+"</code>";817 });818 return text;819}820var _EncodeCode = function(text) {821//822// Encode/escape certain characters inside Markdown code runs.823// The point is that in code, these characters are literals,824// and lose their special Markdown meanings.825//826 // Encode all ampersands; HTML entities are not827 // entities within a Markdown code span.828 text = text.replace(/&/g,"&amp;");829 // Do the angle bracket song and dance:830 text = text.replace(/</g,"&lt;");831 text = text.replace(/>/g,"&gt;");832 // Now, escape characters that are magic in Markdown:833 text = escapeCharacters(text,"\*_{}[]\\",false);834// jj the line above breaks this:835//---836//* Item837// 1. Subitem838// special char: *839//---840 return text;841}842var _DoItalicsAndBold = function(text) {843 // <strong> must go first:844 text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\1/g,845 "<strong>$2</strong>");846 text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,847 "<em>$2</em>");848 return text;849}850var _DoBlockQuotes = function(text) {851 /*852 text = text.replace(/853 ( // Wrap whole match in $1854 (855 ^[ \t]*>[ \t]? // '>' at the start of a line856 .+\n // rest of the first line857 (.+\n)* // subsequent consecutive lines858 \n* // blanks859 )+860 )861 /gm, function(){...});862 */863 text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,864 function(wholeMatch,m1) {865 var bq = m1;866 // attacklab: hack around Konqueror 3.5.4 bug:867 // "----------bug".replace(/^-/g,"") == "bug"868 bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0"); // trim one level of quoting869 // attacklab: clean up hack870 bq = bq.replace(/~0/g,"");871 bq = bq.replace(/^[ \t]+$/gm,""); // trim whitespace-only lines872 bq = _RunBlockGamut(bq); // recurse873 874 bq = bq.replace(/(^|\n)/g,"$1 ");875 // These leading spaces screw with <pre> content, so we need to fix that:876 bq = bq.replace(877 /(\s*<pre>[^\r]+?<\/pre>)/gm,878 function(wholeMatch,m1) {879 var pre = m1;880 // attacklab: hack around Konqueror 3.5.4 bug:881 pre = pre.replace(/^ /mg,"~0");882 pre = pre.replace(/~0/g,"");883 return pre;884 });885 886 return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");887 });888 return text;889}890var _FormParagraphs = function(text) {891//892// Params:893// $text - string to process with html <p> tags894//895 // Strip leading and trailing lines:896 text = text.replace(/^\n+/g,"");897 text = text.replace(/\n+$/g,"");898 var grafs = text.split(/\n{2,}/g);899 var grafsOut = new Array();900 //901 // Wrap <p> tags.902 //903 var end = grafs.length;904 for (var i=0; i<end; i++) {905 var str = grafs[i];906 // if this is an HTML marker, copy it907 if (str.search(/~K(\d+)K/g) >= 0) {908 grafsOut.push(str);909 }910 else if (str.search(/\S/) >= 0) {911 str = _RunSpanGamut(str);912 str = str.replace(/^([ \t]*)/g,"<p>");913 str += "</p>"914 grafsOut.push(str);915 }916 }917 //918 // Unhashify HTML blocks919 //920 end = grafsOut.length;921 for (var i=0; i<end; i++) {922 // if this is a marker for an html block...923 while (grafsOut[i].search(/~K(\d+)K/) >= 0) {924 var blockText = g_html_blocks[RegExp.$1];925 blockText = blockText.replace(/\$/g,"$$$$"); // Escape any dollar signs926 grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);927 }928 }929 return grafsOut.join("\n\n");930}931var _EncodeAmpsAndAngles = function(text) {932// Smart processing for ampersands and angle brackets that need to be encoded.933 934 // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:935 // http://bumppo.net/projects/amputator/936 text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&amp;");937 938 // Encode naked <'s939 text = text.replace(/<(?![a-z\/?\$!])/gi,"&lt;");940 941 return text;942}943var _EncodeBackslashEscapes = function(text) {944//945// Parameter: String.946// Returns: The string, with after processing the following backslash947// escape sequences.948//949 // attacklab: The polite way to do this is with the new950 // escapeCharacters() function:951 //952 // text = escapeCharacters(text,"\\",true);953 // text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);954 //955 // ...but we're sidestepping its use of the (slow) RegExp constructor956 // as an optimization for Firefox. This function gets called a LOT.957 text = text.replace(/\\(\\)/g,escapeCharacters_callback);958 text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g,escapeCharacters_callback);959 return text;960}961var _DoAutoLinks = function(text) {962 text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");963 // Email addresses: <address@domain.foo>964 /*965 text = text.replace(/966 <967 (?:mailto:)?968 (969 [-.\w]+970 \@971 [-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+972 )973 >974 /gi, _DoAutoLinks_callback());975 */976 text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,977 function(wholeMatch,m1) {978 return _EncodeEmailAddress( _UnescapeSpecialChars(m1) );979 }980 );981 return text;982}983var _EncodeEmailAddress = function(addr) {984//985// Input: an email address, e.g. "foo@example.com"986//987// Output: the email address as a mailto link, with each character988// of the address encoded as either a decimal or hex entity, in989// the hopes of foiling most address harvesting spam bots. E.g.:990//991// <a href="&#x6D;&#97;&#105;&#108;&#x74;&#111;:&#102;&#111;&#111;&#64;&#101;992// x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;">&#102;&#111;&#111;993// &#64;&#101;x&#x61;&#109;&#x70;&#108;&#x65;&#x2E;&#99;&#111;&#109;</a>994//995// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk996// mailing list: <http://tinyurl.com/yu7ue>997//998 // attacklab: why can't javascript speak hex?999 function char2hex(ch) {1000 var hexDigits = '0123456789ABCDEF';1001 var dec = ch.charCodeAt(0);1002 return(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15));1003 }1004 var encode = [1005 function(ch){return "&#"+ch.charCodeAt(0)+";";},1006 function(ch){return "&#x"+char2hex(ch)+";";},1007 function(ch){return ch;}1008 ];1009 addr = "mailto:" + addr;1010 addr = addr.replace(/./g, function(ch) {1011 if (ch == "@") {1012 // this *must* be encoded. I insist.1013 ch = encode[Math.floor(Math.random()*2)](ch);1014 } else if (ch !=":") {1015 // leave ':' alone (to spot mailto: later)1016 var r = Math.random();1017 // roughly 10% raw, 45% hex, 45% dec1018 ch = (1019 r > .9 ? encode[2](ch) :1020 r > .45 ? encode[1](ch) :1021 encode[0](ch)1022 );1023 }1024 return ch;1025 });1026 addr = "<a href=\"" + addr + "\">" + addr + "</a>";1027 addr = addr.replace(/">.+:/g,"\">"); // strip the mailto: from the visible part1028 return addr;1029}1030var _UnescapeSpecialChars = function(text) {1031//1032// Swap back in all the special characters we've hidden.1033//1034 text = text.replace(/~E(\d+)E/g,1035 function(wholeMatch,m1) {1036 var charCodeToReplace = parseInt(m1);1037 return String.fromCharCode(charCodeToReplace);1038 }1039 );1040 return text;1041}1042var _Outdent = function(text) {1043//1044// Remove one level of line-leading tabs or spaces1045//1046 // attacklab: hack around Konqueror 3.5.4 bug:1047 // "----------bug".replace(/^-/g,"") == "bug"1048 text = text.replace(/^(\t|[ ]{1,4})/gm,"~0"); // attacklab: g_tab_width1049 // attacklab: clean up hack1050 text = text.replace(/~0/g,"")1051 return text;1052}1053var _Detab = function(text) {1054// attacklab: Detab's completely rewritten for speed.1055// In perl we could fix it by anchoring the regexp with \G.1056// In javascript we're less fortunate.1057 // expand first n-1 tabs1058 text = text.replace(/\t(?=\t)/g," "); // attacklab: g_tab_width1059 // replace the nth with two sentinels1060 text = text.replace(/\t/g,"~A~B");1061 // use the sentinel to anchor our regex so it doesn't explode1062 text = text.replace(/~B(.+?)~A/g,1063 function(wholeMatch,m1,m2) {1064 var leadingText = m1;1065 var numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width1066 // there *must* be a better way to do this:1067 for (var i=0; i<numSpaces; i++) leadingText+=" ";1068 return leadingText;1069 }1070 );1071 // clean up sentinels1072 text = text.replace(/~A/g," "); // attacklab: g_tab_width1073 text = text.replace(/~B/g,"");1074 return text;1075}1076//1077// attacklab: Utility functions1078//1079var escapeCharacters = function(text, charsToEscape, afterBackslash) {1080 // First we have to escape the escape characters so that1081 // we can build a character class out of them1082 var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";1083 if (afterBackslash) {1084 regexString = "\\\\" + regexString;1085 }1086 var regex = new RegExp(regexString,"g");1087 text = text.replace(regex,escapeCharacters_callback);1088 return text;1089}1090var escapeCharacters_callback = function(wholeMatch,m1) {1091 var charCodeToEscape = m1.charCodeAt(0);1092 return "~E"+charCodeToEscape+"E";1093}1094} // end of Attacklab.showdown.converter1095// Version 0.9 used the Showdown namespace instead of Attacklab.showdown1096// The old namespace is deprecated, but we'll support it for now:1097var Showdown = Attacklab.showdown;1098// If anyone's interested, tell the world that this file's been loaded1099if (Attacklab.fileLoaded) {1100 Attacklab.fileLoaded("showdown.js");1101}

Full Screen

Full Screen

editor.js

Source:editor.js Github

copy

Full Screen

...187 blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre' +188 '|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section' +189 '|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary';190 // Normalize line breaks191 text = text.replace( /\r\n|\r/g, '\n' );192 if ( text.indexOf( '\n' ) === -1 ) {193 return text;194 }195 if ( text.indexOf( '<object' ) !== -1 ) {196 text = text.replace( /<object[\s\S]+?<\/object>/g, function( a ) {197 return a.replace( /\n+/g, '' );198 });199 }200 text = text.replace( /<[^<>]+>/g, function( a ) {201 return a.replace( /[\n\t ]+/g, ' ' );202 });203 // Protect pre|script tags204 if ( text.indexOf( '<pre' ) !== -1 || text.indexOf( '<script' ) !== -1 ) {205 preserve_linebreaks = true;206 text = text.replace( /<(pre|script)[^>]*>[\s\S]*?<\/\1>/g, function( a ) {207 return a.replace( /\n/g, '<wp-line-break>' );208 });209 }210 // keep <br> tags inside captions and convert line breaks211 if ( text.indexOf( '[caption' ) !== -1 ) {212 preserve_br = true;213 text = text.replace( /\[caption[\s\S]+?\[\/caption\]/g, function( a ) {214 // keep existing <br>215 a = a.replace( /<br([^>]*)>/g, '<wp-temp-br$1>' );216 // no line breaks inside HTML tags217 a = a.replace( /<[^<>]+>/g, function( b ) {218 return b.replace( /[\n\t ]+/, ' ' );219 });220 // convert remaining line breaks to <br>221 return a.replace( /\s*\n\s*/g, '<wp-temp-br />' );222 });223 }224 text = text + '\n\n';225 text = text.replace( /<br \/>\s*<br \/>/gi, '\n\n' );226 text = text.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n$1' );227 text = text.replace( new RegExp( '(</(?:' + blocklist + ')>)', 'gi' ), '$1\n\n' );228 text = text.replace( /<hr( [^>]*)?>/gi, '<hr$1>\n\n' ); // hr is self closing block element229 text = text.replace( /\s*<option/gi, '<option' ); // No <p> or <br> around <option>230 text = text.replace( /<\/option>\s*/gi, '</option>' );231 text = text.replace( /\n\s*\n+/g, '\n\n' );232 text = text.replace( /([\s\S]+?)\n\n/g, '<p>$1</p>\n' );233 text = text.replace( /<p>\s*?<\/p>/gi, '');234 text = text.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' );235 text = text.replace( /<p>(<li.+?)<\/p>/gi, '$1');236 text = text.replace( /<p>\s*<blockquote([^>]*)>/gi, '<blockquote$1><p>');237 text = text.replace( /<\/blockquote>\s*<\/p>/gi, '</p></blockquote>');238 text = text.replace( new RegExp( '<p>\\s*(</?(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '$1' );239 text = text.replace( new RegExp( '(</?(?:' + blocklist + ')(?: [^>]*)?>)\\s*</p>', 'gi' ), '$1' );240 // Remove redundant spaces and line breaks after existing <br /> tags241 text = text.replace( /(<br[^>]*>)\s*\n/gi, '$1' );242 // Create <br /> from the remaining line breaks243 text = text.replace( /\s*\n/g, '<br />\n');244 text = text.replace( new RegExp( '(</?(?:' + blocklist + ')[^>]*>)\\s*<br />', 'gi' ), '$1' );245 text = text.replace( /<br \/>(\s*<\/?(?:p|li|div|dl|dd|dt|th|pre|td|ul|ol)>)/gi, '$1' );246 text = text.replace( /(?:<p>|<br ?\/?>)*\s*\[caption([^\[]+)\[\/caption\]\s*(?:<\/p>|<br ?\/?>)*/gi, '[caption$1[/caption]' );247 text = text.replace( /(<(?:div|th|td|form|fieldset|dd)[^>]*>)(.*?)<\/p>/g, function( a, b, c ) {248 if ( c.match( /<p( [^>]*)?>/ ) ) {249 return a;250 }251 return b + '<p>' + c + '</p>';252 });253 // put back the line breaks in pre|script254 if ( preserve_linebreaks ) {255 text = text.replace( /<wp-line-break>/g, '\n' );256 }257 if ( preserve_br ) {258 text = text.replace( /<wp-temp-br([^>]*)>/g, '<br$1>' );259 }260 return text;261 }262 // Add old events263 function pre_wpautop( html ) {264 var obj = { o: exports, data: html, unfiltered: html };265 if ( $ ) {266 $( 'body' ).trigger( 'beforePreWpautop', [ obj ] );267 }268 obj.data = removep( obj.data );269 if ( $ ) {270 $( 'body' ).trigger( 'afterPreWpautop', [ obj ] );271 }272 return obj.data;...

Full Screen

Full Screen

quiztools.js

Source:quiztools.js Github

copy

Full Screen

1var sampleWindow = null;2function loadReviewPage(numWords, secNum) {3 if (sampleWindow) {4 unLoadPage();5 }6 var gotWord = 0;7 sampleWindow = window.open("", "chineseReview", "location=no,menubar=yes,resizable=yes,height=480,width=600");8 sampleWindow.document.writeln("<html><head>");9 sampleWindow.document.writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");10 sampleWindow.document.writeln("</head><body>");11 sampleWindow.document.writeln("<b>2nd Yr. Chinese - ");12 sampleWindow.document.writeln(secNum + " Vocabulary Review</b><br>");13 sampleWindow.document.writeln("<table border=\"1\" cellpadding=\"5\" cellspacing=\"1\" width=\"100%\">");14 for (var i = 1; i < numWords; i++) {15 var name = "Box" + String(i);16 var cur = document.images[name].src;17 //r tradIndex = "anstrad" + String(i);18 //r pinyIndex = "anspinyin" + String(i);19 //r englIndex = "ansenglish" + String(i);20 21 //alert(22 if (cur.indexOf("red") > -1) {23 gotWord = 1;24 var firstIndex = "ans" + document.reviewPg.selectCol1.options[document.reviewPg.selectCol1.selectedIndex].value + String(i);25 var secondIndex = "ans" + document.reviewPg.selectCol2.options[document.reviewPg.selectCol2.selectedIndex].value + String(i);26 var thirdIndex = "ans" + document.reviewPg.selectCol3.options[document.reviewPg.selectCol3.selectedIndex].value + String(i);27 var bookIndex = "ansbookNum" + String(i);28 sampleWindow.document.writeln("<tr>\n");29 sampleWindow.document.writeln("<td width=\"10%\">" + document.response.elements[bookIndex].value + "</td>");30 sampleWindow.document.writeln("<td width=\"20%\"><font size=\"+2\">" + document.response.elements[firstIndex].value + "</font></td>");31 sampleWindow.document.writeln("<td width=\"30%\">" + document.response.elements[secondIndex].value + "</td>");32 sampleWindow.document.writeln("<td width=\"40%\">" + document.response.elements[thirdIndex].value + "</td>");33 sampleWindow.document.writeln("</tr>");34 }35 }36 sampleWindow.document.writeln("</table>");37 if (gotWord == 0) {38 sampleWindow.document.writeln("<br><b>Please mark at least one word by clicking on the small square in its row.</b>");39 }40 sampleWindow.document.writeln("<hr width=\"50%\" align=\"left\"><i>http://cgi.stanford.edu/~hc10/cgi-bin/chinese/main.pl</i>");41 sampleWindow.document.writeln("<br><br></body></html>");42}43function unLoadPage() {44 if (sampleWindow) {45 sampleWindow.close();46 sampleWindow = null;47 }48}49function replace(string,text,by) {50 // Replaces text with by in string51 var strLength = string.length, txtLength = text.length;52 if ((strLength == 0) || (txtLength == 0)) return string;53 var i = string.indexOf(text);54 if ((!i) && (text != string.substring(0,txtLength))) return string;55 if (i == -1) return string;56 57 var newstr = string.substring(0,i) + by;58 if (i+txtLength < strLength)59 newstr += replace(string.substring(i+txtLength,strLength),text,by);60 return newstr;61}62function reveal(index) {63 var ansindex = "ans" + String(index);64 var ansbox = String(index);65 var display = document.response.elements[ansindex].value;66 display = replace(display, '#', '/');67 document.answer.elements[ansbox].value = display;68}69function give(index) {70 var ansindex = "ans" + String(index);71 var ansbox = String(index);72 var display = document.response.elements[ansindex].value;73 display = replace(display, '#', '/');74 document.response.elements[ansbox].value = display;75}76function check(index) {77 reveal(index);78 var textbox = String(index);79 var hiddenanswer = "ans" + String(index);80 var rawans = document.response.elements[hiddenanswer].value;81 var altans = "BLANK";82 var divider = rawans.indexOf("#");83 if (divider > -1) {84 altans = rawans.substr(divider + 1, rawans.length);85 rawans = rawans.substr(0, divider);86 }87 var yourans_nospc = replace(document.response.elements[textbox].value, ' ', '');88 var rawans_nospc = replace(rawans, ' ', '');89 var altans_nospc = replace(altans, ' ', '');90 //if(document.response.elements[textbox].value == rawans || document.response.elements[textbox].value == altans) {91 if(yourans_nospc == rawans_nospc || yourans_nospc == altans_nospc) {92 // green93 document.response.elements[textbox].style.backgroundColor = "#AAFFAA";94 }95 else {96 if(document.response.elements[textbox].value == "") {97 // leave white98 document.response.elements[textbox].style.backgroundColor = "#FFFFFF";99 }100 else {101 // red102 document.response.elements[textbox].style.backgroundColor = "#FFAAAA";103 }104 }105}106function cleanForm(formIndex) {107 document.forms[formIndex].reset();108 var cleanColor = 16777215 - ((parseInt(formIndex) - 2) * 1118481);109 var size = parseInt(document.answer.length) / 3;110 for (var i = 1; i <= size; i++) {111 var tradbox = "trad" + String(i);112 // var simpbox = "simp" + String(i);113 var pinyinbox = "pinyin" + String(i);114 var englishbox = "english" + String(i);115 document.forms[formIndex].elements[tradbox].style.backgroundColor = "#" + cleanColor.toString(16);116 // document.forms[formIndex].elements[simpbox].style.backgroundColor = "#" + cleanColor.toString(16);117 document.forms[formIndex].elements[pinyinbox].style.backgroundColor = "#" + cleanColor.toString(16);118 document.forms[formIndex].elements[englishbox].style.backgroundColor = "#" + cleanColor.toString(16);119 document.forms[formIndex].elements[tradbox].value = "";120 // document.forms[formIndex].elements[simpbox].value = "";121 document.forms[formIndex].elements[pinyinbox].value = "";122 document.forms[formIndex].elements[englishbox].value = "";123 }124}125function setBoxes(onOff) {126 var size = parseInt(document.answer.length) / 3;127 if (parseInt(onOff) == 0) {128 var boxName = "emptybox.gif";129 }130 else {131 var boxName = "redbox.gif";132 }133 for (var i = 1; i <= size; i++) {134 var name= "Box" + String(i);135 document.images[name].src =136 "http://www.stanford.edu/~hc10/greek/images/" + boxName;137 }138}139function checkAll(category) {140 var size = parseInt(document.answer.length) / 3;141 if (size < 1) {142 size = 1;143 }144 for (var i = 1; i <= size; i++) {145 check(category + String(i));146 }147}148function giveAll(category) {149 var size = parseInt(document.answer.length) / 3;150 if (size < 1) {151 size = 1;152 }153 for (var i = 1; i <= size; i++) {154 give(category + String(i));155 }156}157function checkRange(begin, end) {158 if (parseInt(end) < parseInt(begin)) {159 end = begin;160 }161 for (var i = parseInt(begin); i <= parseInt(end); i++) {162 check(i);163 }164}165function py2utf(index) { 166 var textbox = "pinyin" + String(index);167 text = document.response.elements[textbox].value;168 var key = document.all ? event.keyCode : 0;169 if (key == 8 || key == 16 || key == 17 || key == 18 || key == 20 || key == 33 || key == 34 || key == 36 || key == 37 || key == 38 || key == 39 || key == 40 || key == 45 || key == 46) {170 return;171 }172 173 text = replace(text,'u:an1','üān');174 text = replace(text,'u:an2','üán');175 text = replace(text,'u:an3','üǎn');176 text = replace(text,'u:an4','üàn');177 text = replace(text,'u:e1','üē');178 text = replace(text,'u:e2','üé');179 text = replace(text,'u:e3','üě');180 text = replace(text,'u:e4','üè');181 text = replace(text,'a1','ā');182 text = replace(text,'a2','á');183 text = replace(text,'a3','ǎ');184 text = replace(text,'a4','à');185 text = replace(text,'ai1','āi');186 text = replace(text,'ai2','ái');187 text = replace(text,'ai3','ǎi');188 text = replace(text,'ai4','ài');189 text = replace(text,'an1','ān');190 text = replace(text,'an2','án');191 text = replace(text,'an3','ǎn');192 text = replace(text,'an4','àn');193 text = replace(text,'ang1','āng');194 text = replace(text,'ang2','áng');195 text = replace(text,'ang3','ǎng');196 text = replace(text,'ang4','àng');197 text = replace(text,'ao1','āo');198 text = replace(text,'ao2','áo');199 text = replace(text,'ao3','ǎo');200 text = replace(text,'ao4','ào');201 text = replace(text,'ar1','ār');202 text = replace(text,'ar2','ár');203 text = replace(text,'ar3','ǎr');204 text = replace(text,'ar4','àr');205 text = replace(text,'e1','ē');206 text = replace(text,'e2','é');207 text = replace(text,'e3','ě');208 text = replace(text,'e4','è');209 text = replace(text,'ei1','ēi');210 text = replace(text,'ei2','éi');211 text = replace(text,'ei3','ěi');212 text = replace(text,'ei4','èi');213 text = replace(text,'en1','ēn');214 text = replace(text,'en2','én');215 text = replace(text,'en3','ěn');216 text = replace(text,'en4','èn');217 text = replace(text,'eng1','ēng');218 text = replace(text,'eng2','éng');219 text = replace(text,'eng3','ěng');220 text = replace(text,'eng4','èng');221 text = replace(text,'er1','ēr');222 text = replace(text,'er2','ér');223 text = replace(text,'er3','ěr');224 text = replace(text,'er4','èr');225 text = replace(text,'i1','ī');226 text = replace(text,'i2','í');227 text = replace(text,'i3','ǐ');228 text = replace(text,'i4','ì');229 text = replace(text,'in1','īn');230 text = replace(text,'in2','ín');231 text = replace(text,'in3','ǐn');232 text = replace(text,'in4','ìn');233 text = replace(text,'ing1','īng');234 text = replace(text,'ing2','íng');235 text = replace(text,'ing3','ǐng');236 text = replace(text,'ing4','ìng');237 text = replace(text,'ir1','īr');238 text = replace(text,'ir2','ír');239 text = replace(text,'ir3','ǐr');240 text = replace(text,'ir4','ìr');241 text = replace(text,'o1','ō');242 text = replace(text,'o2','ó');243 text = replace(text,'o3','ǒ');244 text = replace(text,'o4','ò');245 text = replace(text,'ong1','ōng');246 text = replace(text,'ong2','óng');247 text = replace(text,'ong3','ǒng');248 text = replace(text,'ong4','òng');249 text = replace(text,'ou1','ōu');250 text = replace(text,'ou2','óu');251 text = replace(text,'ou3','ǒu');252 text = replace(text,'ou4','òu');253 text = replace(text,'u1','ū');254 text = replace(text,'u2','ú');255 text = replace(text,'u3','ǔ');256 text = replace(text,'u4','ù');257 text = replace(text,'un1','ūn');258 text = replace(text,'un2','ún');259 text = replace(text,'un3','ǔn');260 text = replace(text,'un4','ùn');261 text = replace(text,'u:1','ǖ');262 text = replace(text,'u:2','ǘ');263 text = replace(text,'u:3','ǚ');264 text = replace(text,'u:4','ǜ');265 document.response.elements[textbox].value = text; ...

Full Screen

Full Screen

inputex-examples.js

Source:inputex-examples.js Github

copy

Full Screen

...5 */6 7 // Decode html entities8 var html_entity_decode = function (text) {9 text = text.replace(/&quot;/g,'"'); // 34 2210 text = text.replace(/&amp;/g,'&'); // 38 26 11 text = text.replace(/&#39;/g,"'"); // 39 2712 text = text.replace(/&lt;/g,'<'); // 60 3C13 text = text.replace(/&gt;/g,'>'); // 62 3E14 text = text.replace(/&circ;/g,'^'); // 94 5E15 text = text.replace(/&lsquo;/g,'‘'); // 145 9116 text = text.replace(/&rsquo;/g,'’'); // 146 9217 text = text.replace(/&ldquo;/g,'“'); // 147 9318 text = text.replace(/&rdquo;/g,'”'); // 148 9419 text = text.replace(/&bull;/g,'•'); // 149 9520 text = text.replace(/&ndash;/g,'–'); // 150 9621 text = text.replace(/&mdash;/g,'—'); // 151 9722 text = text.replace(/&tilde;/g,'˜'); // 152 9823 text = text.replace(/&trade;/g,'™'); // 153 9924 text = text.replace(/&scaron;/g,'š'); // 154 9A25 text = text.replace(/&rsaquo;/g,'›'); // 155 9B26 text = text.replace(/&oelig;/g,'œ'); // 156 9C27 text = text.replace(/&#357;/g,''); // 157 9D28 text = text.replace(/&#382;/g,'ž'); // 158 9E29 text = text.replace(/&Yuml;/g,'Ÿ'); // 159 9F30 text = text.replace(/&nbsp;/g,' '); // 160 A031 text = text.replace(/&iexcl;/g,'¡'); // 161 A132 text = text.replace(/&cent;/g,'¢'); // 162 A233 text = text.replace(/&pound;/g,'£'); // 163 A334 text = text.replace(/&curren;/g,' '); // 164 A435 text = text.replace(/&yen;/g,'¥'); // 165 A536 text = text.replace(/&brvbar;/g,'¦'); // 166 A637 text = text.replace(/&sect;/g,'§'); // 167 A738 text = text.replace(/&uml;/g,'¨'); // 168 A839 text = text.replace(/&copy;/g,'©'); // 169 A940 text = text.replace(/&ordf;/g,'ª'); // 170 AA41 text = text.replace(/&laquo;/g,'«'); // 171 AB42 text = text.replace(/&not;/g,'¬'); // 172 AC43 text = text.replace(/&shy;/g,'­'); // 173 AD44 text = text.replace(/&reg;/g,'®'); // 174 AE45 text = text.replace(/&macr;/g,'¯'); // 175 AF46 text = text.replace(/&deg;/g,'°'); // 176 B047 text = text.replace(/&plusmn;/g,'±'); // 177 B148 text = text.replace(/&sup2;/g,'²'); // 178 B249 text = text.replace(/&sup3;/g,'³'); // 179 B350 text = text.replace(/&acute;/g,'´'); // 180 B451 text = text.replace(/&micro;/g,'µ'); // 181 B552 text = text.replace(/&para/g,'¶'); // 182 B653 text = text.replace(/&middot;/g,'·'); // 183 B754 text = text.replace(/&cedil;/g,'¸'); // 184 B855 text = text.replace(/&sup1;/g,'¹'); // 185 B956 text = text.replace(/&ordm;/g,'º'); // 186 BA57 text = text.replace(/&raquo;/g,'»'); // 187 BB58 text = text.replace(/&frac14;/g,'¼'); // 188 BC59 text = text.replace(/&frac12;/g,'½'); // 189 BD60 text = text.replace(/&frac34;/g,'¾'); // 190 BE61 text = text.replace(/&iquest;/g,'¿'); // 191 BF62 text = text.replace(/&Agrave;/g,'À'); // 192 C063 text = text.replace(/&Aacute;/g,'Á'); // 193 C164 text = text.replace(/&Acirc;/g,'Â'); // 194 C265 text = text.replace(/&Atilde;/g,'Ã'); // 195 C366 text = text.replace(/&Auml;/g,'Ä'); // 196 C467 text = text.replace(/&Aring;/g,'Å'); // 197 C568 text = text.replace(/&AElig;/g,'Æ'); // 198 C669 text = text.replace(/&Ccedil;/g,'Ç'); // 199 C770 text = text.replace(/&Egrave;/g,'È'); // 200 C871 text = text.replace(/&Eacute;/g,'É'); // 201 C972 text = text.replace(/&Ecirc;/g,'Ê'); // 202 CA73 text = text.replace(/&Euml;/g,'Ë'); // 203 CB74 text = text.replace(/&Igrave;/g,'Ì'); // 204 CC75 text = text.replace(/&Iacute;/g,'Í'); // 205 CD76 text = text.replace(/&Icirc;/g,'Î'); // 206 CE77 text = text.replace(/&Iuml;/g,'Ï'); // 207 CF78 text = text.replace(/&ETH;/g,'Ð'); // 208 D079 text = text.replace(/&Ntilde;/g,'Ñ'); // 209 D180 text = text.replace(/&Ograve;/g,'Ò'); // 210 D281 text = text.replace(/&Oacute;/g,'Ó'); // 211 D382 text = text.replace(/&Ocirc;/g,'Ô'); // 212 D483 text = text.replace(/&Otilde;/g,'Õ'); // 213 D584 text = text.replace(/&Ouml;/g,'Ö'); // 214 D685 text = text.replace(/&times;/g,'×'); // 215 D786 text = text.replace(/&Oslash;/g,'Ø'); // 216 D887 text = text.replace(/&Ugrave;/g,'Ù'); // 217 D988 text = text.replace(/&Uacute;/g,'Ú'); // 218 DA89 text = text.replace(/&Ucirc;/g,'Û'); // 219 DB90 text = text.replace(/&Uuml;/g,'Ü'); // 220 DC91 text = text.replace(/&Yacute;/g,'Ý'); // 221 DD92 text = text.replace(/&THORN;/g,'Þ'); // 222 DE93 text = text.replace(/&szlig;/g,'ß'); // 223 DF94 text = text.replace(/&agrave;/g,'à'); // 224 E095 text = text.replace(/&aacute;/g,'á'); // 225 E196 text = text.replace(/&acirc;/g,'â'); // 226 E297 text = text.replace(/&atilde;/g,'ã'); // 227 E398 text = text.replace(/&auml;/g,'ä'); // 228 E499 text = text.replace(/&aring;/g,'å'); // 229 E5100 text = text.replace(/&aelig;/g,'æ'); // 230 E6101 text = text.replace(/&ccedil;/g,'ç'); // 231 E7102 text = text.replace(/&egrave;/g,'è'); // 232 E8103 text = text.replace(/&eacute;/g,'é'); // 233 E9104 text = text.replace(/&ecirc;/g,'ê'); // 234 EA105 text = text.replace(/&euml;/g,'ë'); // 235 EB106 text = text.replace(/&igrave;/g,'ì'); // 236 EC107 text = text.replace(/&iacute;/g,'í'); // 237 ED108 text = text.replace(/&icirc;/g,'î'); // 238 EE109 text = text.replace(/&iuml;/g,'ï'); // 239 EF110 text = text.replace(/&eth;/g,'ð'); // 240 F0111 text = text.replace(/&ntilde;/g,'ñ'); // 241 F1112 text = text.replace(/&ograve;/g,'ò'); // 242 F2113 text = text.replace(/&oacute;/g,'ó'); // 243 F3114 text = text.replace(/&ocirc;/g,'ô'); // 244 F4115 text = text.replace(/&otilde;/g,'õ'); // 245 F5116 text = text.replace(/&ouml;/g,'ö'); // 246 F6117 text = text.replace(/&divide;/g,'÷'); // 247 F7118 text = text.replace(/&oslash;/g,'ø'); // 248 F8119 text = text.replace(/&ugrave;/g,'ù'); // 249 F9120 text = text.replace(/&uacute;/g,'ú'); // 250 FA121 text = text.replace(/&ucirc;/g,'û'); // 251 FB122 text = text.replace(/&uuml;/g,'ü'); // 252 FC123 text = text.replace(/&yacute;/g,'ý'); // 253 FD124 text = text.replace(/&thorn;/g,'þ'); // 254 FE125 text = text.replace(/&yuml;/g,'ÿ'); // 255 FF126 return text;127 };128 129 130 // Required for the ListField131 inputEx.spacerUrl = "../images/space.gif";132 133 134 YAHOO.util.Event.onDOMReady(function() {135 136 var examples, i, length, textarea, code;137 138 examples = YAHOO.util.Dom.getElementsByClassName('JScript');139 ...

Full Screen

Full Screen

RelatedObjectLookups.js

Source:RelatedObjectLookups.js Github

copy

Full Screen

1// Handles related-objects functionality: lookup link for raw_id_fields2// and Add Another links.3function html_unescape(text) {4 // Unescape a string that was escaped using django.utils.html.escape.5 text = text.replace(/&lt;/g, '<');6 text = text.replace(/&gt;/g, '>');7 text = text.replace(/&quot;/g, '"');8 text = text.replace(/&#39;/g, "'");9 text = text.replace(/&amp;/g, '&');10 return text;11}12// IE doesn't accept periods or dashes in the window name, but the element IDs13// we use to generate popup window names may contain them, therefore we map them14// to allowed characters in a reversible way so that we can locate the correct 15// element when the popup window is dismissed.16function id_to_windowname(text) {17 text = text.replace(/\./g, '__dot__');18 text = text.replace(/\-/g, '__dash__');19 return text;20}21function windowname_to_id(text) {22 text = text.replace(/__dot__/g, '.');23 text = text.replace(/__dash__/g, '-');24 return text;25}26function showRelatedObjectLookupPopup(triggeringLink) {27 var name = triggeringLink.id.replace(/^lookup_/, '');28 name = id_to_windowname(name);29 var href;30 if (triggeringLink.href.search(/\?/) >= 0) {31 href = triggeringLink.href + '&pop=1';32 } else {33 href = triggeringLink.href + '?pop=1';34 }35 var win = window.open(href, name, 'height=500,width=800,resizable=yes,scrollbars=yes');36 win.focus();37 return false;...

Full Screen

Full Screen

page.js

Source:page.js Github

copy

Full Screen

...10 } else {11 path = /\/api\/[A-z0-9\/]+/.exec( pathname ).toString().substr( 5 );12 }13 var text = document.body.innerHTML;14 text = text.replace(/\[name\]/gi, name);15 text = text.replace(/\[path\]/gi, path);16 text = text.replace(/\[page:(\w+)\]/gi, "[page:$1 $1]" ); // [page:name] to [page:name title]17 text = text.replace(/\[page:(\w+) ([\w|\.]+)\]/gi, "<a href=\"javascript:window.parent.goTo('$1')\" title=\"$1\">$2</a>" ); // [page:name title]18 text = text.replace(/\[link:([\w|\:|\/|\.|\-|\_]+)\]/gi, "[link:$1 $1]" ); // [link:url] to [link:url title]19 text = text.replace(/\[link:([\w|\:|\/|\.|\-|\_|\(|\)]+) ([\w|\:|\/|\.|\-|\_ ]+)\]/gi, "<a href=\"$1\" target=\"_blank\">$2</a>" ); // [link:url title]20 text = text.replace(/\*([\w|\d|\"|\-|\(][\w|\d|\ |\-|\/|\+|\-|\(|\)|\=|\,|\.\"]*[\w|\d|\"|\)]|\w)\*/gi, "<strong>$1</strong>" ); // *21 document.body.innerHTML = text;22 // handle code snippets formatting23 var elements = document.getElementsByTagName( 'code' );24 for ( var i = 0; i < elements.length; i ++ ) {25 var element = elements[ i ];26 text = element.textContent.trim();27 text = text.replace( /^\t\t/gm, '' );28 element.textContent = text;29 }30 // Edit button31 var button = document.createElement( 'div' );32 button.id = 'button';33 button.textContent = 'Edit this page';34 button.addEventListener( 'click', function ( event ) {35 window.open( 'https://github.com/mrdoob/three.js/blob/dev/docs/' + section + '/' + path + '.html' );36 }, false );37 document.body.appendChild( button );38 // Syntax highlighting39 var styleBase = document.createElement( 'link' );40 styleBase.href = '../../prettify/prettify.css';41 styleBase.rel = 'stylesheet';...

Full Screen

Full Screen

normalizer_no.js

Source:normalizer_no.js Github

copy

Full Screen

...21 * Remove commonly used diacritic marks from a string as these22 * are not used in a consistent manner. Leave only ä, ö, ü.23 */24const removeDiacritics = function (text) {25 text = text.replace('à', 'a')26 text = text.replace('À', 'A')27 text = text.replace('á', 'a')28 text = text.replace('Á', 'A')29 text = text.replace('â', 'a')30 text = text.replace('Â', 'A')31 text = text.replace('ç', 'c')32 text = text.replace('Ç', 'C')33 text = text.replace('è', 'e')34 text = text.replace('È', 'E')35 text = text.replace('é', 'e')36 text = text.replace('É', 'E')37 text = text.replace('ê', 'e')38 text = text.replace('Ê', 'E')39 text = text.replace('î', 'i')40 text = text.replace('Î', 'I')41 text = text.replace('ñ', 'n')42 text = text.replace('Ñ', 'N')43 text = text.replace('ó', 'o')44 text = text.replace('Ó', 'O')45 text = text.replace('ô', 'o')46 text = text.replace('Ô', 'O')47 text = text.replace('û', 'u')48 text = text.replace('Û', 'U')49 text = text.replace('š', 's')50 text = text.replace('Š', 'S')51 return text52}53// export the relevant stuff....

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var gherkin = require('gherkin');2var fs = require('fs');3var text = fs.readFileSync('test.feature', 'utf8');4var parser = new gherkin.Parser();5var feature = parser.parse(text);6console.log(feature);7var gherkin = require('gherkin');8var fs = require('fs');9var text = fs.readFileSync('test.feature', 'utf8');10var parser = new gherkin.Parser();11var feature = parser.parse(text);12console.log(feature);13var gherkin = require('gherkin');14var fs = require('fs');15var text = fs.readFileSync('test.feature', 'utf8');16var parser = new gherkin.Parser();17var feature = parser.parse(text);18console.log(feature);19var gherkin = require('gherkin');20var fs = require('fs');21var text = fs.readFileSync('test.feature', 'utf8');22var parser = new gherkin.Parser();23var feature = parser.parse(text);24console.log(feature);25var gherkin = require('gherkin');26var fs = require('fs');27var text = fs.readFileSync('test.feature', 'utf8');28var parser = new gherkin.Parser();29var feature = parser.parse(text);30console.log(feature);31var gherkin = require('gherkin');32var fs = require('fs');33var text = fs.readFileSync('test.feature', 'utf8');34var parser = new gherkin.Parser();35var feature = parser.parse(text);36console.log(feature);

Full Screen

Using AI Code Generation

copy

Full Screen

1var text = "I am a string";2var replacedText = text.replace("a", "the");3var text = "I am a string";4var replacedText = text.replace(/a/g, "the");5var text = "I am a string";6var replacedText = text.replace(/a/gi, "the");7var text = "I am a string";8var replacedText = text.replace(/a/g, "the");9var text = "I am a string";10var replacedText = text.replace(/a/gi, "the");11var text = "I am a string";12var replacedText = text.replace(/a/g, "the");13var text = "I am a string";14var replacedText = text.replace(/a/gi, "the");15var text = "I am a string";16var replacedText = text.replace(/a/g, "the");17var text = "I am a string";18var replacedText = text.replace(/a/gi, "the");19var text = "I am a string";20var replacedText = text.replace(/a/g, "the");21var text = "I am a string";22var replacedText = text.replace(/a/gi,

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Given, When, Then } = require('cucumber');2const { expect } = require('chai');3When('I replace the placeholders with values', function () {4 return 'pending';5});6Then('I should get a valid feature file', function () {7 return 'pending';8});9 at Object.Given (/Users/saurabhagrawal/Documents/POC/POC-1/test.js:6:48)10const {Given, When, Then} = require('cucumber');11const {expect} = require('chai');12Given(/^I am on the home page$/, function () {13 return 'pending';14});15When(/^I search for a movie$/, function () {16 return 'pending';17});18Then(/^I should see the movie in the results$/, function () {19 return 'pending';20});

Full Screen

Using AI Code Generation

copy

Full Screen

1var text = 'I am a <TYPE> developer';2var newText = text.replace('<TYPE>', 'web');3console.log(newText);4var text = 'I am a <TYPE> developer';5var newText = text.replace('<TYPE>', 'web');6console.log(newText);7var text = 'I am a <TYPE> developer';8var newText = text.replace('<TYPE>', 'web');9console.log(newText);10var text = 'I am a <TYPE> developer';11var newText = text.replace('<TYPE>', 'web');12console.log(newText);13var text = 'I am a <TYPE> developer';14var newText = text.replace('<TYPE>', 'web');15console.log(newText);16var text = 'I am a <TYPE> developer';17var newText = text.replace('<TYPE>', 'web');18console.log(newText);19var text = 'I am a <TYPE> developer';20var newText = text.replace('<TYPE>', 'web');21console.log(newText);22var text = 'I am a <TYPE> developer';23var newText = text.replace('<TYPE>',

Full Screen

Using AI Code Generation

copy

Full Screen

1var text1 = 'I have 2 apples';2var text2 = 'I have 3 oranges';3var text3 = 'I have 4 pears';4var text4 = 'I have 2 apples and 3 oranges and 4 pears';5var text5 = text4.replace(/(\d+)/g, function(match, num){6 return num*2;7});8console.log(text5);9var text1 = 'I have 2 apples';10var text2 = 'I have 3 oranges';11var text3 = 'I have 4 pears';12var text4 = 'I have 2 apples and 3 oranges and 4 pears';13var text5 = text4.replace(/(\d+)/g, function(match, num){14 return num*2;15});16console.log(text5);17var text1 = 'I have 2 apples';18var text2 = 'I have 3 oranges';19var text3 = 'I have 4 pears';20var text4 = 'I have 2 apples and 3 oranges and 4 pears';21var text5 = text4.replace(/(\d+)/g, function(match, num){22 return num*2;23});24console.log(text5);25var text1 = 'I have 2 apples';26var text2 = 'I have 3 oranges';27var text3 = 'I have 4 pears';28var text4 = 'I have 2 apples and 3 oranges and 4 pears';29var text5 = text4.replace(/(\d+)/g, function(match, num){30 return num*2;31});32console.log(text5);

Full Screen

Using AI Code Generation

copy

Full Screen

1var fs = require('fs');2var gherkin = require('gherkin');3var path = require('path');4var lang = 'en';5var langDir = path.join(__dirname, 'node_modules', 'gherkin', 'i18n');6var langFile = path.join(langDir, lang + '.json');7var langJson = fs.readFileSync(langFile, 'utf8');8var langObj = JSON.parse(langJson);9var replace = function(s) {10 return s.replace(/<[^>]+>/g, function(x) {11 return langObj[x];12 });13};

Full Screen

Cucumber Tutorial:

LambdaTest offers a detailed Cucumber testing tutorial, explaining its features, importance, best practices, and more to help you get started with running your automation testing scripts.

Cucumber Tutorial Chapters:

Here are the detailed Cucumber testing chapters to help you get started:

  • Importance of Cucumber - Learn why Cucumber is important in Selenium automation testing during the development phase to identify bugs and errors.
  • Setting Up Cucumber in Eclipse and IntelliJ - Learn how to set up Cucumber in Eclipse and IntelliJ.
  • Running First Cucumber.js Test Script - After successfully setting up your Cucumber in Eclipse or IntelliJ, this chapter will help you get started with Selenium Cucumber testing in no time.
  • Annotations in Cucumber - To handle multiple feature files and the multiple scenarios in each file, you need to use functionality to execute these scenarios. This chapter will help you learn about a handful of Cucumber annotations ranging from tags, Cucumber hooks, and more to ease the maintenance of the framework.
  • Automation Testing With Cucumber And Nightwatch JS - Learn how to build a robust BDD framework setup for performing Selenium automation testing by integrating Cucumber into the Nightwatch.js framework.
  • Automation Testing With Selenium, Cucumber & TestNG - Learn how to perform Selenium automation testing by integrating Cucumber with the TestNG framework.
  • Integrate Cucumber With Jenkins - By using Cucumber with Jenkins integration, you can schedule test case executions remotely and take advantage of the benefits of Jenkins. Learn how to integrate Cucumber with Jenkins with this detailed chapter.
  • Cucumber Best Practices For Selenium Automation - Take a deep dive into the advanced use cases, such as creating a feature file, separating feature files, and more for Cucumber testing.

Run Cucumber-gherkin automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful