refactor(subParsers): change name and directory of subparsers

BREAKING CHANGE: makeHtml subparsers names changed, by prepending 'makehtml.' to them.
Example: 'anchors', subparser is now named 'makehtml.anchors'.

Event names were also changed to reflect this.
Example: 'anchors.before' is now named 'makehtml.anchors.before'.

**To migrate:**

If you have a listener extension, replace the old event name with the new one. Example:

Replace this

```js
showdown.extension('myext', function() {
  return [{
    type: 'listener',
    listeners: {
      'anchors.before': function (event, text, converter, options, globals) {
        //... some code
        return text;
      }
  }];
});
```

with this
```js
showdown.extension('myext', function() {
  return [{
    type: 'listener',
    listeners: {
      'makehtml.anchors.before': function (event, text, converter, options, globals) {
        //... some code
        return text;
      }
  }];
});
```
This commit is contained in:
Estevao Soares dos Santos 2017-12-16 18:25:44 +00:00
parent 6dbd3966eb
commit 3db9200d2c
49 changed files with 2143 additions and 2142 deletions

View File

@ -23,8 +23,9 @@ module.exports = function (grunt) {
'src/options.js', 'src/options.js',
'src/showdown.js', 'src/showdown.js',
'src/helpers.js', 'src/helpers.js',
'src/subParsers/makehtml/*.js',
'src/subParsers/makemd/*.js',
'src/converter.js', 'src/converter.js',
'src/subParsers/*.js',
'src/loader.js' 'src/loader.js'
], ],
dest: 'dist/<%= pkg.name %>.js' dest: 'dist/<%= pkg.name %>.js'

3708
dist/showdown.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -298,7 +298,7 @@ showdown.Converter = function (converterOptions) {
text = '\n\n' + text + '\n\n'; text = '\n\n' + text + '\n\n';
// detab // detab
text = showdown.subParser('detab')(text, options, globals); text = showdown.subParser('makehtml.detab')(text, options, globals);
/** /**
* Strip any lines consisting only of spaces and tabs. * Strip any lines consisting only of spaces and tabs.
@ -310,19 +310,19 @@ showdown.Converter = function (converterOptions) {
//run languageExtensions //run languageExtensions
showdown.helper.forEach(langExtensions, function (ext) { showdown.helper.forEach(langExtensions, function (ext) {
text = showdown.subParser('runExtension')(ext, text, options, globals); text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals);
}); });
// run the sub parsers // run the sub parsers
text = showdown.subParser('metadata')(text, options, globals); text = showdown.subParser('makehtml.metadata')(text, options, globals);
text = showdown.subParser('hashPreCodeTags')(text, options, globals); text = showdown.subParser('makehtml.hashPreCodeTags')(text, options, globals);
text = showdown.subParser('githubCodeBlocks')(text, options, globals); text = showdown.subParser('makehtml.githubCodeBlocks')(text, options, globals);
text = showdown.subParser('hashHTMLBlocks')(text, options, globals); text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
text = showdown.subParser('hashCodeTags')(text, options, globals); text = showdown.subParser('makehtml.hashCodeTags')(text, options, globals);
text = showdown.subParser('stripLinkDefinitions')(text, options, globals); text = showdown.subParser('makehtml.stripLinkDefinitions')(text, options, globals);
text = showdown.subParser('blockGamut')(text, options, globals); text = showdown.subParser('makehtml.blockGamut')(text, options, globals);
text = showdown.subParser('unhashHTMLSpans')(text, options, globals); text = showdown.subParser('makehtml.unhashHTMLSpans')(text, options, globals);
text = showdown.subParser('unescapeSpecialChars')(text, options, globals); text = showdown.subParser('makehtml.unescapeSpecialChars')(text, options, globals);
// attacklab: Restore dollar signs // attacklab: Restore dollar signs
text = text.replace(/¨D/g, '$$'); text = text.replace(/¨D/g, '$$');
@ -331,11 +331,11 @@ showdown.Converter = function (converterOptions) {
text = text.replace(/¨T/g, '¨'); text = text.replace(/¨T/g, '¨');
// render a complete html document instead of a partial if the option is enabled // render a complete html document instead of a partial if the option is enabled
text = showdown.subParser('completeHTMLDocument')(text, options, globals); text = showdown.subParser('makehtml.completeHTMLDocument')(text, options, globals);
// Run output modifiers // Run output modifiers
showdown.helper.forEach(outputModifiers, function (ext) { showdown.helper.forEach(outputModifiers, function (ext) {
text = showdown.subParser('runExtension')(ext, text, options, globals); text = showdown.subParser('makehtml.runExtension')(ext, text, options, globals);
}); });
// update metadata // update metadata

View File

@ -1,32 +0,0 @@
/**
* These are all the transformations that form block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('blockGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('blockGamut.before', text, options, globals);
// we parse blockquotes first so that we can have headings and hrs
// inside blockquotes
text = showdown.subParser('blockQuotes')(text, options, globals);
text = showdown.subParser('headers')(text, options, globals);
// Do Horizontal Rules:
text = showdown.subParser('horizontalRule')(text, options, globals);
text = showdown.subParser('lists')(text, options, globals);
text = showdown.subParser('codeBlocks')(text, options, globals);
text = showdown.subParser('tables')(text, options, globals);
// We already ran _HashHTMLBlocks() before, in Markdown(), but that
// was to escape raw HTML in the original Markdown source. This time,
// we're escaping the markup we've just created, so that we don't wrap
// <p> tags around block-level tags.
text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
text = showdown.subParser('paragraphs')(text, options, globals);
text = globals.converter._dispatch('blockGamut.after', text, options, globals);
return text;
});

View File

@ -1,11 +0,0 @@
showdown.subParser('ellipsis', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('ellipsis.before', text, options, globals);
text = text.replace(/\.\.\./g, '…');
text = globals.converter._dispatch('ellipsis.after', text, options, globals);
return text;
});

View File

@ -1,8 +0,0 @@
showdown.subParser('hashBlock', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('hashBlock.before', text, options, globals);
text = text.replace(/(^\n+|\n+$)/g, '');
text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
text = globals.converter._dispatch('hashBlock.after', text, options, globals);
return text;
});

View File

@ -1,15 +0,0 @@
/**
* Turn Markdown link shortcuts into XHTML <a> tags.
*/
showdown.subParser('horizontalRule', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('horizontalRule.before', text, options, globals);
var key = showdown.subParser('hashBlock')('<hr />', options, globals);
text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
text = globals.converter._dispatch('horizontalRule.after', text, options, globals);
return text;
});

View File

