var text = text.replace(/ ^[ ]{0,3}[(.+)]: // id = $1 attacklab: gtabwidth - 1 [ \t]* \n? // maybe one newline [ \t]* (\S+?)>? // url = $2 [ \t]* \n? // maybe one newline [ \t]* (?: (\n) // any lines skipped = $3 attacklab: lookbehind removed ["(] (.+?) // title = $4 [")] [ \t] )? // title is optional (?:\n+|$) /gm, function(){...});
var text = text.replace(/ ( // save in $1 ^ // start of line (with /m) <($blocktagsa) // start tag = $2 \b // word break // attacklab: hack around khtml/pcre bug... [^\r]?\n // any number of lines, minimally matching \2> // the matching end tag [ \t] // trailing spaces/tabs (?=\n+) // followed by a newline ) // attacklab: there are sentinel newlines at end of document /gm,function(){...}};
var text = text.replace(/ ( // save in $1 ^ // start of line (with /m) <($blocktagsb) // start tag = $2 \b // word break // attacklab: hack around khtml/pcre bug... [^\r]? // any number of lines, minimally matching .\2> // the matching end tag [ \t]* // trailing spaces/tabs (?=\n+) // followed by a newline ) // attacklab: there are sentinel newlines at end of document /gm,function(){...}};
text = text.replace(/ ( // save in $1 \n\n // Starting after a blank line [ ]{0,3} (<(hr) // start tag = $2 \b // word break ([^<>])? // \/?>) // the matching end tag [ \t] (?=\n{2,}) // followed by a blank line ) /g,hashElement);
text = text.replace(/ ( // save in $1 \n\n // Starting after a blank line [ ]{0,3} // attacklab: gtabwidth - 1 [ \t]* (?=\n{2,}) // followed by a blank line ) /g,hashElement);
text = text.replace(/ (?: \n\n // Starting after a blank line ) ( // save in $1 [ ]{0,3} // attacklab: gtabwidth - 1 (?: <([?%]) // $2 [^\r]? \2> ) [ \t] (?=\n{2,}) // followed by a blank line ) /g,hashElement);
text = text.replace(/ ( // wrap whole match in $1 [ ( (?: [[^]]] // allow brackets nested one level | [^[] // or anything else ) ) ]
[ ]? // one optional space
(?:\n[ ]*)? // one optional newline followed by spaces
\[
(.*?) // id = $3
\]
)()()()() // pad remaining backreferences /g,DoAnchorscallback);
text = text.replace(/ ( // wrap whole match in $1 [ ( (?: [[^]]] // allow brackets nested one level | [^[]] // or anything else ) ) ] ( // literal paren [ \t] () // no id, so leave $3 empty (.?)>? // href = $4 [ \t] ( // $5 (['"]) // quote char = $6 (.?) // Title = $7 \6 // matching quote [ \t] // ignore any spaces/tabs between closing quote and ) )? // title is optional ) ) /g,writeAnchorTag);
text = text.replace(/ ( // wrap whole match in $1 [ ([^[]]+) // link text = $2; can't contain '[' or ']' ] )()()()()() // pad rest of backreferences /g, writeAnchorTag);
text = text.replace(/ ( // wrap whole match in $1 ![ (.*?) // alt text = $2 ]
[ ]? // one optional space
(?:\n[ ]*)? // one optional newline followed by spaces
\[
(.*?) // id = $3
\]
)()()()() // pad rest of backreferences /g,writeImageTag);
text = text.replace(/ ( // wrap whole match in $1 ![ (.?) // alt text = $2 ] \s? // One optional whitespace character ( // literal paren [ \t] () // no id, so leave $3 empty (\S+?)>? // src url = $4 [ \t]* ( // $5 (['"]) // quote char = $6 (.?) // title = $7 \6 // matching quote [ \t] )? // title is optional ) ) /g,writeImageTag);
text = text.replace(/ ^(#{1,6}) // $1 = string of #'s [ \t]* (.+?) // $2 = Header text [ \t]* #* // optional closing #'s (not counted) \n+ /gm, function() {...});
text = text.replace(/
(^|[^]) // Character before opening can't be a backslash
(+) // $2 = Opening run of
( // $3 = The code block
[^\r]*?
[^] // attacklab: work around lack of lookbehind
)
\2 // Matching closer
(?!`)
/gm, function(){...});
var _DoItalicsAndBold = function( text ) {
// <strong> must go first:
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, "<strong>$2</strong>");
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, "<em>$2</em>");
return text;
}
var _DoBlockQuotes = function( text ) {
/* text = text.replace(/ ( // Wrap whole match in $1 ( ^[ \t]>[ \t]? // '>' at the start of a line .+\n // rest of the first line (.+\n) // subsequent consecutive lines \n* // blanks )+ ) /gm, function(){...});
text = text.replace(/ < (?:mailto:)? ( [-.\w]+ \@ [-a-z0-9]+(.[-a-z0-9]+)*.[a-z]+ ) > /gi, DoAutoLinkscallback());