From 714c3c9207fa26ed5a872cb1d4996dee1e1c4229 Mon Sep 17 00:00:00 2001
From: Hahaha!! 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;
-});
-
-showdown.subParser('blockQuotes', function (text, options, globals) {
- 'use strict';
-
- text = globals.converter._dispatch('blockQuotes.before', text, options, globals);
- /*
- 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(/((^[ \t]{0,3}>[ \t]?.+\n(.+\n)*\n*)+)/gm, function (wholeMatch, m1) {
- var bq = m1;
-
- // attacklab: hack around Konqueror 3.5.4 bug:
- // "----------bug".replace(/^-/g,"") == "bug"
- bq = bq.replace(/^[ \t]*>[ \t]?/gm, '~0'); // trim one level of quoting
-
- // attacklab: clean up hack
- bq = bq.replace(/~0/g, '');
-
- bq = bq.replace(/^[ \t]+$/gm, ''); // trim whitespace-only lines
- bq = showdown.subParser('githubCodeBlocks')(bq, options, globals);
- bq = showdown.subParser('blockGamut')(bq, options, globals); // recurse
-
- bq = bq.replace(/(^|\n)/g, '$1 ');
- // These leading spaces screw with Just type tags
-
- for (var i = 0; i < end; i++) {
- var str = grafs[i];
- // if this is an HTML marker, copy it
- if (str.search(/~(K|G)(\d+)\1/g) >= 0) {
- grafsOut.push(str);
- } else {
- str = showdown.subParser('spanGamut')(str, options, globals);
- str = str.replace(/^([ \t]*)/g, ' ');
- str += ' >t<>", "<", ">", "g")
- * returns: ["t<", ""]
- * matchRecursiveRegExp("
', 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 = 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
- // content, so we need to fix that:
- bq = bq.replace(/(\s*
[^\r]+?<\/pre>)/gm, function (wholeMatch, m1) {
- var pre = m1;
- // attacklab: hack around Konqueror 3.5.4 bug:
- pre = pre.replace(/^ /mg, '~0');
- pre = pre.replace(/~0/g, '');
- return pre;
- });
-
- return showdown.subParser('hashBlock')('\n' + bq + '\n
', options, globals);
- });
-
- text = globals.converter._dispatch('blockQuotes.after', text, options, globals);
- return text;
-});
-
-/**
- * Process Markdown `` blocks.
- */
-showdown.subParser('codeBlocks', function (text, options, globals) {
- 'use strict';
-
- text = globals.converter._dispatch('codeBlocks.before', text, options, globals);
- /*
- text = text.replace(text,
- /(?:\n\n|^)
- ( // $1 = the code block -- one or more lines, starting with a space/tab
- (?:
- (?:[ ]{4}|\t) // Lines must start with a tab or a tab-width of spaces - attacklab: g_tab_width
- .*\n+
- )+
- )
- (\n*[ ]{0,3}[^ \t\n]|(?=~0)) // attacklab: g_tab_width
- /g,function(){...});
- */
-
- // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
- text += '~0';
-
- var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g;
- text = text.replace(pattern, function (wholeMatch, m1, m2) {
- var codeblock = m1,
- nextChar = m2,
- end = '\n';
-
- codeblock = showdown.subParser('outdent')(codeblock);
- codeblock = showdown.subParser('encodeCode')(codeblock);
- codeblock = showdown.subParser('detab')(codeblock);
- codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines
- codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines
-
- if (options.omitExtraWLInCodeBlocks) {
- end = '';
- }
-
- codeblock = '
';
-
- return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
- });
-
- // attacklab: strip sentinel
- text = text.replace(/~0/, '');
-
- text = globals.converter._dispatch('codeBlocks.after', text, options, globals);
- return text;
-});
-
-/**
- *
- * * Backtick quotes are used for ' + codeblock + end + ' spans.
- *
- * * You can use multiple backticks as the delimiters if you want to
- * include literal backticks in the code span. So, this input:
- *
- * Just type ``foo `bar` baz`` at the prompt.
- *
- * Will translate to:
- *
- * foo `bar` baz at the prompt.`bar` ...
- */
-showdown.subParser('codeSpans', function (text, options, globals) {
- 'use strict';
-
- text = globals.converter._dispatch('codeSpans.before', text, options, globals);
-
- /*
- 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(){...});
- */
-
- if (typeof(text) === 'undefined') {
- text = '';
- }
- text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
- function (wholeMatch, m1, m2, m3) {
- var c = m3;
- c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
- c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
- c = showdown.subParser('encodeCode')(c);
- return m1 + '' + c + '';
- }
- );
-
- text = globals.converter._dispatch('codeSpans.after', text, options, globals);
- return text;
-});
-
-/**
- * Convert all tabs to spaces
- */
-showdown.subParser('detab', function (text) {
- 'use strict';
-
- // expand first n-1 tabs
- text = text.replace(/\t(?=\t)/g, ' '); // g_tab_width
-
- // replace the nth with two sentinels
- text = text.replace(/\t/g, '~A~B');
-
- // use the sentinel to anchor our regex so it doesn't explode
- text = text.replace(/~B(.+?)~A/g, function (wholeMatch, m1) {
- var leadingText = m1,
- numSpaces = 4 - leadingText.length % 4; // g_tab_width
-
- // there *must* be a better way to do this:
- for (var i = 0; i < numSpaces; i++) {
- leadingText += ' ';
- }
-
- return leadingText;
- });
-
- // clean up sentinels
- text = text.replace(/~A/g, ' '); // g_tab_width
- text = text.replace(/~B/g, '');
-
- return text;
-
-});
-
-/**
- * Smart processing for ampersands and angle brackets that need to be encoded.
- */
-showdown.subParser('encodeAmpsAndAngles', function (text) {
- 'use strict';
- // Ampersand-encoding based entirely on Nat Irons's Amputator MT plugin:
- // http://bumppo.net/projects/amputator/
- text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, '&');
-
- // Encode naked <'s
- text = text.replace(/<(?![a-z\/?\$!])/gi, '<');
-
- return text;
-});
-
-/**
- * Returns the string, with after processing the following backslash escape sequences.
- *
- * attacklab: The polite way to do this is with the new escapeCharacters() function:
- *
- * text = escapeCharacters(text,"\\",true);
- * text = escapeCharacters(text,"`*_{}[]()>#+-.!",true);
- *
- * ...but we're sidestepping its use of the (slow) RegExp constructor
- * as an optimization for Firefox. This function gets called a LOT.
- */
-showdown.subParser('encodeBackslashEscapes', function (text) {
- 'use strict';
- text = text.replace(/\\(\\)/g, showdown.helper.escapeCharactersCallback);
- text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g, showdown.helper.escapeCharactersCallback);
- return text;
-});
-
-/**
- * Encode/escape certain characters inside Markdown code runs.
- * The point is that in code, these characters are literals,
- * and lose their special Markdown meanings.
- */
-showdown.subParser('encodeCode', function (text) {
- 'use strict';
-
- // Encode all ampersands; HTML entities are not
- // entities within a Markdown code span.
- text = text.replace(/&/g, '&');
-
- // Do the angle bracket song and dance:
- text = text.replace(//g, '>');
-
- // Now, escape characters that are magic in Markdown:
- text = showdown.helper.escapeCharacters(text, '*_{}[]\\', false);
-
- // jj the line above breaks this:
- //---
- //* Item
- // 1. Subitem
- // special char: *
- // ---
-
- return text;
-});
-
-/**
- * Input: an email address, e.g. "foo@example.com"
- *
- * Output: the email address as a mailto link, with each character
- * of the address encoded as either a decimal or hex entity, in
- * the hopes of foiling most address harvesting spam bots. E.g.:
- *
- * foo
- * @example.com
- *
- * Based on a filter by Matthew Wickline, posted to the BBEdit-Talk
- * mailing list:
';
-
- codeblock = showdown.subParser('hashBlock')(codeblock, options, globals);
-
- // Since GHCodeblocks can be false positives, we need to
- // store the primitive text and the parsed text in a global var,
- // and then return a token
- return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
- });
-
- // attacklab: strip sentinel
- text = text.replace(/~0/, '');
-
- return globals.converter._dispatch('githubCodeBlocks.after', text, options, globals);
-});
-
-showdown.subParser('hashBlock', function (text, options, globals) {
- 'use strict';
- text = text.replace(/(^\n+|\n+$)/g, '');
- return '\n\n~K' + (globals.gHtmlBlocks.push(text) - 1) + 'K\n\n';
-});
-
-showdown.subParser('hashElement', function (text, options, globals) {
- 'use strict';
-
- return function (wholeMatch, m1) {
- var blockText = m1;
-
- // Undo double lines
- blockText = blockText.replace(/\n\n/g, '\n');
- blockText = blockText.replace(/^\n/, '');
-
- // strip trailing blank lines
- blockText = blockText.replace(/\n+$/g, '');
-
- // Replace the element text with a marker ("~KxK" where x is its key)
- blockText = '\n\n~K' + (globals.gHtmlBlocks.push(blockText) - 1) + 'K\n\n';
-
- return blockText;
- };
-});
-
-showdown.subParser('hashHTMLBlocks', function (text, options, globals) {
- 'use strict';
-
- var blockTags = [
- 'pre',
- 'div',
- 'h1',
- 'h2',
- 'h3',
- 'h4',
- 'h5',
- 'h6',
- 'blockquote',
- 'table',
- 'dl',
- 'ol',
- 'ul',
- 'script',
- 'noscript',
- 'form',
- 'fieldset',
- 'iframe',
- 'math',
- 'style',
- 'section',
- 'header',
- 'footer',
- 'nav',
- 'article',
- 'aside',
- 'address',
- 'audio',
- 'canvas',
- 'figure',
- 'hgroup',
- 'output',
- 'video',
- 'p'
- ],
- repFunc = function (wholeMatch, match, left, right) {
- var txt = wholeMatch;
- // check if this html element is marked as markdown
- // if so, it's contents should be parsed as markdown
- if (left.search(/\bmarkdown\b/) !== -1) {
- txt = left + globals.converter.makeHtml(match) + right;
- }
- return '\n\n~K' + (globals.gHtmlBlocks.push(txt) - 1) + 'K\n\n';
- };
-
- for (var i = 0; i < blockTags.length; ++i) {
- text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}<' + blockTags[i] + '\\b[^>]*>', '' + blockTags[i] + '>', 'gim');
- }
-
- // HR SPECIAL CASE
- text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,
- showdown.subParser('hashElement')(text, options, globals));
-
- // Special case for standalone HTML comments:
- text = text.replace(/()/g,
- showdown.subParser('hashElement')(text, options, globals));
-
- // PHP and ASP-style processor instructions (...?> and <%...%>)
- text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,
- showdown.subParser('hashElement')(text, options, globals));
- return text;
-});
-
-/**
- * Hash span elements that should not be parsed as markdown
- */
-showdown.subParser('hashHTMLSpans', function (text, config, globals) {
- 'use strict';
-
- var matches = showdown.helper.matchRecursiveRegExp(text, '' + codeblock + end + ']*>', '', 'gi');
-
- for (var i = 0; i < matches.length; ++i) {
- text = text.replace(matches[i][0], '~L' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'L');
- }
- return text;
-});
-
-/**
- * Unhash HTML spans
- */
-showdown.subParser('unhashHTMLSpans', function (text, config, globals) {
- 'use strict';
-
- for (var i = 0; i < globals.gHtmlSpans.length; ++i) {
- text = text.replace('~L' + i + 'L', globals.gHtmlSpans[i]);
- }
-
- return text;
-});
-
-/**
- * Hash span elements that should not be parsed as markdown
- */
-showdown.subParser('hashPreCodeTags', function (text, config, globals) {
- 'use strict';
-
- var repFunc = function (wholeMatch, match, left, right) {
- // encode html entities
- var codeblock = left + showdown.subParser('encodeCode')(match) + right;
- return '\n\n~G' + (globals.ghCodeBlocks.push({text: wholeMatch, codeblock: codeblock}) - 1) + 'G\n\n';
- };
-
- text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '^(?: |\\t){0,3}]*>\\s*
', 'gim');
- return text;
-});
-
-showdown.subParser('headers', function (text, options, globals) {
- 'use strict';
-
- text = globals.converter._dispatch('headers.before', text, options, globals);
-
- var prefixHeader = options.prefixHeaderId,
- headerLevelStart = (isNaN(parseInt(options.headerLevelStart))) ? 1 : parseInt(options.headerLevelStart),
-
- // Set text-style headers:
- // Header 1
- // ========
- //
- // Header 2
- // --------
- //
- setextRegexH1 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n={2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n=+[ \t]*\n+/gm,
- setextRegexH2 = (options.smoothLivePreview) ? /^(.+)[ \t]*\n-{2,}[ \t]*\n+/gm : /^(.+)[ \t]*\n-+[ \t]*\n+/gm;
-
- text = text.replace(setextRegexH1, function (wholeMatch, m1) {
-
- var spanGamut = showdown.subParser('spanGamut')(m1, options, globals),
- hID = (options.noHeaderId) ? '' : ' id="' + headerId(m1) + '"',
- hLevel = headerLevelStart,
- hashBlock = ']*>', '^(?: |\\t){0,3}\\s* tags.
- */
-showdown.subParser('images', function (text, options, globals) {
- 'use strict';
-
- text = globals.converter._dispatch('images.before', text, options, globals);
-
- var inlineRegExp = /!\[(.*?)]\s?\([ \t]*()(\S+?)>?(?: =([*\d]+[A-Za-z%]{0,4})x([*\d]+[A-Za-z%]{0,4}))?[ \t]*(?:(['"])(.*?)\6[ \t]*)?\)/g,
- referenceRegExp = /!\[([^\]]*?)] ?(?:\n *)?\[(.*?)]()()()()()/g;
-
- function writeImageTag (wholeMatch, altText, linkId, url, width, height, m5, title) {
-
- var gUrls = globals.gUrls,
- gTitles = globals.gTitles,
- gDims = globals.gDimensions;
-
- linkId = linkId.toLowerCase();
-
- if (!title) {
- title = '';
- }
-
- if (url === '' || url === null) {
- if (linkId === '' || linkId === null) {
- // lower-case and turn embedded newlines into spaces
- linkId = altText.toLowerCase().replace(/ ?\n/g, ' ');
- }
- url = '#' + linkId;
-
- if (!showdown.helper.isUndefined(gUrls[linkId])) {
- url = gUrls[linkId];
- if (!showdown.helper.isUndefined(gTitles[linkId])) {
- title = gTitles[linkId];
- }
- if (!showdown.helper.isUndefined(gDims[linkId])) {
- width = gDims[linkId].width;
- height = gDims[linkId].height;
- }
- } else {
- return wholeMatch;
- }
- }
-
- altText = altText.replace(/"/g, '"');
- altText = showdown.helper.escapeCharacters(altText, '*_', false);
- url = showdown.helper.escapeCharacters(url, '*_', false);
- var result = '
';
- return result;
- }
-
- // First, handle reference-style labeled images: ![alt text][id]
- text = text.replace(referenceRegExp, writeImageTag);
-
- // Next, handle inline images: ) {
- codeFlag = true;
- }
- }
- grafsOut[i] = grafsOutIt;
- }
- text = grafsOut.join('\n\n');
- // Strip leading and trailing lines:
- text = text.replace(/^\n+/g, '');
- text = text.replace(/\n+$/g, '');
- return globals.converter._dispatch('paragraphs.after', text, options, globals);
-});
-
-/**
- * Run extension
- */
-showdown.subParser('runExtension', function (ext, text, options, globals) {
- 'use strict';
-
- if (ext.filter) {
- text = ext.filter(text, globals.converter, options);
-
- } else if (ext.regex) {
- // TODO remove this when old extension loading mechanism is deprecated
- var re = ext.regex;
- if (!re instanceof RegExp) {
- re = new RegExp(re, 'g');
- }
- text = text.replace(re, ext.replace);
- }
-
- return text;
-});
-
-/**
- * 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 `
\n');
-
- text = globals.converter._dispatch('spanGamut.after', text, options, globals);
- return text;
-});
-
-showdown.subParser('strikethrough', function (text, options, globals) {
- 'use strict';
-
- if (options.strikethrough) {
- text = globals.converter._dispatch('strikethrough.before', text, options, globals);
- text = text.replace(/(?:~T){2}([\s\S]+?)(?:~T){2}/g, '$1');
- text = globals.converter._dispatch('strikethrough.after', text, options, globals);
- }
-
- return text;
-});
-
-/**
- * Strip any lines consisting only of spaces and tabs.
- * This makes subsequent regexs easier to write, because we can
- * match consecutive blank lines with /\n+/ instead of something
- * contorted like /[ \t]*\n+/
- */
-showdown.subParser('stripBlankLines', function (text) {
- 'use strict';
- return text.replace(/^[ \t]+$/mg, '');
-});
-
-/**
- * Strips link definitions from text, stores the URLs and titles in
- * hash references.
- * Link defs are in the form: ^[id]: url "optional title"
- *
- * ^[ ]{0,3}\[(.+)\]: // id = $1 attacklab: g_tab_width - 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(){...});
- *
- */
-showdown.subParser('stripLinkDefinitions', function (text, options, globals) {
- '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;
-
- // attacklab: sentinel workarounds for lack of \A and \Z, safari\khtml bug
- text += '~0';
-
- text = text.replace(regex, function (wholeMatch, linkId, url, width, height, blankLines, title) {
- linkId = linkId.toLowerCase();
- globals.gUrls[linkId] = showdown.subParser('encodeAmpsAndAngles')(url); // Link IDs are case-insensitive
-
- if (blankLines) {
- // Oops, found blank lines, so it's not a title.
- // Put back the parenthetical statement we stole.
- return blankLines + title;
-
- } else {
- if (title) {
- globals.gTitles[linkId] = title.replace(/"|'/g, '"');
- }
- if (options.parseImgDimensions && width && height) {
- globals.gDimensions[linkId] = {
- width: width,
- height: height
- };
- }
- }
- // Completely remove the definition from the text
- return '';
- });
-
- // attacklab: strip sentinel
- text = text.replace(/~0/, '');
-
- return text;
-});
-
-showdown.subParser('tables', function (text, options, globals) {
- 'use strict';
-
- if (!options.tables) {
- return text;
- }
-
- var tableRgx = /^[ \t]{0,3}\|?.+\|.+\n[ \t]{0,3}\|?[ \t]*:?[ \t]*(?:-|=){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:-|=){2,}[\s\S]+?(?:\n\n|~0)/gm;
-
- function parseStyles(sLine) {
- if (/^:[ \t]*--*$/.test(sLine)) {
- return ' style="text-align:left;"';
- } else if (/^--*[ \t]*:[ \t]*$/.test(sLine)) {
- return ' style="text-align:right;"';
- } else if (/^:[ \t]*--*[ \t]*:$/.test(sLine)) {
- return ' style="text-align:center;"';
- } else {
- return '';
- }
- }
-
- function parseHeaders(header, style) {
- var id = '';
- header = header.trim();
- if (options.tableHeaderId) {
- id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
- }
- header = showdown.subParser('spanGamut')(header, options, globals);
-
- return '' + header + ' \n';
- }
-
- function parseCells(cell, style) {
- var subText = showdown.subParser('spanGamut')(cell, options, globals);
- return '' + subText + ' \n';
- }
-
- function buildTable(headers, cells) {
- var tb = '\n\n
\n';
- return tb;
- }
-
- text = globals.converter._dispatch('tables.before', text, options, globals);
-
- text = text.replace(tableRgx, function (rawTable) {
-
- var i, tableLines = rawTable.split('\n');
-
- // strip wrong first and last column if wrapped tables are used
- for (i = 0; i < tableLines.length; ++i) {
- if (/^[ \t]{0,3}\|/.test(tableLines[i])) {
- tableLines[i] = tableLines[i].replace(/^[ \t]{0,3}\|/, '');
- }
- if (/\|[ \t]*$/.test(tableLines[i])) {
- tableLines[i] = tableLines[i].replace(/\|[ \t]*$/, '');
- }
- }
-
- var rawHeaders = tableLines[0].split('|').map(function (s) { return s.trim();}),
- rawStyles = tableLines[1].split('|').map(function (s) { return s.trim();}),
- rawCells = [],
- headers = [],
- styles = [],
- cells = [];
-
- tableLines.shift();
- tableLines.shift();
-
- for (i = 0; i < tableLines.length; ++i) {
- if (tableLines[i].trim() === '') {
- continue;
- }
- rawCells.push(
- tableLines[i]
- .split('|')
- .map(function (s) {
- return s.trim();
- })
- );
- }
-
- if (rawHeaders.length < rawStyles.length) {
- return rawTable;
- }
-
- for (i = 0; i < rawStyles.length; ++i) {
- styles.push(parseStyles(rawStyles[i]));
- }
-
- for (i = 0; i < rawHeaders.length; ++i) {
- if (showdown.helper.isUndefined(styles[i])) {
- styles[i] = '';
- }
- headers.push(parseHeaders(rawHeaders[i], styles[i]));
- }
-
- for (i = 0; i < rawCells.length; ++i) {
- var row = [];
- for (var ii = 0; ii < headers.length; ++ii) {
- if (showdown.helper.isUndefined(rawCells[i][ii])) {
-
- }
- row.push(parseCells(rawCells[i][ii], styles[ii]));
- }
- cells.push(row);
- }
-
- return buildTable(headers, cells);
- });
-
- text = globals.converter._dispatch('tables.after', text, options, globals);
-
- return text;
-});
-
-/**
- * Swap back in all the special characters we've hidden.
- */
-showdown.subParser('unescapeSpecialChars', function (text) {
- 'use strict';
-
- text = text.replace(/~E(\d+)E/g, function (wholeMatch, m1) {
- var charCodeToReplace = parseInt(m1);
- return String.fromCharCode(charCodeToReplace);
- });
- return text;
-});
-module.exports = showdown;
diff --git a/components/wxParse/wxParse.js b/components/wxParse/wxParse.js
index 4820cdc..ebd1f17 100644
--- a/components/wxParse/wxParse.js
+++ b/components/wxParse/wxParse.js
@@ -1,31 +1,23 @@
-import HtmlToJson from './utils/html2json';
-import showdown from './utils/showdown.js';
-import { getSystemInfo, bindData } from './utils/util';
+import HtmlToJson from '../../utils/html2json';
+import { getSystemInfo, bindData } from '../../utils/util';
Component({
properties: {
nodes: {
type: null,
observer(val) {
- const { language } = this.properties
if (val) {
- if (language === 'html') {
- this._parseNodes(val)
- }
-
- if (language === 'markdown' || language === 'md') {
- const converter = new showdown.Converter();
- const parseNodes = converter.makeHtml(val);
- this._parseNodes(parseNodes)
+ if (typeof val === 'string') { // 初始为html富文本字符串
+ this._parseHtml(val)
+ } else if (Array.isArray(val)) { // html 富文本解析成节点数组
+ this.setData({ nodesData: val })
+ } else { // 其余为单个节点对象
+ const nodesData = [ val ]
+ this.setData({ nodesData })
}
}
}
},
-
- language: {
- type: String,
- value: 'html' // 可选:html | markdown (md)
- }
},
data: {
@@ -42,6 +34,7 @@ Component({
transData.view = {}
transData.view.imagePadding = 0
+
this.setData({
nodesData: transData.nodes,
bindData: {
@@ -52,17 +45,6 @@ Component({
console.log(this.data)
},
- _parseNodes(nodes) {
- if (typeof nodes === 'string') { // 初始为html富文本字符串
- this._parseHtml(nodes)
- } else if (Array.isArray(nodes)) { // html 富文本解析成节点数组
- this.setData({ nodesData: nodes })
- } else { // 其余为单个节点对象
- const nodesData = [ nodes ]
- this.setData({ nodesData })
- }
- },
-
/**
* 图片视觉宽高计算函数区
* @param {*} e
diff --git a/components/wxParse/wxParse.wxml b/components/wxParse/wxParse.wxml
index 72acb28..f700d3a 100644
--- a/components/wxParse/wxParse.wxml
+++ b/components/wxParse/wxParse.wxml
@@ -17,7 +17,7 @@
\n',
- tblLgn = headers.length;
-
- for (var i = 0; i < tblLgn; ++i) {
- tb += headers[i];
- }
- tb += ' \n\n\n';
-
- for (i = 0; i < cells.length; ++i) {
- tb += '\n';
- for (var ii = 0; ii < tblLgn; ++ii) {
- tb += cells[i][ii];
- }
- tb += ' \n';
- }
- tb += '\nh1
- h2
- h3
- h4
-
-
-
-
-
-
-
-
-
-
-
- 

iBIez$Ve%04ZH&9Ly&1a0u>7+F}`J2OUPc>zubPKC%jGb8zTO}
z3dOFLjFUnmYoHT5z~Q|=?PGfEH3uyArVziwvd1q>!>lwsw~6~>?GX6$Ptrc(fXscQ
zqheae_vbO6*L}UV4HgZe-b`V(@a5uuVqhKk?J&iUs_KP_GTCA)+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