\r\n// and tags get encoded.\r\n//\r\n\r\n // Clear the global hashes. If we don't clear these, you get conflicts\r\n // from other articles when generating a page which contains more than\r\n // one article (e.g. an index page that shows the N most recent\r\n // articles):\r\n g_urls = {};\r\n g_titles = {};\r\n g_html_blocks = [];\r\n\r\n // attacklab: Replace ~ with ~T\r\n // This lets us use tilde as an escape char to avoid md5 hashes\r\n // The choice of character is arbitray; anything that isn't\r\n // magic in Markdown will work.\r\n text = text.replace(/~/g, \"~T\");\r\n\r\n // attacklab: Replace $ with ~D\r\n // RegExp interprets $ as a special character\r\n // when it's in a replacement string\r\n text = text.replace(/\\$/g, \"~D\");\r\n\r\n // Standardize line endings\r\n text = text.replace(/\\r\\n/g, \"\\n\"); // DOS to Unix\r\n text = text.replace(/\\r/g, \"\\n\"); // Mac to Unix\r\n\r\n // Make sure text begins and ends with a couple of newlines:\r\n text = \"\\n\\n\" + text + \"\\n\\n\";\r\n\r\n // Convert all tabs to spaces.\r\n text = _Detab(text);\r\n\r\n // Strip any lines consisting only of spaces and tabs.\r\n // This makes subsequent regexen easier to write, because we can\r\n // match consecutive blank lines with /\\n+/ instead of something\r\n // contorted like /[ \\t]*\\n+/ .\r\n text = text.replace(/^[ \\t]+$/mg, \"\");\r\n\r\n // Run language extensions\r\n Showdown.forEach(g_lang_extensions, function (x) {\r\n text = _ExecuteExtension(x, text);\r\n });\r\n\r\n // Handle github codeblocks prior to running HashHTML so that\r\n // HTML contained within the codeblock gets escaped propertly\r\n text = _DoGithubCodeBlocks(text);\r\n\r\n // Turn block-level HTML blocks into hash entries\r\n text = _HashHTMLBlocks(text);\r\n\r\n // Strip link definitions, store in hashes.\r\n text = _StripLinkDefinitions(text);\r\n\r\n text = _RunBlockGamut(text);\r\n\r\n text = _UnescapeSpecialChars(text);\r\n\r\n // attacklab: Restore dollar signs\r\n text = text.replace(/~D/g, \"$$\");\r\n\r\n // attacklab: Restore tildes\r\n text = text.replace(/~T/g, \"~\");\r\n\r\n // Run output modifiers\r\n Showdown.forEach(g_output_modifiers, function (x) {\r\n text = _ExecuteExtension(x, text);\r\n });\r\n\r\n return text;\r\n };\r\n\r\n\r\n//\r\n// Options:\r\n//\r\n\r\n// Parse extensions options into separate arrays\r\n if (converter_options && converter_options.extensions) {\r\n\r\n var self = this;\r\n\r\n // Iterate over each plugin\r\n Showdown.forEach(converter_options.extensions, function (plugin) {\r\n\r\n // Assume it's a bundled plugin if a string is given\r\n if (typeof plugin === 'string') {\r\n plugin = Showdown.extensions[stdExtName(plugin)];\r\n }\r\n\r\n if (typeof plugin === 'function') {\r\n // Iterate over each extension within that plugin\r\n Showdown.forEach(plugin(self), function (ext) {\r\n // Sort extensions by type\r\n if (ext.type) {\r\n if (ext.type === 'language' || ext.type === 'lang') {\r\n g_lang_extensions.push(ext);\r\n } else if (ext.type === 'output' || ext.type === 'html') {\r\n g_output_modifiers.push(ext);\r\n }\r\n } else {\r\n // Assume language extension\r\n g_output_modifiers.push(ext);\r\n }\r\n });\r\n } else {\r\n throw \"Extension '\" + plugin + \"' could not be loaded. It was either not found or is not a valid extension.\";\r\n }\r\n });\r\n }\r\n\r\n\r\n var _ExecuteExtension = function (ext, text) {\r\n if (ext.regex) {\r\n var re = new RegExp(ext.regex, 'g');\r\n return text.replace(re, ext.replace);\r\n } else if (ext.filter) {\r\n return ext.filter(text);\r\n }\r\n };\r\n\r\n var _StripLinkDefinitions = function (text) {\r\n//\r\n// Strips link definitions from text, stores the URLs and titles in\r\n// hash references.\r\n//\r\n\r\n // Link defs are in the form: ^[id]: url \"optional title\"\r\n\r\n /*\r\n var text = text.replace(/\r\n ^[ ]{0,3}\\[(.+)\\]: // id = $1 attacklab: g_tab_width - 1\r\n [ \\t]*\r\n \\n?\t\t\t\t// maybe *one* newline\r\n [ \\t]*\r\n (\\S+?)>?\t\t\t// url = $2\r\n [ \\t]*\r\n \\n?\t\t\t\t// maybe one newline\r\n [ \\t]*\r\n (?:\r\n (\\n*)\t\t\t\t// any lines skipped = $3 attacklab: lookbehind removed\r\n [\"(]\r\n (.+?)\t\t\t\t// title = $4\r\n [\")]\r\n [ \\t]*\r\n )?\t\t\t\t\t// title is optional\r\n (?:\\n+|$)\r\n /gm,\r\n function(){...});\r\n */\r\n\r\n // attacklab: sentinel workarounds for lack of \\A and \\Z, safari\\khtml bug\r\n text += \"~0\";\r\n\r\n text = text.replace(/^[ ]{0,3}\\[(.+)\\]:[ \\t]*\\n?[ \\t]*(\\S+?)>?[ \\t]*\\n?[ \\t]*(?:(\\n*)[\"(](.+?)[\")][ \\t]*)?(?:\\n+|(?=~0))/gm,\r\n function (wholeMatch, m1, m2, m3, m4) {\r\n m1 = m1.toLowerCase();\r\n g_urls[m1] = _EncodeAmpsAndAngles(m2); // Link IDs are case-insensitive\r\n if (m3) {\r\n // Oops, found blank lines, so it's not a title.\r\n // Put back the parenthetical statement we stole.\r\n return m3 + m4;\r\n } else if (m4) {\r\n g_titles[m1] = m4.replace(/\"/g, \""\");\r\n }\r\n\r\n // Completely remove the definition from the text\r\n return \"\";\r\n }\r\n );\r\n\r\n // attacklab: strip sentinel\r\n text = text.replace(/~0/, \"\");\r\n\r\n return text;\r\n }\r\n\r\n var _HashHTMLBlocks = function (text) {\r\n // attacklab: Double up blank lines to reduce lookaround\r\n text = text.replace(/\\n/g, \"\\n\\n\");\r\n\r\n // Hashify HTML blocks:\r\n // We only want to do this for block-level HTML tags, such as headers,\r\n // lists, and tables. That's because we still want to wrap s around\r\n // \"paragraphs\" that are wrapped in non-block-level tags, such as anchors,\r\n // phrase emphasis, and spans. The list of tags we're looking for is\r\n // hard-coded:\r\n var block_tags_a = \"p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del|style|section|header|footer|nav|article|aside\";\r\n var block_tags_b = \"p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside\";\r\n\r\n // First, look for nested blocks, e.g.:\r\n //
\r\n //
\r\n // tags for inner block must be indented.\r\n //
\r\n //
\r\n //\r\n // The outermost tags must start at the left margin for this to match, and\r\n // the inner nested divs must be indented.\r\n // We need to do this before the next, more liberal match, because the next\r\n // match will start at the first `` and stop at the first `
`.\r\n\r\n // attacklab: This regex can be expensive when it fails.\r\n /*\r\n var text = text.replace(/\r\n (\t\t\t\t\t\t// save in $1\r\n ^\t\t\t\t\t// start of line (with /m)\r\n <($block_tags_a)\t// start tag = $2\r\n \\b\t\t\t\t\t// word break\r\n // attacklab: hack around khtml/pcre bug...\r\n [^\\r]*?\\n\t\t\t// any number of lines, minimally matching\r\n \\2>\t\t\t\t// the matching end tag\r\n [ \\t]*\t\t\t\t// trailing spaces/tabs\r\n (?=\\n+)\t\t\t\t// followed by a newline\r\n )\t\t\t\t\t\t// attacklab: there are sentinel newlines at end of document\r\n /gm,function(){...}};\r\n */\r\n 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);\r\n\r\n //\r\n // Now match more liberally, simply from `\\n` to `\\n`\r\n //\r\n\r\n /*\r\n var text = text.replace(/\r\n (\t\t\t\t\t\t// save in $1\r\n ^\t\t\t\t\t// start of line (with /m)\r\n <($block_tags_b)\t// start tag = $2\r\n \\b\t\t\t\t\t// word break\r\n // attacklab: hack around khtml/pcre bug...\r\n [^\\r]*?\t\t\t\t// any number of lines, minimally matching\r\n \\2>\t\t\t\t// the matching end tag\r\n [ \\t]*\t\t\t\t// trailing spaces/tabs\r\n (?=\\n+)\t\t\t\t// followed by a newline\r\n )\t\t\t\t\t\t// attacklab: there are sentinel newlines at end of document\r\n /gm,function(){...}};\r\n */\r\n text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|style|section|header|footer|nav|article|aside)\\b[^\\r]*?<\\/\\2>[ \\t]*(?=\\n+)\\n)/gm, hashElement);\r\n\r\n // Special case just for
. It was easier to make a special case than\r\n // to make the other regex more complicated.\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t// save in $1\r\n \\n\\n\t\t\t\t// Starting after a blank line\r\n [ ]{0,3}\r\n (<(hr)\t\t\t\t// start tag = $2\r\n \\b\t\t\t\t\t// word break\r\n ([^<>])*?\t\t\t//\r\n \\/?>)\t\t\t\t// the matching end tag\r\n [ \\t]*\r\n (?=\\n{2,})\t\t\t// followed by a blank line\r\n )\r\n /g,hashElement);\r\n */\r\n text = text.replace(/(\\n[ ]{0,3}(<(hr)\\b([^<>])*?\\/?>)[ \\t]*(?=\\n{2,}))/g, hashElement);\r\n\r\n // Special case for standalone HTML comments:\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t// save in $1\r\n \\n\\n\t\t\t\t// Starting after a blank line\r\n [ ]{0,3}\t\t\t// attacklab: g_tab_width - 1\r\n \r\n [ \\t]*\r\n (?=\\n{2,})\t\t\t// followed by a blank line\r\n )\r\n /g,hashElement);\r\n */\r\n text = text.replace(/(\\n\\n[ ]{0,3}[ \\t]*(?=\\n{2,}))/g, hashElement);\r\n\r\n // PHP and ASP-style processor instructions (...?> and <%...%>)\r\n\r\n /*\r\n text = text.replace(/\r\n (?:\r\n \\n\\n\t\t\t\t// Starting after a blank line\r\n )\r\n (\t\t\t\t\t\t// save in $1\r\n [ ]{0,3}\t\t\t// attacklab: g_tab_width - 1\r\n (?:\r\n <([?%])\t\t\t// $2\r\n [^\\r]*?\r\n \\2>\r\n )\r\n [ \\t]*\r\n (?=\\n{2,})\t\t\t// followed by a blank line\r\n )\r\n /g,hashElement);\r\n */\r\n text = text.replace(/(?:\\n\\n)([ ]{0,3}(?:<([?%])[^\\r]*?\\2>)[ \\t]*(?=\\n{2,}))/g, hashElement);\r\n\r\n // attacklab: Undo double lines (see comment at top of this function)\r\n text = text.replace(/\\n\\n/g, \"\\n\");\r\n return text;\r\n }\r\n\r\n var hashElement = function (wholeMatch, m1) {\r\n var blockText = m1;\r\n\r\n // Undo double lines\r\n blockText = blockText.replace(/\\n\\n/g, \"\\n\");\r\n blockText = blockText.replace(/^\\n/, \"\");\r\n\r\n // strip trailing blank lines\r\n blockText = blockText.replace(/\\n+$/g, \"\");\r\n\r\n // Replace the element text with a marker (\"~KxK\" where x is its key)\r\n blockText = \"\\n\\n~K\" + (g_html_blocks.push(blockText) - 1) + \"K\\n\\n\";\r\n\r\n return blockText;\r\n };\r\n\r\n var _RunBlockGamut = function (text) {\r\n//\r\n// These are all the transformations that form block-level\r\n// tags like paragraphs, headers, and list items.\r\n//\r\n text = _DoHeaders(text);\r\n\r\n // Do Horizontal Rules:\r\n var key = hashBlock(\"
\");\r\n text = text.replace(/^[ ]{0,2}([ ]?\\*[ ]?){3,}[ \\t]*$/gm, key);\r\n text = text.replace(/^[ ]{0,2}([ ]?\\-[ ]?){3,}[ \\t]*$/gm, key);\r\n text = text.replace(/^[ ]{0,2}([ ]?\\_[ ]?){3,}[ \\t]*$/gm, key);\r\n\r\n text = _DoLists(text);\r\n text = _DoCodeBlocks(text);\r\n text = _DoBlockQuotes(text);\r\n\r\n // We already ran _HashHTMLBlocks() before, in Markdown(), but that\r\n // was to escape raw HTML in the original Markdown source. This time,\r\n // we're escaping the markup we've just created, so that we don't wrap\r\n // tags around block-level tags.\r\n text = _HashHTMLBlocks(text);\r\n text = _FormParagraphs(text);\r\n\r\n return text;\r\n };\r\n\r\n var _RunSpanGamut = function (text) {\r\n//\r\n// These are all the transformations that occur *within* block-level\r\n// tags like paragraphs, headers, and list items.\r\n//\r\n\r\n text = _DoCodeSpans(text);\r\n text = _EscapeSpecialCharsWithinTagAttributes(text);\r\n text = _EncodeBackslashEscapes(text);\r\n\r\n // Process anchor and image tags. Images must come first,\r\n // because ![foo][f] looks like an anchor.\r\n text = _DoImages(text);\r\n text = _DoAnchors(text);\r\n\r\n // Make links out of things like ``\r\n // Must come after _DoAnchors(), because you can use < and >\r\n // delimiters in inline links like [this]().\r\n text = _DoAutoLinks(text);\r\n text = _EncodeAmpsAndAngles(text);\r\n text = _DoItalicsAndBold(text);\r\n\r\n // Do hard breaks:\r\n text = text.replace(/ +\\n/g, \"
\\n\");\r\n\r\n return text;\r\n }\r\n\r\n var _EscapeSpecialCharsWithinTagAttributes = function (text) {\r\n//\r\n// Within tags -- meaning between < and > -- encode [\\ ` * _] so they\r\n// don't conflict with their use in Markdown for code, italics and strong.\r\n//\r\n\r\n // Build a regex to find HTML tags and comments. See Friedl's\r\n // \"Mastering Regular Expressions\", 2nd Ed., pp. 200-201.\r\n var regex = /(<[a-z\\/!$](\"[^\"]*\"|'[^']*'|[^'\">])*>|)/gi;\r\n\r\n text = text.replace(regex, function (wholeMatch) {\r\n var tag = wholeMatch.replace(/(.)<\\/?code>(?=.)/g, \"$1`\");\r\n tag = escapeCharacters(tag, \"\\\\`*_\");\r\n return tag;\r\n });\r\n\r\n return text;\r\n }\r\n\r\n var _DoAnchors = function (text) {\r\n//\r\n// Turn Markdown link shortcuts into XHTML tags.\r\n//\r\n //\r\n // First, handle reference-style links: [link text] [id]\r\n //\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t\t// wrap whole match in $1\r\n \\[\r\n (\r\n (?:\r\n \\[[^\\]]*\\]\t\t// allow brackets nested one level\r\n |\r\n [^\\[]\t\t\t// or anything else\r\n )*\r\n )\r\n \\]\r\n\r\n [ ]?\t\t\t\t\t// one optional space\r\n (?:\\n[ ]*)?\t\t\t\t// one optional newline followed by spaces\r\n\r\n \\[\r\n (.*?)\t\t\t\t\t// id = $3\r\n \\]\r\n )()()()()\t\t\t\t\t// pad remaining backreferences\r\n /g,_DoAnchors_callback);\r\n */\r\n text = text.replace(/(\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\])()()()()/g, writeAnchorTag);\r\n\r\n //\r\n // Next, inline-style links: [link text](url \"optional title\")\r\n //\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t// wrap whole match in $1\r\n \\[\r\n (\r\n (?:\r\n \\[[^\\]]*\\]\t// allow brackets nested one level\r\n |\r\n [^\\[\\]]\t\t\t// or anything else\r\n )\r\n )\r\n \\]\r\n \\(\t\t\t\t\t\t// literal paren\r\n [ \\t]*\r\n ()\t\t\t\t\t\t// no id, so leave $3 empty\r\n (.*?)>?\t\t\t\t// href = $4\r\n [ \\t]*\r\n (\t\t\t\t\t\t// $5\r\n (['\"])\t\t\t\t// quote char = $6\r\n (.*?)\t\t\t\t// Title = $7\r\n \\6\t\t\t\t\t// matching quote\r\n [ \\t]*\t\t\t\t// ignore any spaces/tabs between closing quote and )\r\n )?\t\t\t\t\t\t// title is optional\r\n \\)\r\n )\r\n /g,writeAnchorTag);\r\n */\r\n text = text.replace(/(\\[((?:\\[[^\\]]*\\]|[^\\[\\]])*)\\]\\([ \\t]*()(.*?(?:\\(.*?\\).*?)?)>?[ \\t]*((['\"])(.*?)\\6[ \\t]*)?\\))/g, writeAnchorTag);\r\n\r\n //\r\n // Last, handle reference-style shortcuts: [link text]\r\n // These must come last in case you've also got [link test][1]\r\n // or [link test](/foo)\r\n //\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t \t\t\t\t\t// wrap whole match in $1\r\n \\[\r\n ([^\\[\\]]+)\t\t\t\t// link text = $2; can't contain '[' or ']'\r\n \\]\r\n )()()()()()\t\t\t\t\t// pad rest of backreferences\r\n /g, writeAnchorTag);\r\n */\r\n text = text.replace(/(\\[([^\\[\\]]+)\\])()()()()()/g, writeAnchorTag);\r\n\r\n return text;\r\n }\r\n\r\n var writeAnchorTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {\r\n if (m7 == undefined) m7 = \"\";\r\n var whole_match = m1;\r\n var link_text = m2;\r\n var link_id = m3.toLowerCase();\r\n var url = m4;\r\n var title = m7;\r\n\r\n if (url == \"\") {\r\n if (link_id == \"\") {\r\n // lower-case and turn embedded newlines into spaces\r\n link_id = link_text.toLowerCase().replace(/ ?\\n/g, \" \");\r\n }\r\n url = \"#\" + link_id;\r\n\r\n if (g_urls[link_id] != undefined) {\r\n url = g_urls[link_id];\r\n if (g_titles[link_id] != undefined) {\r\n title = g_titles[link_id];\r\n }\r\n }\r\n else {\r\n if (whole_match.search(/\\(\\s*\\)$/m) > -1) {\r\n // Special case for explicit empty url\r\n url = \"\";\r\n } else {\r\n return whole_match;\r\n }\r\n }\r\n }\r\n\r\n url = escapeCharacters(url, \"*_\");\r\n var result = \"\" + link_text + \"\";\r\n\r\n return result;\r\n }\r\n\r\n var _DoImages = function (text) {\r\n//\r\n// Turn Markdown image shortcuts into tags.\r\n//\r\n\r\n //\r\n // First, handle reference-style labeled images: ![alt text][id]\r\n //\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t// wrap whole match in $1\r\n !\\[\r\n (.*?)\t\t\t\t// alt text = $2\r\n \\]\r\n\r\n [ ]?\t\t\t\t// one optional space\r\n (?:\\n[ ]*)?\t\t\t// one optional newline followed by spaces\r\n\r\n \\[\r\n (.*?)\t\t\t\t// id = $3\r\n \\]\r\n )()()()()\t\t\t\t// pad rest of backreferences\r\n /g,writeImageTag);\r\n */\r\n text = text.replace(/(!\\[(.*?)\\][ ]?(?:\\n[ ]*)?\\[(.*?)\\])()()()()/g, writeImageTag);\r\n\r\n //\r\n // Next, handle inline images: ![alt text](url \"optional title\")\r\n // Don't forget: encode * and _\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t// wrap whole match in $1\r\n !\\[\r\n (.*?)\t\t\t\t// alt text = $2\r\n \\]\r\n \\s?\t\t\t\t\t// One optional whitespace character\r\n \\(\t\t\t\t\t// literal paren\r\n [ \\t]*\r\n ()\t\t\t\t\t// no id, so leave $3 empty\r\n (\\S+?)>?\t\t\t// src url = $4\r\n [ \\t]*\r\n (\t\t\t\t\t// $5\r\n (['\"])\t\t\t// quote char = $6\r\n (.*?)\t\t\t// title = $7\r\n \\6\t\t\t\t// matching quote\r\n [ \\t]*\r\n )?\t\t\t\t\t// title is optional\r\n \\)\r\n )\r\n /g,writeImageTag);\r\n */\r\n text = text.replace(/(!\\[(.*?)\\]\\s?\\([ \\t]*()(\\S+?)>?[ \\t]*((['\"])(.*?)\\6[ \\t]*)?\\))/g, writeImageTag);\r\n\r\n return text;\r\n }\r\n\r\n var writeImageTag = function (wholeMatch, m1, m2, m3, m4, m5, m6, m7) {\r\n var whole_match = m1;\r\n var alt_text = m2;\r\n var link_id = m3.toLowerCase();\r\n var url = m4;\r\n var title = m7;\r\n\r\n if (!title) title = \"\";\r\n\r\n if (url == \"\") {\r\n if (link_id == \"\") {\r\n // lower-case and turn embedded newlines into spaces\r\n link_id = alt_text.toLowerCase().replace(/ ?\\n/g, \" \");\r\n }\r\n url = \"#\" + link_id;\r\n\r\n if (g_urls[link_id] != undefined) {\r\n url = g_urls[link_id];\r\n if (g_titles[link_id] != undefined) {\r\n title = g_titles[link_id];\r\n }\r\n }\r\n else {\r\n return whole_match;\r\n }\r\n }\r\n\r\n alt_text = alt_text.replace(/\"/g, \""\");\r\n url = escapeCharacters(url, \"*_\");\r\n var result = \"\";\r\n\r\n return result;\r\n }\r\n\r\n var _DoHeaders = function (text) {\r\n\r\n // Setext-style headers:\r\n //\tHeader 1\r\n //\t========\r\n //\r\n //\tHeader 2\r\n //\t--------\r\n //\r\n text = text.replace(/^(.+)[ \\t]*\\n=+[ \\t]*\\n+/gm,\r\n function (wholeMatch, m1) {\r\n return hashBlock('' + _RunSpanGamut(m1) + \"
\");\r\n });\r\n\r\n text = text.replace(/^(.+)[ \\t]*\\n-+[ \\t]*\\n+/gm,\r\n function (matchFound, m1) {\r\n return hashBlock('' + _RunSpanGamut(m1) + \"
\");\r\n });\r\n\r\n // atx-style headers:\r\n // # Header 1\r\n // ## Header 2\r\n // ## Header 2 with closing hashes ##\r\n // ...\r\n // ###### Header 6\r\n //\r\n\r\n /*\r\n text = text.replace(/\r\n ^(\\#{1,6})\t\t\t\t// $1 = string of #'s\r\n [ \\t]*\r\n (.+?)\t\t\t\t\t// $2 = Header text\r\n [ \\t]*\r\n \\#*\t\t\t\t\t\t// optional closing #'s (not counted)\r\n \\n+\r\n /gm, function() {...});\r\n */\r\n\r\n text = text.replace(/^(\\#{1,6})[ \\t]*(.+?)[ \\t]*\\#*\\n+/gm,\r\n function (wholeMatch, m1, m2) {\r\n var h_level = m1.length;\r\n return hashBlock(\"' + _RunSpanGamut(m2) + \"\");\r\n });\r\n\r\n function headerId(m) {\r\n return m.replace(/[^\\w]/g, '').toLowerCase();\r\n }\r\n\r\n return text;\r\n }\r\n\r\n// This declaration keeps Dojo compressor from outputting garbage:\r\n var _ProcessListItems;\r\n\r\n var _DoLists = function (text) {\r\n//\r\n// Form HTML ordered (numbered) and unordered (bulleted) lists.\r\n//\r\n\r\n // attacklab: add sentinel to hack around khtml/safari bug:\r\n // http://bugs.webkit.org/show_bug.cgi?id=11231\r\n text += \"~0\";\r\n\r\n // Re-usable pattern to match any entirel ul or ol list:\r\n\r\n /*\r\n var whole_list = /\r\n (\t\t\t\t\t\t\t\t\t// $1 = whole list\r\n (\t\t\t\t\t\t\t\t// $2\r\n [ ]{0,3}\t\t\t\t\t// attacklab: g_tab_width - 1\r\n ([*+-]|\\d+[.])\t\t\t\t// $3 = first list item marker\r\n [ \\t]+\r\n )\r\n [^\\r]+?\r\n (\t\t\t\t\t\t\t\t// $4\r\n ~0\t\t\t\t\t\t\t// sentinel for workaround; should be $\r\n |\r\n \\n{2,}\r\n (?=\\S)\r\n (?!\t\t\t\t\t\t\t// Negative lookahead for another list item marker\r\n [ \\t]*\r\n (?:[*+-]|\\d+[.])[ \\t]+\r\n )\r\n )\r\n )/g\r\n */\r\n var whole_list = /^(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/gm;\r\n\r\n if (g_list_level) {\r\n text = text.replace(whole_list, function (wholeMatch, m1, m2) {\r\n var list = m1;\r\n var list_type = (m2.search(/[*+-]/g) > -1) ? \"ul\" : \"ol\";\r\n\r\n // Turn double returns into triple returns, so that we can make a\r\n // paragraph for the last item in a list, if necessary:\r\n list = list.replace(/\\n{2,}/g, \"\\n\\n\\n\");\r\n ;\r\n var result = _ProcessListItems(list);\r\n\r\n // Trim any trailing whitespace, to put the closing `$list_type>`\r\n // up on the preceding line, to get it past the current stupid\r\n // HTML block parser. This is a hack to work around the terrible\r\n // hack that is the HTML block parser.\r\n result = result.replace(/\\s+$/, \"\");\r\n result = \"<\" + list_type + \">\" + result + \"\" + list_type + \">\\n\";\r\n return result;\r\n });\r\n } else {\r\n whole_list = /(\\n\\n|^\\n?)(([ ]{0,3}([*+-]|\\d+[.])[ \\t]+)[^\\r]+?(~0|\\n{2,}(?=\\S)(?![ \\t]*(?:[*+-]|\\d+[.])[ \\t]+)))/g;\r\n text = text.replace(whole_list, function (wholeMatch, m1, m2, m3) {\r\n var runup = m1;\r\n var list = m2;\r\n\r\n var list_type = (m3.search(/[*+-]/g) > -1) ? \"ul\" : \"ol\";\r\n // Turn double returns into triple returns, so that we can make a\r\n // paragraph for the last item in a list, if necessary:\r\n var list = list.replace(/\\n{2,}/g, \"\\n\\n\\n\");\r\n ;\r\n var result = _ProcessListItems(list);\r\n result = runup + \"<\" + list_type + \">\\n\" + result + \"\" + list_type + \">\\n\";\r\n return result;\r\n });\r\n }\r\n\r\n // attacklab: strip sentinel\r\n text = text.replace(/~0/, \"\");\r\n\r\n return text;\r\n }\r\n\r\n _ProcessListItems = function (list_str) {\r\n//\r\n// Process the contents of a single ordered or unordered list, splitting it\r\n// into individual list items.\r\n//\r\n // The $g_list_level global keeps track of when we're inside a list.\r\n // Each time we enter a list, we increment it; when we leave a list,\r\n // we decrement. If it's zero, we're not in a list anymore.\r\n //\r\n // We do this because when we're not inside a list, we want to treat\r\n // something like this:\r\n //\r\n // I recommend upgrading to version\r\n // 8. Oops, now this line is treated\r\n // as a sub-list.\r\n //\r\n // As a single paragraph, despite the fact that the second line starts\r\n // with a digit-period-space sequence.\r\n //\r\n // Whereas when we're inside a list (or sub-list), that line will be\r\n // treated as the start of a sub-list. What a kludge, huh? This is\r\n // an aspect of Markdown's syntax that's hard to parse perfectly\r\n // without resorting to mind-reading. Perhaps the solution is to\r\n // change the syntax rules such that sub-lists must start with a\r\n // starting cardinal number; e.g. \"1.\" or \"a.\".\r\n\r\n g_list_level++;\r\n\r\n // trim trailing blank lines:\r\n list_str = list_str.replace(/\\n{2,}$/, \"\\n\");\r\n\r\n // attacklab: add sentinel to emulate \\z\r\n list_str += \"~0\";\r\n\r\n /*\r\n list_str = list_str.replace(/\r\n (\\n)?\t\t\t\t\t\t\t// leading line = $1\r\n (^[ \\t]*)\t\t\t\t\t\t// leading whitespace = $2\r\n ([*+-]|\\d+[.]) [ \\t]+\t\t\t// list marker = $3\r\n ([^\\r]+?\t\t\t\t\t\t// list item text = $4\r\n (\\n{1,2}))\r\n (?= \\n* (~0 | \\2 ([*+-]|\\d+[.]) [ \\t]+))\r\n /gm, function(){...});\r\n */\r\n list_str = list_str.replace(/(\\n)?(^[ \\t]*)([*+-]|\\d+[.])[ \\t]+([^\\r]+?(\\n{1,2}))(?=\\n*(~0|\\2([*+-]|\\d+[.])[ \\t]+))/gm,\r\n function (wholeMatch, m1, m2, m3, m4) {\r\n var item = m4;\r\n var leading_line = m1;\r\n var leading_space = m2;\r\n\r\n if (leading_line || (item.search(/\\n{2,}/) > -1)) {\r\n item = _RunBlockGamut(_Outdent(item));\r\n }\r\n else {\r\n // Recursion for sub-lists:\r\n item = _DoLists(_Outdent(item));\r\n item = item.replace(/\\n$/, \"\"); // chomp(item)\r\n item = _RunSpanGamut(item);\r\n }\r\n\r\n return \"\" + item + \"\\n\";\r\n }\r\n );\r\n\r\n // attacklab: strip sentinel\r\n list_str = list_str.replace(/~0/g, \"\");\r\n\r\n g_list_level--;\r\n return list_str;\r\n }\r\n\r\n var _DoCodeBlocks = function (text) {\r\n//\r\n// Process Markdown `` blocks.\r\n//\r\n\r\n /*\r\n text = text.replace(text,\r\n /(?:\\n\\n|^)\r\n (\t\t\t\t\t\t\t\t// $1 = the code block -- one or more lines, starting with a space/tab\r\n (?:\r\n (?:[ ]{4}|\\t)\t\t\t// Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width\r\n .*\\n+\r\n )+\r\n )\r\n (\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))\t// attacklab: g_tab_width\r\n /g,function(){...});\r\n */\r\n\r\n // attacklab: sentinel workarounds for lack of \\A and \\Z, safari\\khtml bug\r\n text += \"~0\";\r\n\r\n text = text.replace(/(?:\\n\\n|^)((?:(?:[ ]{4}|\\t).*\\n+)+)(\\n*[ ]{0,3}[^ \\t\\n]|(?=~0))/g,\r\n function (wholeMatch, m1, m2) {\r\n var codeblock = m1;\r\n var nextChar = m2;\r\n\r\n codeblock = _EncodeCode(_Outdent(codeblock));\r\n codeblock = _Detab(codeblock);\r\n codeblock = codeblock.replace(/^\\n+/g, \"\"); // trim leading newlines\r\n codeblock = codeblock.replace(/\\n+$/g, \"\"); // trim trailing whitespace\r\n\r\n codeblock = \"\" + codeblock + \"\\n
\";\r\n\r\n return hashBlock(codeblock) + nextChar;\r\n }\r\n );\r\n\r\n // attacklab: strip sentinel\r\n text = text.replace(/~0/, \"\");\r\n\r\n return text;\r\n };\r\n\r\n var _DoGithubCodeBlocks = function (text) {\r\n//\r\n// Process Github-style code blocks\r\n// Example:\r\n// ```ruby\r\n// def hello_world(x)\r\n// puts \"Hello, #{x}\"\r\n// end\r\n// ```\r\n//\r\n\r\n\r\n // attacklab: sentinel workarounds for lack of \\A and \\Z, safari\\khtml bug\r\n text += \"~0\";\r\n\r\n text = text.replace(/(?:^|\\n)```(.*)\\n([\\s\\S]*?)\\n```/g,\r\n function (wholeMatch, m1, m2) {\r\n var language = m1;\r\n var codeblock = m2;\r\n\r\n codeblock = _EncodeCode(codeblock);\r\n codeblock = _Detab(codeblock);\r\n codeblock = codeblock.replace(/^\\n+/g, \"\"); // trim leading newlines\r\n codeblock = codeblock.replace(/\\n+$/g, \"\"); // trim trailing whitespace\r\n\r\n codeblock = \"\" + codeblock + \"\\n
\";\r\n\r\n return hashBlock(codeblock);\r\n }\r\n );\r\n\r\n // attacklab: strip sentinel\r\n text = text.replace(/~0/, \"\");\r\n\r\n return text;\r\n }\r\n\r\n var hashBlock = function (text) {\r\n text = text.replace(/(^\\n+|\\n+$)/g, \"\");\r\n return \"\\n\\n~K\" + (g_html_blocks.push(text) - 1) + \"K\\n\\n\";\r\n }\r\n\r\n var _DoCodeSpans = function (text) {\r\n//\r\n// * Backtick quotes are used for
spans.\r\n//\r\n// * You can use multiple backticks as the delimiters if you want to\r\n//\t include literal backticks in the code span. So, this input:\r\n//\r\n//\t\t Just type ``foo `bar` baz`` at the prompt.\r\n//\r\n//\t Will translate to:\r\n//\r\n//\t\t Just type foo `bar` baz
at the prompt.
\r\n//\r\n//\tThere's no arbitrary limit to the number of backticks you\r\n//\tcan use as delimters. If you need three consecutive backticks\r\n//\tin your code, use four for delimiters, etc.\r\n//\r\n// * You can use spaces to get literal backticks at the edges:\r\n//\r\n//\t\t ... type `` `bar` `` ...\r\n//\r\n//\t Turns to:\r\n//\r\n//\t\t ... type `bar`
...\r\n//\r\n\r\n /*\r\n text = text.replace(/\r\n (^|[^\\\\])\t\t\t\t\t// Character before opening ` can't be a backslash\r\n (`+)\t\t\t\t\t\t// $2 = Opening run of `\r\n (\t\t\t\t\t\t\t// $3 = The code block\r\n [^\\r]*?\r\n [^`]\t\t\t\t\t// attacklab: work around lack of lookbehind\r\n )\r\n \\2\t\t\t\t\t\t\t// Matching closer\r\n (?!`)\r\n /gm, function(){...});\r\n */\r\n\r\n text = text.replace(/(^|[^\\\\])(`+)([^\\r]*?[^`])\\2(?!`)/gm,\r\n function (wholeMatch, m1, m2, m3, m4) {\r\n var c = m3;\r\n c = c.replace(/^([ \\t]*)/g, \"\");\t// leading whitespace\r\n c = c.replace(/[ \\t]*$/g, \"\");\t// trailing whitespace\r\n c = _EncodeCode(c);\r\n return m1 + \"\" + c + \"
\";\r\n });\r\n\r\n return text;\r\n }\r\n\r\n var _EncodeCode = function (text) {\r\n//\r\n// Encode/escape certain characters inside Markdown code runs.\r\n// The point is that in code, these characters are literals,\r\n// and lose their special Markdown meanings.\r\n//\r\n // Encode all ampersands; HTML entities are not\r\n // entities within a Markdown code span.\r\n text = text.replace(/&/g, \"&\");\r\n\r\n // Do the angle bracket song and dance:\r\n text = text.replace(//g, \">\");\r\n\r\n // Now, escape characters that are magic in Markdown:\r\n text = escapeCharacters(text, \"\\*_{}[]\\\\\", false);\r\n\r\n// jj the line above breaks this:\r\n//---\r\n\r\n//* Item\r\n\r\n// 1. Subitem\r\n\r\n// special char: *\r\n//---\r\n\r\n return text;\r\n }\r\n\r\n var _DoItalicsAndBold = function (text) {\r\n\r\n // must go first:\r\n text = text.replace(/(\\*\\*|__)(?=\\S)([^\\r]*?\\S[*_]*)\\1/g,\r\n \"$2\");\r\n\r\n text = text.replace(/(\\*|_)(?=\\S)([^\\r]*?\\S)\\1/g,\r\n \"$2\");\r\n\r\n return text;\r\n }\r\n\r\n var _DoBlockQuotes = function (text) {\r\n\r\n /*\r\n text = text.replace(/\r\n (\t\t\t\t\t\t\t\t// Wrap whole match in $1\r\n (\r\n ^[ \\t]*>[ \\t]?\t\t\t// '>' at the start of a line\r\n .+\\n\t\t\t\t\t// rest of the first line\r\n (.+\\n)*\t\t\t\t\t// subsequent consecutive lines\r\n \\n*\t\t\t\t\t\t// blanks\r\n )+\r\n )\r\n /gm, function(){...});\r\n */\r\n\r\n text = text.replace(/((^[ \\t]*>[ \\t]?.+\\n(.+\\n)*\\n*)+)/gm,\r\n function (wholeMatch, m1) {\r\n var bq = m1;\r\n\r\n // attacklab: hack around Konqueror 3.5.4 bug:\r\n // \"----------bug\".replace(/^-/g,\"\") == \"bug\"\r\n\r\n bq = bq.replace(/^[ \\t]*>[ \\t]?/gm, \"~0\");\t// trim one level of quoting\r\n\r\n // attacklab: clean up hack\r\n bq = bq.replace(/~0/g, \"\");\r\n\r\n bq = bq.replace(/^[ \\t]+$/gm, \"\");\t\t// trim whitespace-only lines\r\n bq = _RunBlockGamut(bq);\t\t\t\t// recurse\r\n\r\n bq = bq.replace(/(^|\\n)/g, \"$1 \");\r\n // These leading spaces screw with content, so we need to fix that:\r\n bq = bq.replace(\r\n /(\\s*[^\\r]+?<\\/pre>)/gm,\r\n function (wholeMatch, m1) {\r\n var pre = m1;\r\n // attacklab: hack around Konqueror 3.5.4 bug:\r\n pre = pre.replace(/^ /mg, \"~0\");\r\n pre = pre.replace(/~0/g, \"\");\r\n return pre;\r\n });\r\n\r\n return hashBlock(\"\\n\" + bq + \"\\n
\");\r\n });\r\n return text;\r\n }\r\n\r\n var _FormParagraphs = function (text) {\r\n//\r\n// Params:\r\n// $text - string to process with html tags\r\n//\r\n\r\n // Strip leading and trailing lines:\r\n text = text.replace(/^\\n+/g, \"\");\r\n text = text.replace(/\\n+$/g, \"\");\r\n\r\n var grafs = text.split(/\\n{2,}/g);\r\n var grafsOut = [];\r\n\r\n //\r\n // Wrap
tags.\r\n //\r\n var end = grafs.length;\r\n for (var i = 0; i < end; i++) {\r\n var str = grafs[i];\r\n\r\n // if this is an HTML marker, copy it\r\n if (str.search(/~K(\\d+)K/g) >= 0) {\r\n grafsOut.push(str);\r\n }\r\n else if (str.search(/\\S/) >= 0) {\r\n str = _RunSpanGamut(str);\r\n str = str.replace(/^([ \\t]*)/g, \"
\");\r\n str += \"
\"\r\n grafsOut.push(str);\r\n }\r\n\r\n }\r\n\r\n //\r\n // Unhashify HTML blocks\r\n //\r\n end = grafsOut.length;\r\n for (var i = 0; i < end; i++) {\r\n // if this is a marker for an html block...\r\n while (grafsOut[i].search(/~K(\\d+)K/) >= 0) {\r\n var blockText = g_html_blocks[RegExp.$1];\r\n blockText = blockText.replace(/\\$/g, \"$$$$\"); // Escape any dollar signs\r\n grafsOut[i] = grafsOut[i].replace(/~K\\d+K/, blockText);\r\n }\r\n }\r\n\r\n return grafsOut.join(\"\\n\\n\");\r\n }\r\n\r\n var _EncodeAmpsAndAngles = function (text) {\r\n// Smart processing for ampersands and angle brackets that need to be encoded.\r\n\r\n // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:\r\n // http://bumppo.net/projects/amputator/\r\n text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\\w+);)/g, \"&\");\r\n\r\n // Encode naked <'s\r\n text = text.replace(/<(?![a-z\\/?\\$!])/gi, \"<\");\r\n\r\n return text;\r\n }\r\n\r\n var _EncodeBackslashEscapes = function (text) {\r\n//\r\n// Parameter: String.\r\n// Returns:\tThe string, with after processing the following backslash\r\n//\t\t\t escape sequences.\r\n//\r\n\r\n // attacklab: The polite way to do this is with the new\r\n // escapeCharacters() function:\r\n //\r\n // \ttext = escapeCharacters(text,\"\\\\\",true);\r\n // \ttext = escapeCharacters(text,\"`*_{}[]()>#+-.!\",true);\r\n //\r\n // ...but we're sidestepping its use of the (slow) RegExp constructor\r\n // as an optimization for Firefox. This function gets called a LOT.\r\n\r\n text = text.replace(/\\\\(\\\\)/g, escapeCharacters_callback);\r\n text = text.replace(/\\\\([`*_{}\\[\\]()>#+-.!])/g, escapeCharacters_callback);\r\n return text;\r\n }\r\n\r\n var _DoAutoLinks = function (text) {\r\n\r\n text = text.replace(/<((https?|ftp|dict):[^'\">\\s]+)>/gi, \"$1\");\r\n\r\n // Email addresses: \r\n\r\n /*\r\n text = text.replace(/\r\n <\r\n (?:mailto:)?\r\n (\r\n [-.\\w]+\r\n \\@\r\n [-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+\r\n )\r\n >\r\n /gi, _DoAutoLinks_callback());\r\n */\r\n text = text.replace(/<(?:mailto:)?([-.\\w]+\\@[-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+)>/gi,\r\n function (wholeMatch, m1) {\r\n return _EncodeEmailAddress(_UnescapeSpecialChars(m1));\r\n }\r\n );\r\n\r\n return text;\r\n }\r\n\r\n var _EncodeEmailAddress = function (addr) {\r\n//\r\n// Input: an email address, e.g. \"foo@example.com\"\r\n//\r\n// Output: the email address as a mailto link, with each character\r\n//\tof the address encoded as either a decimal or hex entity, in\r\n//\tthe hopes of foiling most address harvesting spam bots. E.g.:\r\n//\r\n//\tfoo\r\n//\t @example.com\r\n//\r\n// Based on a filter by Matthew Wickline, posted to the BBEdit-Talk\r\n// mailing list: \r\n//\r\n\r\n var encode = [\r\n function (ch) {\r\n return \"\" + ch.charCodeAt(0) + \";\";\r\n },\r\n function (ch) {\r\n return \"\" + ch.charCodeAt(0).toString(16) + \";\";\r\n },\r\n function (ch) {\r\n return ch;\r\n }\r\n ];\r\n\r\n addr = \"mailto:\" + addr;\r\n\r\n addr = addr.replace(/./g, function (ch) {\r\n if (ch == \"@\") {\r\n // this *must* be encoded. I insist.\r\n ch = encode[Math.floor(Math.random() * 2)](ch);\r\n } else if (ch != \":\") {\r\n // leave ':' alone (to spot mailto: later)\r\n var r = Math.random();\r\n // roughly 10% raw, 45% hex, 45% dec\r\n ch = (\r\n r > .9 ? encode[2](ch) :\r\n r > .45 ? encode[1](ch) :\r\n encode[0](ch)\r\n );\r\n }\r\n return ch;\r\n });\r\n\r\n addr = \"\" + addr + \"\";\r\n addr = addr.replace(/\">.+:/g, \"\\\">\"); // strip the mailto: from the visible part\r\n\r\n return addr;\r\n }\r\n\r\n var _UnescapeSpecialChars = function (text) {\r\n//\r\n// Swap back in all the special characters we've hidden.\r\n//\r\n text = text.replace(/~E(\\d+)E/g,\r\n function (wholeMatch, m1) {\r\n var charCodeToReplace = parseInt(m1);\r\n return String.fromCharCode(charCodeToReplace);\r\n }\r\n );\r\n return text;\r\n }\r\n\r\n var _Outdent = function (text) {\r\n//\r\n// Remove one level of line-leading tabs or spaces\r\n//\r\n\r\n // attacklab: hack around Konqueror 3.5.4 bug:\r\n // \"----------bug\".replace(/^-/g,\"\") == \"bug\"\r\n\r\n text = text.replace(/^(\\t|[ ]{1,4})/gm, \"~0\"); // attacklab: g_tab_width\r\n\r\n // attacklab: clean up hack\r\n text = text.replace(/~0/g, \"\")\r\n\r\n return text;\r\n }\r\n\r\n var _Detab = function (text) {\r\n// attacklab: Detab's completely rewritten for speed.\r\n// In perl we could fix it by anchoring the regexp with \\G.\r\n// In javascript we're less fortunate.\r\n\r\n // expand first n-1 tabs\r\n text = text.replace(/\\t(?=\\t)/g, \" \"); // attacklab: g_tab_width\r\n\r\n // replace the nth with two sentinels\r\n text = text.replace(/\\t/g, \"~A~B\");\r\n\r\n // use the sentinel to anchor our regex so it doesn't explode\r\n text = text.replace(/~B(.+?)~A/g,\r\n function (wholeMatch, m1, m2) {\r\n var leadingText = m1;\r\n var numSpaces = 4 - leadingText.length % 4; // attacklab: g_tab_width\r\n\r\n // there *must* be a better way to do this:\r\n for (var i = 0; i < numSpaces; i++) leadingText += \" \";\r\n\r\n return leadingText;\r\n }\r\n );\r\n\r\n // clean up sentinels\r\n text = text.replace(/~A/g, \" \"); // attacklab: g_tab_width\r\n text = text.replace(/~B/g, \"\");\r\n\r\n return text;\r\n }\r\n\r\n\r\n//\r\n// attacklab: Utility functions\r\n//\r\n\r\n\r\n var escapeCharacters = function (text, charsToEscape, afterBackslash) {\r\n // First we have to escape the escape characters so that\r\n // we can build a character class out of them\r\n var regexString = \"([\" + charsToEscape.replace(/([\\[\\]\\\\])/g, \"\\\\$1\") + \"])\";\r\n\r\n if (afterBackslash) {\r\n regexString = \"\\\\\\\\\" + regexString;\r\n }\r\n\r\n var regex = new RegExp(regexString, \"g\");\r\n text = text.replace(regex, escapeCharacters_callback);\r\n\r\n return text;\r\n }\r\n\r\n\r\n var escapeCharacters_callback = function (wholeMatch, m1) {\r\n var charCodeToEscape = m1.charCodeAt(0);\r\n return \"~E\" + charCodeToEscape + \"E\";\r\n }\r\n\r\n} // end of Showdown.converter\r\n\r\n\r\n// export\r\nif (typeof module !== 'undefined') module.exports = Showdown;\r\n\r\n// stolen from AMD branch of underscore\r\n// AMD define happens at the end for compatibility with AMD loaders\r\n// that don't enforce next-turn semantics on modules.\r\nif (typeof define === 'function' && define.amd) {\r\n define('showdown', function () {\r\n return Showdown;\r\n });\r\n}\r\n","/**\r\n * Created by Tivie on 04-11-2014.\r\n */\r\n\r\n\r\n//Check if AngularJs and Showdown is defined and only load ng-Showdown if both are present\r\nif (typeof angular !== 'undefined' && typeof Showdown !== 'undefined') {\r\n\r\n (function (module, Showdown) {\r\n\r\n module\r\n .provider('$Showdown', provider)\r\n .directive('sdModelToHtml', ['$Showdown', markdownToHtmlDirective])\r\n .filter('sdStripHtml', stripHtmlFilter);\r\n\r\n /**\r\n * Angular Provider\r\n * Enables configuration of showdown via angular.config and Dependency Injection into controllers, views\r\n * directives, etc... This assures the directives and filters provided by the library itself stay consistent\r\n * with the user configurations.\r\n * If the user wants to use a different configuration in a determined context, he can use the \"classic\" Showdown\r\n * object instead.\r\n *\r\n */\r\n function provider() {\r\n\r\n // Configuration parameters for Showdown\r\n var config = {\r\n extensions: [],\r\n stripHtml: true\r\n };\r\n\r\n /**\r\n * Sets a configuration option\r\n *\r\n * @param {string} key Config parameter key\r\n * @param {string} value Config parameter value\r\n */\r\n this.setOption = function (key, value) {\r\n config.key = value;\r\n\r\n return this;\r\n };\r\n\r\n /**\r\n * Gets the value of the configuration parameter specified by key\r\n *\r\n * @param {string} key The config parameter key\r\n * @returns {string|null} Returns the value of the config parameter. (or null if the config parameter is not set)\r\n */\r\n this.getOption = function (key) {\r\n if (config.hasOwnProperty(key)) {\r\n return config.key;\r\n } else {\r\n return null;\r\n }\r\n };\r\n\r\n /**\r\n * Loads a Showdown Extension\r\n *\r\n * @param {string} extensionName The name of the extension to load\r\n */\r\n this.loadExtension = function (extensionName) {\r\n config.extensions.push(extensionName);\r\n\r\n return this;\r\n };\r\n\r\n function SDObject() {\r\n var converter = new Showdown.converter(config);\r\n\r\n /**\r\n * Converts a markdown text into HTML\r\n *\r\n * @param {string} markdown The markdown string to be converted to HTML\r\n * @returns {string} The converted HTML\r\n */\r\n this.makeHtml = function (markdown) {\r\n return converter.makeHtml(markdown);\r\n };\r\n\r\n /**\r\n * Strips a text of it's HTML tags\r\n *\r\n * @param {string} text\r\n * @returns {string}\r\n */\r\n this.stripHtml = function (text) {\r\n return String(text).replace(/<[^>]+>/gm, '');\r\n };\r\n }\r\n\r\n // The object returned by service provider\r\n this.$get = function () {\r\n return new SDObject();\r\n };\r\n }\r\n\r\n /**\r\n * AngularJS Directive to Md to HTML transformation\r\n *\r\n * Usage example:\r\n * \r\n *\r\n * @param $Showdown\r\n * @returns {*}\r\n */\r\n function markdownToHtmlDirective($Showdown) {\r\n\r\n var link = function (scope, element) {\r\n scope.$watch('model', function (newValue) {\r\n var val;\r\n if (typeof newValue === 'string') {\r\n val = $Showdown.makeHtml(newValue);\r\n } else {\r\n val = typeof newValue;\r\n }\r\n element.html(val);\r\n });\r\n };\r\n\r\n return {\r\n restrict: 'A',\r\n link: link,\r\n scope: {\r\n model: '=sdModelToHtml'\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * AngularJS Filter to Strip HTML tags from text\r\n *\r\n * @returns {Function}\r\n */\r\n function stripHtmlFilter() {\r\n return function (text) {\r\n return String(text).replace(/<[^>]+>/gm, '');\r\n };\r\n }\r\n\r\n })(angular.module('Showdown', []), Showdown);\r\n\r\n} else {\r\n\r\n /** TODO Since this library is opt out, maybe we should not throw an error so we can concatenate this\r\n script with the main lib */\r\n // throw new Error(\"ng-showdown was not loaded because one of it's dependencies (AngularJS or Showdown) wasn't met\");\r\n}\r\n"]}