@ -1,10 +1,10 @@
/** /**
* Turn Markdown link shortcuts into XHTML <a> tags. * Turn Markdown link shortcuts into XHTML <a> tags.
*/ */
showdown.subParser('anchors', function (text, options, globals) { showdown.subParser('makehtml.anchors', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('anchors.before', text, options, globals); text = globals.converter._dispatch('makehtml.anchors.before', text, options, globals);
var writeAnchorTag = function (wholeMatch, linkText, linkId, url, m5, m6, title) { var writeAnchorTag = function (wholeMatch, linkText, linkId, url, m5, m6, title) {
if (showdown.helper.isUndefined(title)) { if (showdown.helper.isUndefined(title)) {
@ -93,6 +93,6 @@ showdown.subParser('anchors', function (text, options, globals) {
}); });
} }
text = globals.converter._dispatch('anchors.after', text, options, globals); text = globals.converter._dispatch('makehtml.anchors.after', text, options, globals);
return text; return text;
}); });

View File

@ -33,7 +33,7 @@ var simpleURLRegex = /([*~_]+|\b)(((https?|ftp|dict):\/\/|www\.)[^'">\s]+?\.[^'
return function (wholeMatch, b, mail) { return function (wholeMatch, b, mail) {
var href = 'mailto:'; var href = 'mailto:';
b = b || ''; b = b || '';
mail = showdown.subParser('unescapeSpecialChars')(mail, options, globals); mail = showdown.subParser('makehtml.unescapeSpecialChars')(mail, options, globals);
if (options.encodeEmails) { if (options.encodeEmails) {
href = showdown.helper.encodeEmailAddress(href + mail); href = showdown.helper.encodeEmailAddress(href + mail);
mail = showdown.helper.encodeEmailAddress(mail); mail = showdown.helper.encodeEmailAddress(mail);
@ -44,27 +44,27 @@ var simpleURLRegex = /([*~_]+|\b)(((https?|ftp|dict):\/\/|www\.)[^'">\s]+?\.[^'
}; };
}; };
showdown.subParser('autoLinks', function (text, options, globals) { showdown.subParser('makehtml.autoLinks', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('autoLinks.before', text, options, globals); text = globals.converter._dispatch('makehtml.autoLinks.before', text, options, globals);
text = text.replace(delimUrlRegex, replaceLink(options)); text = text.replace(delimUrlRegex, replaceLink(options));
text = text.replace(delimMailRegex, replaceMail(options, globals)); text = text.replace(delimMailRegex, replaceMail(options, globals));
text = globals.converter._dispatch('autoLinks.after', text, options, globals); text = globals.converter._dispatch('makehtml.autoLinks.after', text, options, globals);
return text; return text;
}); });
showdown.subParser('simplifiedAutoLinks', function (text, options, globals) { showdown.subParser('makehtml.simplifiedAutoLinks', function (text, options, globals) {
'use strict'; 'use strict';
if (!options.simplifiedAutoLink) { if (!options.simplifiedAutoLink) {
return text; return text;
} }
text = globals.converter._dispatch('simplifiedAutoLinks.before', text, options, globals); text = globals.converter._dispatch('makehtml.simplifiedAutoLinks.before', text, options, globals);
if (options.excludeTrailingPunctuationFromURLs) { if (options.excludeTrailingPunctuationFromURLs) {
text = text.replace(simpleURLRegex2, replaceLink(options)); text = text.replace(simpleURLRegex2, replaceLink(options));
@ -73,7 +73,7 @@ showdown.subParser('simplifiedAutoLinks', function (text, options, globals) {
} }
text = text.replace(simpleMailRegex, replaceMail(options, globals)); text = text.replace(simpleMailRegex, replaceMail(options, globals));
text = globals.converter._dispatch('simplifiedAutoLinks.after', text, options, globals); text = globals.converter._dispatch('makehtml.simplifiedAutoLinks.after', text, options, globals);
return text; return text;
}); });

View File

@ -0,0 +1,32 @@
/**
* These are all the transformations that form block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('makehtml.blockGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.blockGamut.before', text, options, globals);
// we parse blockquotes first so that we can have headings and hrs
// inside blockquotes
text = showdown.subParser('makehtml.blockQuotes')(text, options, globals);
text = showdown.subParser('makehtml.headers')(text, options, globals);
// Do Horizontal Rules:
text = showdown.subParser('makehtml.horizontalRule')(text, options, globals);
text = showdown.subParser('makehtml.lists')(text, options, globals);
text = showdown.subParser('makehtml.codeBlocks')(text, options, globals);
text = showdown.subParser('makehtml.tables')(text, options, globals);
// We already ran _HashHTMLBlocks() before, in Markdown(), but that
// was to escape raw HTML in the original Markdown source. This time,
// we're escaping the markup we've just created, so that we don't wrap
// <p> tags around block-level tags.
text = showdown.subParser('makehtml.hashHTMLBlocks')(text, options, globals);
text = showdown.subParser('makehtml.paragraphs')(text, options, globals);
text = globals.converter._dispatch('makehtml.blockGamut.after', text, options, globals);
return text;
});

View File

@ -1,7 +1,7 @@
showdown.subParser('blockQuotes', function (text, options, globals) { showdown.subParser('makehtml.blockQuotes', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('blockQuotes.before', text, options, globals); text = globals.converter._dispatch('makehtml.blockQuotes.before', text, options, globals);
text = text.replace(/((^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) { text = text.replace(/((^ {0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
var bq = m1; var bq = m1;
@ -14,8 +14,8 @@ showdown.subParser('blockQuotes', function (text, options, globals) {
bq = bq.replace(/¨0/g, ''); bq = bq.replace(/¨0/g, '');
bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
bq = showdown.subParser('githubCodeBlocks')(bq, options, globals); bq = showdown.subParser('makehtml.githubCodeBlocks')(bq, options, globals);
bq = showdown.subParser('blockGamut')(bq, options, globals); // recurse bq = showdown.subParser('makehtml.blockGamut')(bq, options, globals); // recurse
bq = bq.replace(/(^|\n)/g, '$1 '); bq = bq.replace(/(^|\n)/g, '$1 ');
// These leading spaces screw with <pre> content, so we need to fix that: // These leading spaces screw with <pre> content, so we need to fix that:
@ -27,9 +27,9 @@ showdown.subParser('blockQuotes', function (text, options, globals) {
return pre; return pre;
}); });
return showdown.subParser('hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals); return showdown.subParser('makehtml.hashBlock')('<blockquote>\n' + bq + '\n</blockquote>', options, globals);
}); });
text = globals.converter._dispatch('blockQuotes.after', text, options, globals); text = globals.converter._dispatch('makehtml.blockQuotes.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,10 +1,10 @@
/** /**
* Process Markdown `<pre><code>` blocks. * Process Markdown `<pre><code>` blocks.
*/ */
showdown.subParser('codeBlocks', function (text, options, globals) { showdown.subParser('makehtml.codeBlocks', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('codeBlocks.before', text, options, globals); text = globals.converter._dispatch('makehtml.codeBlocks.before', text, options, globals);
// sentinel workarounds for lack of \A and \Z, safari\khtml bug // sentinel workarounds for lack of \A and \Z, safari\khtml bug
text += '¨0'; text += '¨0';
@ -15,9 +15,9 @@ showdown.subParser('codeBlocks', function (text, options, globals) {
nextChar = m2, nextChar = m2,
end = '\n'; end = '\n';
codeblock = showdown.subParser('outdent')(codeblock, options, globals); codeblock = showdown.subParser('makehtml.outdent')(codeblock, options, globals);
codeblock = showdown.subParser('encodeCode')(codeblock, options, globals); codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
codeblock = showdown.subParser('detab')(codeblock, options, globals); codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
@ -27,12 +27,12 @@ showdown.subParser('codeBlocks', function (text, options, globals) {
codeblock = '<pre><code>' + codeblock + end + '</code></pre>'; codeblock = '<pre><code>' + codeblock + end + '</code></pre>';
return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar; return showdown.subParser('makehtml.hashBlock')(codeblock, options, globals) + nextChar;
}); });
// strip sentinel // strip sentinel
text = text.replace(/¨0/, ''); text = text.replace(/¨0/, '');
text = globals.converter._dispatch('codeBlocks.after', text, options, globals); text = globals.converter._dispatch('makehtml.codeBlocks.after', text, options, globals);
return text; return text;
}); });

View File

@ -23,10 +23,10 @@
* *
* ... type <code>`bar`</code> ... * ... type <code>`bar`</code> ...
*/ */
showdown.subParser('codeSpans', function (text, options, globals) { showdown.subParser('makehtml.codeSpans', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('codeSpans.before', text, options, globals); text = globals.converter._dispatch('makehtml.codeSpans.before', text, options, globals);
if (typeof(text) === 'undefined') { if (typeof(text) === 'undefined') {
text = ''; text = '';
@ -36,13 +36,13 @@ showdown.subParser('codeSpans', function (text, options, globals) {
var c = m3; var c = m3;
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
c = showdown.subParser('encodeCode')(c, options, globals); c = showdown.subParser('makehtml.encodeCode')(c, options, globals);
c = m1 + '<code>' + c + '</code>'; c = m1 + '<code>' + c + '</code>';
c = showdown.subParser('hashHTMLSpans')(c, options, globals); c = showdown.subParser('makehtml.hashHTMLSpans')(c, options, globals);
return c; return c;
} }
); );
text = globals.converter._dispatch('codeSpans.after', text, options, globals); text = globals.converter._dispatch('makehtml.codeSpans.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,14 +1,14 @@
/** /**
* Turn Markdown link shortcuts into XHTML <a> tags. * Turn Markdown link shortcuts into XHTML <a> tags.
*/ */
showdown.subParser('completeHTMLDocument', function (text, options, globals) { showdown.subParser('makehtml.completeHTMLDocument', function (text, options, globals) {
'use strict'; 'use strict';
if (!options.completeHTMLDocument) { if (!options.completeHTMLDocument) {
return text; return text;
} }
text = globals.converter._dispatch('completeHTMLDocument.before', text, options, globals); text = globals.converter._dispatch('makehtml.completeHTMLDocument.before', text, options, globals);
var doctype = 'html', var doctype = 'html',
doctypeParsed = '<!DOCTYPE HTML>\n', doctypeParsed = '<!DOCTYPE HTML>\n',
@ -57,6 +57,6 @@ showdown.subParser('completeHTMLDocument', function (text, options, globals) {
text = doctypeParsed + '<html' + lang + '>\n<head>\n' + title + charset + metadata + '</head>\n<body>\n' + text.trim() + '\n</body>\n</html>'; text = doctypeParsed + '<html' + lang + '>\n<head>\n' + title + charset + metadata + '</head>\n<body>\n' + text.trim() + '\n</body>\n</html>';
text = globals.converter._dispatch('completeHTMLDocument.after', text, options, globals); text = globals.converter._dispatch('makehtml.completeHTMLDocument.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,9 +1,9 @@
/** /**
* Convert all tabs to spaces * Convert all tabs to spaces
*/ */
showdown.subParser('detab', function (text, options, globals) { showdown.subParser('makehtml.detab', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('detab.before', text, options, globals); text = globals.converter._dispatch('makehtml.detab.before', text, options, globals);
// expand first n-1 tabs // expand first n-1 tabs
text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
@ -28,6 +28,6 @@ showdown.subParser('detab', function (text, options, globals) {
text = text.replace(/¨A/g, ' '); // g_tab_width text = text.replace(/¨A/g, ' '); // g_tab_width
text = text.replace(/¨B/g, ''); text = text.replace(/¨B/g, '');
text = globals.converter._dispatch('detab.after', text, options, globals); text = globals.converter._dispatch('makehtml.detab.after', text, options, globals);
return text; return text;
}); });

View File

@ -0,0 +1,11 @@
showdown.subParser('makehtml.ellipsis', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.ellipsis.before', text, options, globals);
text = text.replace(/\.\.\./g, '…');
text = globals.converter._dispatch('makehtml.ellipsis.after', text, options, globals);
return text;
});

View File

@ -2,14 +2,14 @@
* These are all the transformations that occur *within* block-level * These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items. * tags like paragraphs, headers, and list items.
*/ */
showdown.subParser('emoji', function (text, options, globals) { showdown.subParser('makehtml.emoji', function (text, options, globals) {
'use strict'; 'use strict';
if (!options.emoji) { if (!options.emoji) {
return text; return text;
} }
text = globals.converter._dispatch('emoji.before', text, options, globals); text = globals.converter._dispatch('makehtml.emoji.before', text, options, globals);
var emojiRgx = /:([\S]+?):/g; var emojiRgx = /:([\S]+?):/g;
@ -20,7 +20,7 @@ showdown.subParser('emoji', function (text, options, globals) {
return wm; return wm;
}); });
text = globals.converter._dispatch('emoji.after', text, options, globals); text = globals.converter._dispatch('makehtml.emoji.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,9 +1,9 @@
/** /**
* Smart processing for ampersands and angle brackets that need to be encoded. * Smart processing for ampersands and angle brackets that need to be encoded.
*/ */
showdown.subParser('encodeAmpsAndAngles', function (text, options, globals) { showdown.subParser('makehtml.encodeAmpsAndAngles', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('encodeAmpsAndAngles.before', text, options, globals); text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.before', text, options, globals);
// Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin: // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
// http://bumppo.net/projects/amputator/ // http://bumppo.net/projects/amputator/
@ -18,6 +18,6 @@ showdown.subParser('encodeAmpsAndAngles', function (text, options, globals) {
// Encode > // Encode >
text = text.replace(/>/g, '&gt;'); text = text.replace(/>/g, '&gt;');
text = globals.converter._dispatch('encodeAmpsAndAngles.after', text, options, globals); text = globals.converter._dispatch('makehtml.encodeAmpsAndAngles.after', text, options, globals);
return text; return text;
}); });

View File

@ -9,13 +9,13 @@
* ...but we're sidestepping its use of the (slow) RegExp constructor * ...but we're sidestepping its use of the (slow) RegExp constructor
* as an optimization for Firefox. This function gets called a LOT. * as an optimization for Firefox. This function gets called a LOT.
*/ */
showdown.subParser('encodeBackslashEscapes', function (text, options, globals) { showdown.subParser('makehtml.encodeBackslashEscapes', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('encodeBackslashEscapes.before', text, options, globals); text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.before', text, options, globals);
text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback); text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
text = text.replace(/\\([`*_{}\[\]()>#+.!~=|-])/g, showdown.helper.escapeCharactersCallback); text = text.replace(/\\([`*_{}\[\]()>#+.!~=|-])/g, showdown.helper.escapeCharactersCallback);
text = globals.converter._dispatch('encodeBackslashEscapes.after', text, options, globals); text = globals.converter._dispatch('makehtml.encodeBackslashEscapes.after', text, options, globals);
return text; return text;
}); });

View File

@ -3,10 +3,10 @@
* The point is that in code, these characters are literals, * The point is that in code, these characters are literals,
* and lose their special Markdown meanings. * and lose their special Markdown meanings.
*/ */
showdown.subParser('encodeCode', function (text, options, globals) { showdown.subParser('makehtml.encodeCode', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('encodeCode.before', text, options, globals); text = globals.converter._dispatch('makehtml.encodeCode.before', text, options, globals);
// Encode all ampersands; HTML entities are not // Encode all ampersands; HTML entities are not
// entities within a Markdown code span. // entities within a Markdown code span.
@ -18,6 +18,6 @@ showdown.subParser('encodeCode', function (text, options, globals) {
// Now, escape characters that are magic in Markdown: // Now, escape characters that are magic in Markdown:
.replace(/([*_{}\[\]\\=~-])/g, showdown.helper.escapeCharactersCallback); .replace(/([*_{}\[\]\\=~-])/g, showdown.helper.escapeCharactersCallback);
text = globals.converter._dispatch('encodeCode.after', text, options, globals); text = globals.converter._dispatch('makehtml.encodeCode.after', text, options, globals);
return text; return text;
}); });

View File

@ -2,9 +2,9 @@
* Within tags -- meaning between < and > -- encode [\ ` * _ ~ =] so they * Within tags -- meaning between < and > -- encode [\ ` * _ ~ =] so they
* don't conflict with their use in Markdown for code, italics and strong. * don't conflict with their use in Markdown for code, italics and strong.
*/ */
showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text, options, globals) { showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('escapeSpecialCharsWithinTagAttributes.before', text, options, globals); text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.before', text, options, globals);
// Build a regex to find HTML tags. // Build a regex to find HTML tags.
var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi, var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi,
@ -21,6 +21,6 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text, opti
.replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback); .replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
}); });
text = globals.converter._dispatch('escapeSpecialCharsWithinTagAttributes.after', text, options, globals); text = globals.converter._dispatch('makehtml.escapeSpecialCharsWithinTagAttributes.after', text, options, globals);
return text; return text;
}); });

View File

@ -8,7 +8,7 @@
* end * end
* ``` * ```
*/ */
showdown.subParser('githubCodeBlocks', function (text, options, globals) { showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals) {
'use strict'; 'use strict';
// early exit if option is not enabled // early exit if option is not enabled
@ -16,7 +16,7 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
return text; return text;
} }
text = globals.converter._dispatch('githubCodeBlocks.before', text, options, globals); text = globals.converter._dispatch('makehtml.githubCodeBlocks.before', text, options, globals);
text += '¨0'; text += '¨0';
@ -24,14 +24,14 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n'; var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
// First parse the github code block // First parse the github code block
codeblock = showdown.subParser('encodeCode')(codeblock, options, globals); codeblock = showdown.subParser('makehtml.encodeCode')(codeblock, options, globals);
codeblock = showdown.subParser('detab')(codeblock, options, globals); codeblock = showdown.subParser('makehtml.detab')(codeblock, options, globals);
codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace
codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>'; codeblock = '<pre><code' + (language ? ' class="' + language + ' language-' + language + '"' : '') + '>' + codeblock + end + '</code></pre>';
codeblock = showdown.subParser('hashBlock')(codeblock, options, globals); codeblock = showdown.subParser('makehtml.hashBlock')(codeblock, options, globals);
// Since GHCodeblocks can be false positives, we need to // Since GHCodeblocks can be false positives, we need to
// store the primitive text and the parsed text in a global var, // store the primitive text and the parsed text in a global var,
@ -42,5 +42,5 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
// attacklab: strip sentinel // attacklab: strip sentinel
text = text.replace(/¨0/, ''); text = text.replace(/¨0/, '');
return globals.converter._dispatch('githubCodeBlocks.after', text, options, globals); return globals.converter._dispatch('makehtml.githubCodeBlocks.after', text, options, globals);
}); });

View File

@ -0,0 +1,8 @@
showdown.subParser('makehtml.hashBlock', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.hashBlock.before', text, options, globals);
text = text.replace(/(^\n+|\n+$)/g, '');
text = '\n\n¨K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
text = globals.converter._dispatch('makehtml.hashBlock.after', text, options, globals);
return text;
});

View File

@ -1,18 +1,18 @@
/** /**
* Hash and escape <code> elements that should not be parsed as markdown * Hash and escape <code> elements that should not be parsed as markdown
*/ */
showdown.subParser('hashCodeTags', function (text, options, globals) { showdown.subParser('makehtml.hashCodeTags', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('hashCodeTags.before', text, options, globals); text = globals.converter._dispatch('makehtml.hashCodeTags.before', text, options, globals);
var repFunc = function (wholeMatch, match, left, right) { var repFunc = function (wholeMatch, match, left, right) {
var codeblock = left + showdown.subParser('encodeCode')(match, options, globals) + right; var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
return '¨C' + (globals.gHtmlSpans.push(codeblock) - 1) + 'C'; return '¨C' + (globals.gHtmlSpans.push(codeblock) - 1) + 'C';
}; };
// Hash naked <code> // Hash naked <code>
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\\b[^>]*>', '</code>', 'gim'); text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\\b[^>]*>', '</code>', 'gim');
text = globals.converter._dispatch('hashCodeTags.after', text, options, globals); text = globals.converter._dispatch('makehtml.hashCodeTags.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,4 +1,4 @@
showdown.subParser('hashElement', function (text, options, globals) { showdown.subParser('makehtml.hashElement', function (text, options, globals) {
'use strict'; 'use strict';
return function (wholeMatch, m1) { return function (wholeMatch, m1) {

View File

@ -1,6 +1,6 @@
showdown.subParser('hashHTMLBlocks', function (text, options, globals) { showdown.subParser('makehtml.hashHTMLBlocks', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('hashHTMLBlocks.before', text, options, globals); text = globals.converter._dispatch('makehtml.hashHTMLBlocks.before', text, options, globals);
var blockTags = [ var blockTags = [
'pre', 'pre',
@ -82,7 +82,7 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
} }
// HR SPECIAL CASE // HR SPECIAL CASE
text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, text = text.replace(/(\n {0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
showdown.subParser('hashElement')(text, options, globals)); showdown.subParser('makehtml.hashElement')(text, options, globals));
// Special case for standalone HTML comments // Special case for standalone HTML comments
text = showdown.helper.replaceRecursiveRegExp(text, function (txt) { text = showdown.helper.replaceRecursiveRegExp(text, function (txt) {
@ -91,8 +91,8 @@ showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
// PHP and ASP-style processor instructions (<?...?> and <%...%>) // PHP and ASP-style processor instructions (<?...?> and <%...%>)
text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g, text = text.replace(/(?:\n\n)( {0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
showdown.subParser('hashElement')(text, options, globals)); showdown.subParser('makehtml.hashElement')(text, options, globals));
text = globals.converter._dispatch('hashHTMLBlocks.after', text, options, globals); text = globals.converter._dispatch('makehtml.hashHTMLBlocks.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,9 +1,9 @@
/** /**
* Hash span elements that should not be parsed as markdown * Hash span elements that should not be parsed as markdown
*/ */
showdown.subParser('hashHTMLSpans', function (text, options, globals) { showdown.subParser('makehtml.hashHTMLSpans', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('hashHTMLSpans.before', text, options, globals); text = globals.converter._dispatch('makehtml.hashHTMLSpans.before', text, options, globals);
function hashHTMLSpan (html) { function hashHTMLSpan (html) {
return '¨C' + (globals.gHtmlSpans.push(html) - 1) + 'C'; return '¨C' + (globals.gHtmlSpans.push(html) - 1) + 'C';
@ -31,16 +31,16 @@ showdown.subParser('hashHTMLSpans', function (text, options, globals) {
/*showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');*/ /*showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');*/
text = globals.converter._dispatch('hashHTMLSpans.after', text, options, globals); text = globals.converter._dispatch('makehtml.hashHTMLSpans.after', text, options, globals);
return text; return text;
}); });
/** /**
* Unhash HTML spans * Unhash HTML spans
*/ */
showdown.subParser('unhashHTMLSpans', function (text, options, globals) { showdown.subParser('makehtml.unhashHTMLSpans', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('unhashHTMLSpans.before', text, options, globals); text = globals.converter._dispatch('makehtml.unhashHTMLSpans.before', text, options, globals);
for (var i = 0; i < globals.gHtmlSpans.length; ++i) { for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
var repText = globals.gHtmlSpans[i], var repText = globals.gHtmlSpans[i],
@ -59,6 +59,6 @@ showdown.subParser('unhashHTMLSpans', function (text, options, globals) {
text = text.replace('¨C' + i + 'C', repText); text = text.replace('¨C' + i + 'C', repText);
} }
text = globals.converter._dispatch('unhashHTMLSpans.after', text, options, globals); text = globals.converter._dispatch('makehtml.unhashHTMLSpans.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,19 +1,19 @@
/** /**
* Hash and escape <pre><code> elements that should not be parsed as markdown * Hash and escape <pre><code> elements that should not be parsed as markdown
*/ */
showdown.subParser('hashPreCodeTags', function (text, options, globals) { showdown.subParser('makehtml.hashPreCodeTags', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('hashPreCodeTags.before', text, options, globals); text = globals.converter._dispatch('makehtml.hashPreCodeTags.before', text, options, globals);
var repFunc = function (wholeMatch, match, left, right) { var repFunc = function (wholeMatch, match, left, right) {
// encode html entities // encode html entities
var codeblock = left + showdown.subParser('encodeCode')(match, options, globals) + right; var codeblock = left + showdown.subParser('makehtml.encodeCode')(match, options, globals) + right;
return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n'; return '\n\n¨G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
}; };
// Hash <pre><code> // Hash <pre><code>
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^ {0,3}</code>\\s*</pre>', 'gim'); text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^ {0,3}<pre\\b[^>]*>\\s*<code\\b[^>]*>', '^ {0,3}</code>\\s*</pre>', 'gim');
text = globals.converter._dispatch('hashPreCodeTags.after', text, options, globals); text = globals.converter._dispatch('makehtml.hashPreCodeTags.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,7 +1,7 @@
showdown.subParser('headers', function (text, options, globals) { showdown.subParser('makehtml.headers', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('headers.before', text, options, globals); text = globals.converter._dispatch('makehtml.headers.before', text, options, globals);
var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart), var headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
@ -17,19 +17,19 @@ showdown.subParser('headers', function (text, options, globals) {
text = text.replace(setextRegexH1, function (wholeMatch, m1) { text = text.replace(setextRegexH1, function (wholeMatch, m1) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals), var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"', hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart, hLevel = headerLevelStart,
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>'; hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(hashBlock, options, globals); return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals);
}); });
text = text.replace(setextRegexH2, function (matchFound, m1) { text = text.replace(setextRegexH2, function (matchFound, m1) {
var spanGamut = showdown.subParser('spanGamut')(m1, options, globals), var spanGamut = showdown.subParser('makehtml.spanGamut')(m1, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"', hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
hLevel = headerLevelStart + 1, hLevel = headerLevelStart + 1,
hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>'; hashBlock = '<h' + hLevel + hID + '>' + spanGamut + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(hashBlock, options, globals); return showdown.subParser('makehtml.hashBlock')(hashBlock, options, globals);
}); });
// atx-style headers: // atx-style headers:
@ -47,12 +47,12 @@ showdown.subParser('headers', function (text, options, globals) {
hText = m2.replace(/\s?\{([^{]+?)}\s*$/, ''); hText = m2.replace(/\s?\{([^{]+?)}\s*$/, '');
} }
var span = showdown.subParser('spanGamut')(hText, options, globals), var span = showdown.subParser('makehtml.spanGamut')(hText, options, globals),
hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"', hID = (options.noHeaderId) ? '' : ' id="' + headerId(m2) + '"',
hLevel = headerLevelStart - 1 + m1.length, hLevel = headerLevelStart - 1 + m1.length,
header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>'; header = '<h' + hLevel + hID + '>' + span + '</h' + hLevel + '>';
return showdown.subParser('hashBlock')(header, options, globals); return showdown.subParser('makehtml.hashBlock')(header, options, globals);
}); });
function headerId (m) { function headerId (m) {
@ -121,6 +121,6 @@ showdown.subParser('headers', function (text, options, globals) {
return title; return title;
} }
text = globals.converter._dispatch('headers.after', text, options, globals); text = globals.converter._dispatch('makehtml.headers.after', text, options, globals);
return text; return text;
}); });

View File

@ -0,0 +1,15 @@
/**
* Turn Markdown link shortcuts into XHTML <a> tags.
*/
showdown.subParser('makehtml.horizontalRule', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.horizontalRule.before', text, options, globals);
var key = showdown.subParser('makehtml.hashBlock')('<hr />', options, globals);
text = text.replace(/^ {0,2}( ?-){3,}[ \t]*$/gm, key);
text = text.replace(/^ {0,2}( ?\*){3,}[ \t]*$/gm, key);
text = text.replace(/^ {0,2}( ?_){3,}[ \t]*$/gm, key);
text = globals.converter._dispatch('makehtml.horizontalRule.after', text, options, globals);
return text;
});

View File

@ -1,10 +1,10 @@
/** /**
* Turn Markdown image shortcuts into <img> tags. * Turn Markdown image shortcuts into <img> tags.
*/ */
showdown.subParser('images', function (text, options, globals) { showdown.subParser('makehtml.images', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('images.before', text, options, globals); text = globals.converter._dispatch('makehtml.images.before', text, options, globals);
var inlineRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g, var inlineRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<?([\S]+?(?:\([\S]*?\)[\S]*?)?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(["'])([^"]*?)\6)?[ \t]?\)/g,
crazyRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g, crazyRegExp = /!\[([^\]]*?)][ \t]*()\([ \t]?<([^>]*)>(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(?:(["'])([^"]*?)\6))?[ \t]?\)/g,
@ -99,6 +99,6 @@ showdown.subParser('images', function (text, options, globals) {
// handle reference-style shortcuts: ![img text] // handle reference-style shortcuts: ![img text]
text = text.replace(refShortcutRegExp, writeImageTag); text = text.replace(refShortcutRegExp, writeImageTag);
text = globals.converter._dispatch('images.after', text, options, globals); text = globals.converter._dispatch('makehtml.images.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,7 +1,7 @@
showdown.subParser('italicsAndBold', function (text, options, globals) { showdown.subParser('makehtml.italicsAndBold', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('italicsAndBold.before', text, options, globals); text = globals.converter._dispatch('makehtml.italicsAndBold.before', text, options, globals);
// it's faster to have 3 separate regexes for each case than have just one // it's faster to have 3 separate regexes for each case than have just one
// because of backtracing, in some cases, it could lead to an exponential effect // because of backtracing, in some cases, it could lead to an exponential effect
@ -65,6 +65,6 @@ showdown.subParser('italicsAndBold', function (text, options, globals) {
} }
text = globals.converter._dispatch('italicsAndBold.after', text, options, globals); text = globals.converter._dispatch('makehtml.italicsAndBold.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,7 +1,7 @@
/** /**
* Form HTML ordered (numbered) and unordered (bulleted) lists. * Form HTML ordered (numbered) and unordered (bulleted) lists.
*/ */
showdown.subParser('lists', function (text, options, globals) { showdown.subParser('makehtml.lists', function (text, options, globals) {
'use strict'; 'use strict';
/** /**
@ -53,7 +53,7 @@ showdown.subParser('lists', function (text, options, globals) {
listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) { listStr = listStr.replace(rgx, function (wholeMatch, m1, m2, m3, m4, taskbtn, checked) {
checked = (checked && checked.trim() !== ''); checked = (checked && checked.trim() !== '');
var item = showdown.subParser('outdent')(m4, options, globals), var item = showdown.subParser('makehtml.outdent')(m4, options, globals),
bulletStyle = ''; bulletStyle = '';
// Support for github tasklists // Support for github tasklists
@ -85,20 +85,20 @@ showdown.subParser('lists', function (text, options, globals) {
// Has a double return (multi paragraph) or // Has a double return (multi paragraph) or
// Has sublist // Has sublist
if (m1 || (item.search(/\n{2,}/) > -1)) { if (m1 || (item.search(/\n{2,}/) > -1)) {
item = showdown.subParser('githubCodeBlocks')(item, options, globals); item = showdown.subParser('makehtml.githubCodeBlocks')(item, options, globals);
item = showdown.subParser('blockGamut')(item, options, globals); item = showdown.subParser('makehtml.blockGamut')(item, options, globals);
} else { } else {
// Recursion for sub-lists: // Recursion for sub-lists:
item = showdown.subParser('lists')(item, options, globals); item = showdown.subParser('makehtml.lists')(item, options, globals);
item = item.replace(/\n$/, ''); // chomp(item) item = item.replace(/\n$/, ''); // chomp(item)
item = showdown.subParser('hashHTMLBlocks')(item, options, globals); item = showdown.subParser('makehtml.hashHTMLBlocks')(item, options, globals);
// Colapse double linebreaks // Colapse double linebreaks
item = item.replace(/\n\n+/g, '\n\n'); item = item.replace(/\n\n+/g, '\n\n');
if (isParagraphed) { if (isParagraphed) {
item = showdown.subParser('paragraphs')(item, options, globals); item = showdown.subParser('makehtml.paragraphs')(item, options, globals);
} else { } else {
item = showdown.subParser('spanGamut')(item, options, globals); item = showdown.subParser('makehtml.spanGamut')(item, options, globals);
} }
} }
@ -198,6 +198,6 @@ showdown.subParser('lists', function (text, options, globals) {
// strip sentinel // strip sentinel
text = text.replace(/¨0/, ''); text = text.replace(/¨0/, '');
text = globals.converter._dispatch('lists.after', text, options, globals); text = globals.converter._dispatch('makehtml.lists.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,14 +1,14 @@
/** /**
* Parse metadata at the top of the document * Parse metadata at the top of the document
*/ */
showdown.subParser('metadata', function (text, options, globals) { showdown.subParser('makehtml.metadata', function (text, options, globals) {
'use strict'; 'use strict';
if (!options.metadata) { if (!options.metadata) {
return text; return text;
} }
text = globals.converter._dispatch('metadata.before', text, options, globals); text = globals.converter._dispatch('makehtml.metadata.before', text, options, globals);
function parseMetadataContents (content) { function parseMetadataContents (content) {
// raw is raw so it's not changed in any way // raw is raw so it's not changed in any way
@ -44,6 +44,6 @@ showdown.subParser('metadata', function (text, options, globals) {
text = text.replace(/¨M/g, ''); text = text.replace(/¨M/g, '');
text = globals.converter._dispatch('metadata.after', text, options, globals); text = globals.converter._dispatch('makehtml.metadata.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,9 +1,9 @@
/** /**
* Remove one level of line-leading tabs or spaces * Remove one level of line-leading tabs or spaces
*/ */
showdown.subParser('outdent', function (text, options, globals) { showdown.subParser('makehtml.outdent', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('outdent.before', text, options, globals); text = globals.converter._dispatch('makehtml.outdent.before', text, options, globals);
// attacklab: hack around Konqueror 3.5.4 bug: // attacklab: hack around Konqueror 3.5.4 bug:
// "----------bug".replace(/^-/g,"") == "bug" // "----------bug".replace(/^-/g,"") == "bug"
@ -12,6 +12,6 @@ showdown.subParser('outdent', function (text, options, globals) {
// attacklab: clean up hack // attacklab: clean up hack
text = text.replace(/¨0/g, ''); text = text.replace(/¨0/g, '');
text = globals.converter._dispatch('outdent.after', text, options, globals); text = globals.converter._dispatch('makehtml.outdent.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,10 +1,10 @@
/** /**
* *
*/ */
showdown.subParser('paragraphs', function (text, options, globals) { showdown.subParser('makehtml.paragraphs', function (text, options, globals) {
'use strict'; 'use strict';
text = globals.converter._dispatch('paragraphs.before', text, options, globals); text = globals.converter._dispatch('makehtml.paragraphs.before', text, options, globals);
// Strip leading and trailing lines: // Strip leading and trailing lines:
text = text.replace(/^\n+/g, ''); text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, ''); text = text.replace(/\n+$/g, '');
@ -22,7 +22,7 @@ showdown.subParser('paragraphs', function (text, options, globals) {
// test for presence of characters to prevent empty lines being parsed // test for presence of characters to prevent empty lines being parsed
// as paragraphs (resulting in undesired extra empty paragraphs) // as paragraphs (resulting in undesired extra empty paragraphs)
} else if (str.search(/\S/) >= 0) { } else if (str.search(/\S/) >= 0) {
str = showdown.subParser('spanGamut')(str, options, globals); str = showdown.subParser('makehtml.spanGamut')(str, options, globals);
str = str.replace(/^([ \t]*)/g, '<p>'); str = str.replace(/^([ \t]*)/g, '<p>');
str += '</p>'; str += '</p>';
grafsOut.push(str); grafsOut.push(str);
@ -47,7 +47,7 @@ showdown.subParser('paragraphs', function (text, options, globals) {
// we need to check if ghBlock is a false positive // we need to check if ghBlock is a false positive
if (codeFlag) { if (codeFlag) {
// use encoded version of all text // use encoded version of all text
blockText = showdown.subParser('encodeCode')(globals.ghCodeBlocks[num].text, options, globals); blockText = showdown.subParser('makehtml.encodeCode')(globals.ghCodeBlocks[num].text, options, globals);
} else { } else {
blockText = globals.ghCodeBlocks[num].codeblock; blockText = globals.ghCodeBlocks[num].codeblock;
} }
@ -66,5 +66,5 @@ showdown.subParser('paragraphs', function (text, options, globals) {
// Strip leading and trailing lines: // Strip leading and trailing lines:
text = text.replace(/^\n+/g, ''); text = text.replace(/^\n+/g, '');
text = text.replace(/\n+$/g, ''); text = text.replace(/\n+$/g, '');
return globals.converter._dispatch('paragraphs.after', text, options, globals); return globals.converter._dispatch('makehtml.paragraphs.after', text, options, globals);
}); });

View File

@ -1,7 +1,7 @@
/** /**
* Run extension * Run extension
*/ */
showdown.subParser('runExtension', function (ext, text, options, globals) { showdown.subParser('makehtml.runExtension', function (ext, text, options, globals) {
'use strict'; 'use strict';
if (ext.filter) { if (ext.filter) {

View File

@ -0,0 +1,49 @@
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('makehtml.spanGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('smakehtml.panGamut.before', text, options, globals);
text = showdown.subParser('makehtml.codeSpans')(text, options, globals);
text = showdown.subParser('makehtml.escapeSpecialCharsWithinTagAttributes')(text, options, globals);
text = showdown.subParser('makehtml.encodeBackslashEscapes')(text, options, globals);
// Process anchor and image tags. Images must come first,
// because ![foo][f] looks like an anchor.
text = showdown.subParser('makehtml.images')(text, options, globals);
text = showdown.subParser('makehtml.anchors')(text, options, globals);
// Make links out of things like `<http://example.com/>`
// Must come after anchors, because you can use < and >
// delimiters in inline links like [this](<url>).
text = showdown.subParser('makehtml.autoLinks')(text, options, globals);
text = showdown.subParser('makehtml.simplifiedAutoLinks')(text, options, globals);
text = showdown.subParser('makehtml.emoji')(text, options, globals);
text = showdown.subParser('makehtml.underline')(text, options, globals);
text = showdown.subParser('makehtml.italicsAndBold')(text, options, globals);
text = showdown.subParser('makehtml.strikethrough')(text, options, globals);
text = showdown.subParser('makehtml.ellipsis')(text, options, globals);
// we need to hash HTML tags inside spans
text = showdown.subParser('makehtml.hashHTMLSpans')(text, options, globals);
// now we encode amps and angles
text = showdown.subParser('makehtml.encodeAmpsAndAngles')(text, options, globals);
// Do hard breaks
if (options.simpleLineBreaks) {
// GFM style hard breaks
// only add line breaks if the text does not contain a block (special case for lists)
if (!/\n\n¨K/.test(text)) {
text = text.replace(/\n+/g, '<br />\n');
}
} else {
// Vanilla hard breaks
text = text.replace(/ +\n/g, '<br />\n');
}
text = globals.converter._dispatch('makehtml.spanGamut.after', text, options, globals);
return text;
});

View File

@ -0,0 +1,18 @@
showdown.subParser('makehtml.strikethrough', function (text, options, globals) {
'use strict';
function parseInside (txt) {
if (options.simplifiedAutoLink) {
txt = showdown.subParser('makehtml.simplifiedAutoLinks')(txt, options, globals);
}
return '<del>' + txt + '</del>';
}
if (options.strikethrough) {
text = globals.converter._dispatch('makehtml.strikethrough.before', text, options, globals);
text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return parseInside(txt); });
text = globals.converter._dispatch('makehtml.strikethrough.after', text, options, globals);
}
return text;
});

View File

@ -3,7 +3,7 @@
* hash references. * hash references.
* Link defs are in the form: ^[id]: url "optional title" * Link defs are in the form: ^[id]: url "optional title"
*/ */
showdown.subParser('stripLinkDefinitions', function (text, options, globals) { showdown.subParser('makehtml.stripLinkDefinitions', function (text, options, globals) {
'use strict'; 'use strict';
var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?([^>\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm, var regex = /^ {0,3}\[(.+)]:[ \t]*\n?[ \t]*<?([^>\s]+)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*\n?[ \t]*(?:(\n*)["|'(](.+?)["|')][ \t]*)?(?:\n+|(?=¨0))/gm,
@ -18,7 +18,7 @@ showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
// remove newlines // remove newlines
globals.gUrls[linkId] = url.replace(/\s/g, ''); globals.gUrls[linkId] = url.replace(/\s/g, '');
} else { } else {
globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url, options, globals); // Link IDs are case-insensitive globals.gUrls[linkId] = showdown.subParser('makehtml.encodeAmpsAndAngles')(url, options, globals); // Link IDs are case-insensitive
} }
if (blankLines) { if (blankLines) {

View File

@ -1,4 +1,4 @@
showdown.subParser('tables', function (text, options, globals) { showdown.subParser('makehtml.tables', function (text, options, globals) {
'use strict'; 'use strict';
if (!options.tables) { if (!options.tables) {
@ -28,13 +28,13 @@ showdown.subParser('tables', function (text, options, globals) {
if (options.tablesHeaderId || options.tableHeaderId) { if (options.tablesHeaderId || options.tableHeaderId) {
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"'; id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
} }
header = showdown.subParser('spanGamut')(header, options, globals); header = showdown.subParser('makehtml.spanGamut')(header, options, globals);
return '<th' + id + style + '>' + header + '</th>\n'; return '<th' + id + style + '>' + header + '</th>\n';
} }
function parseCells (cell, style) { function parseCells (cell, style) {
var subText = showdown.subParser('spanGamut')(cell, options, globals); var subText = showdown.subParser('makehtml.spanGamut')(cell, options, globals);
return '<td' + style + '>' + subText + '</td>\n'; return '<td' + style + '>' + subText + '</td>\n';
} }
@ -70,7 +70,7 @@ showdown.subParser('tables', function (text, options, globals) {
tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, ''); tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
} }
// parse code spans first, but we only support one line code spans // parse code spans first, but we only support one line code spans
tableLines[i] = showdown.subParser('codeSpans')(tableLines[i], options, globals); tableLines[i] = showdown.subParser('makehtml.codeSpans')(tableLines[i], options, globals);
} }
var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}), var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
@ -125,7 +125,7 @@ showdown.subParser('tables', function (text, options, globals) {
return buildTable(headers, cells); return buildTable(headers, cells);
} }
text = globals.converter._dispatch('tables.before', text, options, globals); text = globals.converter._dispatch('makehtml.tables.before', text, options, globals);
// find escaped pipe characters // find escaped pipe characters
text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback); text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);
@ -136,7 +136,7 @@ showdown.subParser('tables', function (text, options, globals) {
// parse one column tables // parse one column tables
text = text.replace(singeColTblRgx, parseTable); text = text.replace(singeColTblRgx, parseTable);
text = globals.converter._dispatch('tables.after', text, options, globals); text = globals.converter._dispatch('makehtml.tables.after', text, options, globals);
return text; return text;
}); });

View File

@ -1,11 +1,11 @@
showdown.subParser('underline', function (text, options, globals) { showdown.subParser('makehtml.underline', function (text, options, globals) {
'use strict'; 'use strict';
if (!options.underline) { if (!options.underline) {
return text; return text;
} }
text = globals.converter._dispatch('underline.before', text, options, globals); text = globals.converter._dispatch('makehtml.underline.before', text, options, globals);
if (options.literalMidWordUnderscores) { if (options.literalMidWordUnderscores) {
text = text.replace(/\b_?__(\S[\s\S]*)___?\b/g, function (wm, txt) { text = text.replace(/\b_?__(\S[\s\S]*)___?\b/g, function (wm, txt) {
@ -20,7 +20,7 @@ showdown.subParser('underline', function (text, options, globals) {
// escape remaining underscores to prevent them being parsed by italic and bold // escape remaining underscores to prevent them being parsed by italic and bold
text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback); text = text.replace(/(_)/g, showdown.helper.escapeCharactersCallback);
text = globals.converter._dispatch('underline.after', text, options, globals); text = globals.converter._dispatch('makehtml.underline.after', text, options, globals);
return text; return text;
}); });

View File

@ -0,0 +1,15 @@
/**
* Swap back in all the special characters we've hidden.
*/
showdown.subParser('makehtml.unescapeSpecialChars', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.before', text, options, globals);
text = text.replace(/¨E(\d+)E/g, function (wholeMatch, m1) {
var charCodeToReplace = parseInt(m1);
return String.fromCharCode(charCodeToReplace);
});
text = globals.converter._dispatch('makehtml.unescapeSpecialChars.after', text, options, globals);
return text;
});

View File

@ -1,49 +0,0 @@
/**
* These are all the transformations that occur *within* block-level
* tags like paragraphs, headers, and list items.
*/
showdown.subParser('spanGamut', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('spanGamut.before', text, options, globals);
text = showdown.subParser('codeSpans')(text, options, globals);
text = showdown.subParser('escapeSpecialCharsWithinTagAttributes')(text, options, globals);
text = showdown.subParser('encodeBackslashEscapes')(text, options, globals);
// Process anchor and image tags. Images must come first,
// because ![foo][f] looks like an anchor.
text = showdown.subParser('images')(text, options, globals);
text = showdown.subParser('anchors')(text, options, globals);
// Make links out of things like `<http://example.com/>`
// Must come after anchors, because you can use < and >
// delimiters in inline links like [this](<url>).
text = showdown.subParser('autoLinks')(text, options, globals);
text = showdown.subParser('simplifiedAutoLinks')(text, options, globals);
text = showdown.subParser('emoji')(text, options, globals);
text = showdown.subParser('underline')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);
text = showdown.subParser('ellipsis')(text, options, globals);
// we need to hash HTML tags inside spans
text = showdown.subParser('hashHTMLSpans')(text, options, globals);
// now we encode amps and angles
text = showdown.subParser('encodeAmpsAndAngles')(text, options, globals);
// Do hard breaks
if (options.simpleLineBreaks) {
// GFM style hard breaks
// only add line breaks if the text does not contain a block (special case for lists)
if (!/\n\n¨K/.test(text)) {
text = text.replace(/\n+/g, '<br />\n');
}
} else {
// Vanilla hard breaks
text = text.replace(/ +\n/g, '<br />\n');
}
text = globals.converter._dispatch('spanGamut.after', text, options, globals);
return text;
});

View File

@ -1,18 +0,0 @@
showdown.subParser('strikethrough', function (text, options, globals) {
'use strict';
function parseInside (txt) {
if (options.simplifiedAutoLink) {
txt = showdown.subParser('simplifiedAutoLinks')(txt, options, globals);
}
return '<del>' + txt + '</del>';
}
if (options.strikethrough) {
text = globals.converter._dispatch('strikethrough.before', text, options, globals);
text = text.replace(/(?:~){2}([\s\S]+?)(?:~){2}/g, function (wm, txt) { return parseInside(txt); });
text = globals.converter._dispatch('strikethrough.after', text, options, globals);
}
return text;
});

View File

@ -1,15 +0,0 @@
/**
* Swap back in all the special characters we've hidden.
*/
showdown.subParser('unescapeSpecialChars', function (text, options, globals) {
'use strict';
text = globals.converter._dispatch('unescapeSpecialChars.before', text, options, globals);
text = text.replace(/¨E(\d+)E/g, function (wholeMatch, m1) {
var charCodeToReplace = parseInt(m1);
return String.fromCharCode(charCodeToReplace);
});
text = globals.converter._dispatch('unescapeSpecialChars.after', text, options, globals);
return text;
});