mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
Merge branch 'master' into feature/reverse_convert
# Conflicts: # dist/showdown.js # dist/showdown.js.map # dist/showdown.min.js # dist/showdown.min.js.map
This commit is contained in:
commit
53255fd7a1
21
CHANGELOG.md
21
CHANGELOG.md
|
@ -1,3 +1,24 @@
|
|||
<a name="1.8.5"></a>
|
||||
# [1.8.5](https://github.com/showdownjs/showdown/compare/1.8.4...1.8.5) (2017-12-10)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **completeHTMLDocument:** add option to output a complete HTML document ([a8427c9](https://github.com/showdownjs/showdown/commit/a8427c9))
|
||||
* **metadata:** add support for embedded metadata ([63d949f](https://github.com/showdownjs/showdown/commit/63d949f)), closes [#260](https://github.com/showdownjs/showdown/issues/260)
|
||||
|
||||
|
||||
|
||||
<a name="1.8.4"></a>
|
||||
## [1.8.4](https://github.com/showdownjs/showdown/compare/1.8.3...1.8.4) (2017-12-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **tables:** raw html inside code tags in tables no longer breaks tables ([4ef4c5e](https://github.com/showdownjs/showdown/commit/4ef4c5e)), closes [#471](https://github.com/showdownjs/showdown/issues/471)
|
||||
|
||||
|
||||
|
||||
<a name="1.8.3"></a>
|
||||
## [1.8.3](https://github.com/showdownjs/showdown/compare/1.8.2...1.8.3) (2017-11-28)
|
||||
|
||||
|
|
|
@ -17,3 +17,5 @@ We would like to thank everyone that contributed to this library. If you find ou
|
|||
- **Walter Schnell** (10$)
|
||||
|
||||
- [**Learn on demand Systems**](http://www.learnondemandsystems.com/) (1000$)
|
||||
|
||||
- **ivanhjc** (5$)
|
||||
|
|
|
@ -360,8 +360,15 @@ var defaultOptions = showdown.getDefaultOptions();
|
|||
* **underline**: (boolean) [default false] ***EXPERIMENTAL FEATURE*** Enable support for underline.
|
||||
Syntax is **double** or **triple** **underscores** ex: `__underlined word__`. With this option enabled, underscores are no longer parses into `<em>` and `<strong>`.
|
||||
|
||||
* **completeHTMLDocument**: (boolean) [default false] Outputs a complete html document,
|
||||
including `<html>`, `<head>` and `<body>` tags' instead of an HTML fragment. (since v.1.8.5)
|
||||
|
||||
* **metadata**: (boolean) [default false] Enable support for document metadata (defined at the top of the document
|
||||
between `«««` and `»»»` or between `---` and `---`). (since v.1.8.5)
|
||||
|
||||
**NOTE**: Please note that until **version 1.6.0**, all of these options are ***DISABLED*** by default in the cli tool.
|
||||
|
||||
|
||||
|
||||
## Flavors
|
||||
|
||||
You can also use flavors or presets to set the correct options automatically, so that showdown behaves like popular markdown flavors.
|
||||
|
|
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"name": "showdown",
|
||||
"version": "1.8.3",
|
||||
"version": "1.8.5",
|
||||
"description": "A Markdown to HTML converter written in Javascript",
|
||||
"author": "Estevão Santos",
|
||||
"homepage": "http://showdownjs.github.io/showdown/",
|
||||
"homepage": "http://showdownjs.com/",
|
||||
"keywords": [
|
||||
"markdown",
|
||||
"converter"
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,88 @@
|
|||
# Performance Tests for showdown
|
||||
|
||||
|
||||
## [version 1.9.0](https://github.com/showdownjs/showdown/tree/1.9.0)
|
||||
|
||||
### Test Suite: Basic (50 cycles)
|
||||
| test | avgTime | max | min |
|
||||
|:-----|--------:|----:|----:|
|
||||
|Simple "Hello World"|0.476|9.945|0.088|
|
||||
|performance.testfile.md|32.208|61.885|28.234|
|
||||
|
||||
### Test Suite: subParsers (20 cycles)
|
||||
| test | avgTime | max | min |
|
||||
|:-----|--------:|----:|----:|
|
||||
|hashHTMLBlocks|5.827|23.030|2.429|
|
||||
|anchors|0.363|0.636|0.294|
|
||||
|autoLinks|0.120|0.319|0.071|
|
||||
|blockQuotes|2.884|6.237|2.040|
|
||||
|codeBlocks|0.290|1.131|0.189|
|
||||
|codeSpans|0.314|0.875|0.234|
|
||||
|detab|0.095|0.141|0.086|
|
||||
|encodeAmpsAndAngles|0.155|1.186|0.095|
|
||||
|encodeBackslashEscapes|0.087|0.144|0.069|
|
||||
|encodeCode|0.918|1.279|0.865|
|
||||
|escapeSpecialCharsWithinTagAttributes|0.245|0.711|0.156|
|
||||
|githubCodeBlocks|0.160|0.291|0.142|
|
||||
|hashBlock|0.043|0.067|0.038|
|
||||
|hashElement|0.003|0.035|0.000|
|
||||
|hashHTMLSpans|4.273|6.304|3.983|
|
||||
|hashPreCodeTags|0.133|0.344|0.110|
|
||||
|headers|1.454|3.874|1.098|
|
||||
|horizontalRule|0.230|0.300|0.202|
|
||||
|images|0.191|0.476|0.135|
|
||||
|italicsAndBold|0.310|0.866|0.236|
|
||||
|lists|3.135|4.249|2.662|
|
||||
|outdent|0.167|0.262|0.140|
|
||||
|paragraphs|6.383|7.885|5.680|
|
||||
|spanGamut|4.106|5.310|3.698|
|
||||
|strikethrough|0.005|0.087|0.000|
|
||||
|stripLinkDefinitions|0.245|0.376|0.221|
|
||||
|tables|0.003|0.049|0.001|
|
||||
|unescapeSpecialChars|0.010|0.057|0.007|
|
||||
|
||||
|
||||
## [version 1.8.4](https://github.com/showdownjs/showdown/tree/1.8.4)
|
||||
|
||||
### Test Suite: Basic (50 cycles)
|
||||
| test | avgTime | max | min |
|
||||
|:-----|--------:|----:|----:|
|
||||
|Simple "Hello World"|0.736|11.076|0.117|
|
||||
|performance.testfile.md|32.918|62.427|27.941|
|
||||
|
||||
### Test Suite: subParsers (20 cycles)
|
||||
| test | avgTime | max | min |
|
||||
|:-----|--------:|----:|----:|
|
||||
|hashHTMLBlocks|5.260|17.333|2.340|
|
||||
|anchors|0.522|2.898|0.307|
|
||||
|autoLinks|0.124|0.300|0.071|
|
||||
|blockQuotes|2.244|3.333|2.015|
|
||||
|codeBlocks|0.244|0.817|0.190|
|
||||
|codeSpans|0.354|1.201|0.243|
|
||||
|detab|0.096|0.143|0.088|
|
||||
|encodeAmpsAndAngles|0.138|0.198|0.096|
|
||||
|encodeBackslashEscapes|0.093|0.184|0.071|
|
||||
|encodeCode|0.961|1.611|0.858|
|
||||
|escapeSpecialCharsWithinTagAttributes|0.252|0.520|0.158|
|
||||
|githubCodeBlocks|0.262|0.390|0.161|
|
||||
|hashBlock|0.052|0.129|0.037|
|
||||
|hashElement|0.003|0.040|0.000|
|
||||
|hashHTMLSpans|4.240|4.673|4.044|
|
||||
|hashPreCodeTags|0.134|0.337|0.113|
|
||||
|headers|1.412|4.475|1.077|
|
||||
|horizontalRule|0.358|2.686|0.196|
|
||||
|images|0.184|0.480|0.130|
|
||||
|italicsAndBold|0.300|0.458|0.234|
|
||||
|lists|3.074|4.651|2.626|
|
||||
|outdent|0.204|0.931|0.137|
|
||||
|paragraphs|6.406|8.020|5.821|
|
||||
|spanGamut|4.136|6.038|3.840|
|
||||
|strikethrough|0.007|0.132|0.000|
|
||||
|stripLinkDefinitions|0.248|0.403|0.217|
|
||||
|tables|0.003|0.040|0.001|
|
||||
|unescapeSpecialChars|0.009|0.039|0.007|
|
||||
|
||||
|
||||
## [version 1.8.3](https://github.com/showdownjs/showdown/tree/1.8.3)
|
||||
|
||||
### Test Suite: Basic (50 cycles)
|
||||
|
|
|
@ -43,7 +43,17 @@ showdown.Converter = function (converterOptions) {
|
|||
/**
|
||||
* The flavor set in this converter
|
||||
*/
|
||||
setConvFlavor = setFlavor;
|
||||
setConvFlavor = setFlavor,
|
||||
|
||||
/**
|
||||
* Metadata of the document
|
||||
* @type {{parsed: {}, raw: string, format: string}}
|
||||
*/
|
||||
metadata = {
|
||||
parsed: {},
|
||||
raw: '',
|
||||
format: ''
|
||||
};
|
||||
|
||||
_constructor();
|
||||
|
||||
|
@ -255,7 +265,12 @@ showdown.Converter = function (converterOptions) {
|
|||
langExtensions: langExtensions,
|
||||
outputModifiers: outputModifiers,
|
||||
converter: this,
|
||||
ghCodeBlocks: []
|
||||
ghCodeBlocks: [],
|
||||
metadata: {
|
||||
parsed: {},
|
||||
raw: '',
|
||||
format: ''
|
||||
}
|
||||
};
|
||||
|
||||
// This lets us use ¨ trema as an escape char to avoid md5 hashes
|
||||
|
@ -299,6 +314,7 @@ showdown.Converter = function (converterOptions) {
|
|||
});
|
||||
|
||||
// run the sub parsers
|
||||
text = showdown.subParser('metadata')(text, options, globals);
|
||||
text = showdown.subParser('hashPreCodeTags')(text, options, globals);
|
||||
text = showdown.subParser('githubCodeBlocks')(text, options, globals);
|
||||
text = showdown.subParser('hashHTMLBlocks')(text, options, globals);
|
||||
|
@ -314,11 +330,16 @@ showdown.Converter = function (converterOptions) {
|
|||
// attacklab: Restore tremas
|
||||
text = text.replace(/¨T/g, '¨');
|
||||
|
||||
// render a complete html document instead of a partial if the option is enabled
|
||||
text = showdown.subParser('completeHTMLDocument')(text, options, globals);
|
||||
|
||||
// Run output modifiers
|
||||
showdown.helper.forEach(outputModifiers, function (ext) {
|
||||
text = showdown.subParser('runExtension')(ext, text, options, globals);
|
||||
});
|
||||
|
||||
// update metadata
|
||||
metadata = globals.metadata;
|
||||
return text;
|
||||
};
|
||||
|
||||
|
@ -928,4 +949,50 @@ showdown.Converter = function (converterOptions) {
|
|||
output: outputModifiers
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the metadata of the previously parsed document
|
||||
* @param raw
|
||||
* @returns {string|{}}
|
||||
*/
|
||||
this.getMetadata = function (raw) {
|
||||
if (raw) {
|
||||
return metadata.raw;
|
||||
} else {
|
||||
return metadata.parsed;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the metadata format of the previously parsed document
|
||||
* @returns {string}
|
||||
*/
|
||||
this.getMetadataFormat = function () {
|
||||
return metadata.format;
|
||||
};
|
||||
|
||||
/**
|
||||
* Private: set a single key, value metadata pair
|
||||
* @param {string} key
|
||||
* @param {string} value
|
||||
*/
|
||||
this._setMetadataPair = function (key, value) {
|
||||
metadata.parsed[key] = value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Private: set metadata format
|
||||
* @param {string} format
|
||||
*/
|
||||
this._setMetadataFormat = function (format) {
|
||||
metadata.format = format;
|
||||
};
|
||||
|
||||
/**
|
||||
* Private: set metadata raw text
|
||||
* @param {string} raw
|
||||
*/
|
||||
this._setMetadataRaw = function (raw) {
|
||||
metadata.raw = raw;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -150,6 +150,16 @@ function getDefaultOpts (simple) {
|
|||
defaultValue: false,
|
||||
description: 'Enable support for underline. Syntax is double or triple underscores: `__underline word__`. With this option enabled, underscores no longer parses into `<em>` and `<strong>`',
|
||||
type: 'boolean'
|
||||
},
|
||||
completeHTMLDocument: {
|
||||
defaultValue: false,
|
||||
description: 'Outputs a complete html document, including `<html>`, `<head>` and `<body>` tags',
|
||||
type: 'boolean'
|
||||
},
|
||||
metadata: {
|
||||
defaultValue: false,
|
||||
description: 'Enable support for document metadata (defined at the top of the document between `«««` and `»»»` or between `---` and `---`).',
|
||||
type: 'boolean'
|
||||
}
|
||||
};
|
||||
if (simple === false) {
|
||||
|
|
62
src/subParsers/makehtml/completeHTMLDocument.js
Normal file
62
src/subParsers/makehtml/completeHTMLDocument.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
/**
|
||||
* Turn Markdown link shortcuts into XHTML <a> tags.
|
||||
*/
|
||||
showdown.subParser('completeHTMLDocument', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
if (!options.completeHTMLDocument) {
|
||||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('completeHTMLDocument.before', text, options, globals);
|
||||
|
||||
var doctype = 'html',
|
||||
doctypeParsed = '<!DOCTYPE HTML>\n',
|
||||
title = '',
|
||||
charset = '<meta charset="utf-8">\n',
|
||||
lang = '',
|
||||
metadata = '';
|
||||
|
||||
if (typeof globals.metadata.parsed.doctype !== 'undefined') {
|
||||
doctypeParsed = '<!DOCTYPE ' + globals.metadata.parsed.doctype + '>\n';
|
||||
doctype = globals.metadata.parsed.doctype.toString().toLowerCase();
|
||||
if (doctype === 'html' || doctype === 'html5') {
|
||||
charset = '<meta charset="utf-8">';
|
||||
}
|
||||
}
|
||||
|
||||
for (var meta in globals.metadata.parsed) {
|
||||
if (globals.metadata.parsed.hasOwnProperty(meta)) {
|
||||
switch (meta.toLowerCase()) {
|
||||
case 'doctype':
|
||||
break;
|
||||
|
||||
case 'title':
|
||||
title = '<title>' + globals.metadata.parsed.title + '</title>\n';
|
||||
break;
|
||||
|
||||
case 'charset':
|
||||
if (doctype === 'html' || doctype === 'html5') {
|
||||
charset = '<meta charset="' + globals.metadata.parsed.charset + '">\n';
|
||||
} else {
|
||||
charset = '<meta name="charset" content="' + globals.metadata.parsed.charset + '">\n';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'language':
|
||||
case 'lang':
|
||||
lang = ' lang="' + globals.metadata.parsed[meta] + '"';
|
||||
metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n';
|
||||
break;
|
||||
|
||||
default:
|
||||
metadata += '<meta name="' + meta + '" content="' + globals.metadata.parsed[meta] + '">\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
return text;
|
||||
});
|
|
@ -154,7 +154,7 @@ showdown.subParser('lists', function (text, options, globals) {
|
|||
style = styleStartNumber(list, listType);
|
||||
if (pos !== -1) {
|
||||
// slice
|
||||
result += '\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
|
||||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt.slice(0, pos), !!trimTrailing) + '</' + listType + '>\n';
|
||||
|
||||
// invert counterType and listType
|
||||
listType = (listType === 'ul') ? 'ol' : 'ul';
|
||||
|
@ -163,12 +163,12 @@ showdown.subParser('lists', function (text, options, globals) {
|
|||
//recurse
|
||||
parseCL(txt.slice(pos));
|
||||
} else {
|
||||
result += '\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
|
||||
result += '\n\n<' + listType + style + '>\n' + processListItems(txt, !!trimTrailing) + '</' + listType + '>\n';
|
||||
}
|
||||
})(list);
|
||||
} else {
|
||||
var style = styleStartNumber(list, listType);
|
||||
result = '\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
|
||||
result = '\n\n<' + listType + style + '>\n' + processListItems(list, !!trimTrailing) + '</' + listType + '>\n';
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
49
src/subParsers/makehtml/metadata.js
Normal file
49
src/subParsers/makehtml/metadata.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
/**
|
||||
* Parse metadata at the top of the document
|
||||
*/
|
||||
showdown.subParser('metadata', function (text, options, globals) {
|
||||
'use strict';
|
||||
|
||||
if (!options.metadata) {
|
||||
return text;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('metadata.before', text, options, globals);
|
||||
|
||||
function parseMetadataContents (content) {
|
||||
// raw is raw so it's not changed in any way
|
||||
globals.metadata.raw = content;
|
||||
|
||||
// escape chars forbidden in html attributes
|
||||
// double quotes
|
||||
content = content
|
||||
// ampersand first
|
||||
.replace(/&/g, '&')
|
||||
// double quotes
|
||||
.replace(/"/g, '"');
|
||||
|
||||
content = content.replace(/\n {4}/g, ' ');
|
||||
content.replace(/^([\S ]+): +([\s\S]+?)$/gm, function (wm, key, value) {
|
||||
globals.metadata.parsed[key] = value;
|
||||
return '';
|
||||
});
|
||||
}
|
||||
|
||||
text = text.replace(/^\s*«««+(\S*?)\n([\s\S]+?)\n»»»+\n/, function (wholematch, format, content) {
|
||||
parseMetadataContents(content);
|
||||
return '¨M';
|
||||
});
|
||||
|
||||
text = text.replace(/^\s*---+(\S*?)\n([\s\S]+?)\n---+\n/, function (wholematch, format, content) {
|
||||
if (format) {
|
||||
globals.metadata.format = format;
|
||||
}
|
||||
parseMetadataContents(content);
|
||||
return '¨M';
|
||||
});
|
||||
|
||||
text = text.replace(/¨M/g, '');
|
||||
|
||||
text = globals.converter._dispatch('metadata.after', text, options, globals);
|
||||
return text;
|
||||
});
|
|
@ -5,9 +5,9 @@ showdown.subParser('tables', function (text, options, globals) {
|
|||
return text;
|
||||
}
|
||||
|
||||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|<ol|<ul|¨0)/gm,
|
||||
var tableRgx = /^ {0,3}\|?.+\|.+\n {0,3}\|?[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*:?[ \t]*(?:[-=]){2,}[\s\S]+?(?:\n\n|¨0)/gm,
|
||||
//singeColTblRgx = /^ {0,3}\|.+\|\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n(?: {0,3}\|.+\|\n)+(?:\n\n|¨0)/gm;
|
||||
singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|<ol|<ul|¨0)/gm;
|
||||
singeColTblRgx = /^ {0,3}\|.+\|[ \t]*\n {0,3}\|[ \t]*:?[ \t]*(?:[-=]){2,}[ \t]*:?[ \t]*\|[ \t]*\n( {0,3}\|.+\|[ \t]*\n)*(?:\n|¨0)/gm;
|
||||
|
||||
function parseStyles (sLine) {
|
||||
if (/^:[ \t]*--*$/.test(sLine)) {
|
||||
|
@ -24,7 +24,7 @@ showdown.subParser('tables', function (text, options, globals) {
|
|||
function parseHeaders (header, style) {
|
||||
var id = '';
|
||||
header = header.trim();
|
||||
// support both tablesHeaderId and tableHeaderId due to error in documention so we don't break backwards compatibility
|
||||
// support both tablesHeaderId and tableHeaderId due to error in documentation so we don't break backwards compatibility
|
||||
if (options.tablesHeaderId || options.tableHeaderId) {
|
||||
id = ' id="' + header.replace(/ /g, '_').toLowerCase() + '"';
|
||||
}
|
||||
|
@ -125,24 +125,11 @@ showdown.subParser('tables', function (text, options, globals) {
|
|||
return buildTable(headers, cells);
|
||||
}
|
||||
|
||||
function hackFixTableFollowedByList (rawTable) {
|
||||
var lastChars = rawTable.slice(-3);
|
||||
if (lastChars === '<ol' || lastChars === '<ul') {
|
||||
rawTable = rawTable.slice(0, -3) + '\n\n' + rawTable.slice(-3);
|
||||
}
|
||||
return rawTable;
|
||||
}
|
||||
|
||||
text = globals.converter._dispatch('tables.before', text, options, globals);
|
||||
|
||||
// find escaped pipe characters
|
||||
text = text.replace(/\\(\|)/g, showdown.helper.escapeCharactersCallback);
|
||||
|
||||
// hackfix issue #443. Due to lists only having a linebreak before them, we need to manually insert a linebreak to prevent
|
||||
// tables not being parsed when followed by a list
|
||||
text = text.replace(tableRgx, hackFixTableFollowedByList);
|
||||
text = text.replace(singeColTblRgx, hackFixTableFollowedByList);
|
||||
|
||||
// parse multi column tables
|
||||
text = text.replace(tableRgx, parseTable);
|
||||
|
||||
|
|
15
test/features/completeHTMLOutput/simple.html
Normal file
15
test/features/completeHTMLOutput/simple.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
</head>
|
||||
<body>
|
||||
<p>This is a <strong>markdown</strong> file</p>
|
||||
<p>Converted into a full HTML document</p>
|
||||
<ul>
|
||||
<li>this</li>
|
||||
<li>is</li>
|
||||
<li>awesome</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
7
test/features/completeHTMLOutput/simple.md
Normal file
7
test/features/completeHTMLOutput/simple.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
This is a **markdown** file
|
||||
|
||||
Converted into a full HTML document
|
||||
|
||||
- this
|
||||
- is
|
||||
- awesome
|
8
test/features/metadata/dashes-conflict.html
Normal file
8
test/features/metadata/dashes-conflict.html
Normal file
|
@ -0,0 +1,8 @@
|
|||
<p><strong>some</strong> markdown text</p>
|
||||
<ul>
|
||||
<li>a list</li>
|
||||
<li>another list ---</li>
|
||||
<li>and stuff</li>
|
||||
</ul>
|
||||
<p>a paragraph --- with dashes</p>
|
||||
<hr />
|
16
test/features/metadata/dashes-conflict.md
Normal file
16
test/features/metadata/dashes-conflict.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
|
||||
---
|
||||
**some** markdown text
|
||||
|
||||
- a list
|
||||
- another list ---
|
||||
- and stuff
|
||||
|
||||
a paragraph --- with dashes
|
||||
|
||||
---
|
16
test/features/metadata/embeded-in-output.html
Normal file
16
test/features/metadata/embeded-in-output.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>This is the document title</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="language" content="en">
|
||||
<meta name="author" content="Tivie">
|
||||
<meta name="contributors" content="John, Mary, Steve">
|
||||
<meta name="description" content="This is a long text and so it spans on multiple lines. It must be indented, for showdown to parse it correctly. Markdown **such as bold** is not parsed and it will be rendered as plain text.">
|
||||
<meta name="date" content="01-01-2010">
|
||||
<meta name="keywords" content="foo, bar, baz">
|
||||
</head>
|
||||
<body>
|
||||
<p><strong>some</strong> markdown text</p>
|
||||
</body>
|
||||
</html>
|
16
test/features/metadata/embeded-in-output.md
Normal file
16
test/features/metadata/embeded-in-output.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
«««
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown **such as bold** is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
keywords: foo, bar, baz
|
||||
»»»
|
||||
|
||||
**some** markdown text
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>This is the document title</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="language" content="en">
|
||||
<meta name="author" content="Tivie">
|
||||
<meta name="contributors" content="John, Mary, Steve">
|
||||
<meta name="keywords" content="foo, bar, baz">
|
||||
</head>
|
||||
<body>
|
||||
<hr />
|
||||
<p>description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown <strong>such as bold</strong> is not parsed
|
||||
and it will be rendered as plain text.</p>
|
||||
<h2 id="date01012010">date: 01-01-2010</h2>
|
||||
<p><strong>some</strong> markdown text</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
«««
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
keywords: foo, bar, baz
|
||||
»»»
|
||||
---
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown **such as bold** is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
---
|
||||
|
||||
**some** markdown text
|
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>This is the document title</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="language" content="en">
|
||||
<meta name="author" content="Tivie">
|
||||
<meta name="contributors" content="John, Mary, Steve">
|
||||
<meta name="keywords" content="foo, bar, baz">
|
||||
</head>
|
||||
<body>
|
||||
<hr />
|
||||
<p>description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown <strong>such as bold</strong> is not parsed
|
||||
and it will be rendered as plain text.</p>
|
||||
<h2 id="date01012010">date: 01-01-2010</h2>
|
||||
<p><strong>some</strong> markdown text</p>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
keywords: foo, bar, baz
|
||||
---
|
||||
---
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown **such as bold** is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
---
|
||||
|
||||
**some** markdown text
|
15
test/features/metadata/ignore-metadata.html
Normal file
15
test/features/metadata/ignore-metadata.html
Normal file
|
@ -0,0 +1,15 @@
|
|||
<hr />
|
||||
<p>title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown <strong>such as bold</strong> is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
keywords: foo, bar, baz</p>
|
||||
<hr />
|
||||
<p><strong>some</strong> markdown text</p>
|
18
test/features/metadata/ignore-metadata.md
Normal file
18
test/features/metadata/ignore-metadata.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown **such as bold** is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
keywords: foo, bar, baz
|
||||
|
||||
---
|
||||
|
||||
**some** markdown text
|
1
test/features/metadata/simple-angled-for-method.html
Normal file
1
test/features/metadata/simple-angled-for-method.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p>some <strong>text</strong></p>
|
6
test/features/metadata/simple-angled-for-method.md
Normal file
6
test/features/metadata/simple-angled-for-method.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
«««
|
||||
foo: bar
|
||||
baz: bazinga
|
||||
»»»
|
||||
|
||||
some **text**
|
1
test/features/metadata/simple-angled-quotes.html
Normal file
1
test/features/metadata/simple-angled-quotes.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p><strong>some</strong> markdown text</p>
|
16
test/features/metadata/simple-angled-quotes.md
Normal file
16
test/features/metadata/simple-angled-quotes.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
«««
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown **such as bold** is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
keywords: foo, bar, baz
|
||||
»»»
|
||||
|
||||
**some** markdown text
|
1
test/features/metadata/simple-three-dashes.html
Normal file
1
test/features/metadata/simple-three-dashes.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p><strong>some</strong> markdown text</p>
|
16
test/features/metadata/simple-three-dashes.md
Normal file
16
test/features/metadata/simple-three-dashes.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
title: This is the document title
|
||||
language: en
|
||||
author: Tivie
|
||||
contributors: John, Mary, Steve
|
||||
description: This is a long text and so it
|
||||
spans on multiple lines.
|
||||
It must be indented,
|
||||
for showdown to parse it correctly.
|
||||
Markdown **such as bold** is not parsed
|
||||
and it will be rendered as plain text.
|
||||
date: 01-01-2010
|
||||
keywords: foo, bar, baz
|
||||
---
|
||||
|
||||
**some** markdown text
|
1
test/features/metadata/simple-with-format.html
Normal file
1
test/features/metadata/simple-with-format.html
Normal file
|
@ -0,0 +1 @@
|
|||
<p><strong>some</strong> markdown text</p>
|
9
test/features/metadata/simple-with-format.md
Normal file
9
test/features/metadata/simple-with-format.md
Normal file
|
@ -0,0 +1,9 @@
|
|||
---YAML
|
||||
foo: bar
|
||||
baz:
|
||||
- bazinga
|
||||
- bling
|
||||
- blang
|
||||
---
|
||||
|
||||
**some** markdown text
|
|
@ -0,0 +1,14 @@
|
|||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:right;">h1</th>
|
||||
<th style="text-align:left;">h2</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align:right;">asdf</td>
|
||||
<td style="text-align:left;">one <code>two <ol> three</code></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
|
@ -0,0 +1,3 @@
|
|||
| h1 | h2 |
|
||||
|--------:|:---------------------|
|
||||
| asdf | one `two <ol> three` |
|
|
@ -27,6 +27,20 @@ describe('showdown.Converter', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('metadata methods', function () {
|
||||
var converter = new showdown.Converter();
|
||||
|
||||
it('_setMetadataPair() should set foo to bar', function () {
|
||||
converter._setMetadataPair('foo', 'bar');
|
||||
converter.getMetadata().should.eql({foo: 'bar'});
|
||||
});
|
||||
|
||||
it('_setMetadata should set metadata to {baz: bazinga}', function () {
|
||||
converter._setMetadataRaw('{baz: bazinga}');
|
||||
converter.getMetadata(true).should.eql('{baz: bazinga}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('converter.setFlavor()', function () {
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,4 +59,41 @@ describe('showdown.Converter', function () {
|
|||
html.should.equal(expectedHtml);
|
||||
});
|
||||
});
|
||||
|
||||
describe('makeHtml() with option metadata', function () {
|
||||
var converter = new showdown.Converter(),
|
||||
text1 =
|
||||
'---SIMPLE\n' +
|
||||
'foo: bar\n' +
|
||||
'baz: bazinga\n' +
|
||||
'---\n',
|
||||
text2 =
|
||||
'---TIVIE\n' +
|
||||
'a: b\n' +
|
||||
'c: 123\n' +
|
||||
'---\n';
|
||||
|
||||
it('should correctly set metadata', function () {
|
||||
converter.setOption('metadata', true);
|
||||
|
||||
var expectedHtml = '',
|
||||
expectedObj = {foo: 'bar', baz: 'bazinga'},
|
||||
expectedRaw = 'foo: bar\nbaz: bazinga',
|
||||
expectedFormat = 'SIMPLE';
|
||||
converter.makeHtml(text1).should.equal(expectedHtml);
|
||||
converter.getMetadata().should.eql(expectedObj);
|
||||
converter.getMetadata(true).should.equal(expectedRaw);
|
||||
converter.getMetadataFormat().should.equal(expectedFormat);
|
||||
});
|
||||
|
||||
it('consecutive calls should reset metadata', function () {
|
||||
converter.makeHtml(text2);
|
||||
var expectedObj = {a: 'b', c: '123'},
|
||||
expectedRaw = 'a: b\nc: 123',
|
||||
expectedFormat = 'TIVIE';
|
||||
converter.getMetadata().should.eql(expectedObj);
|
||||
converter.getMetadata(true).should.equal(expectedRaw);
|
||||
converter.getMetadataFormat().should.equal(expectedFormat);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,7 +14,9 @@ var bootstrap = require('../bootstrap.js'),
|
|||
emojisSuite = bootstrap.getTestSuite('test/features/emojis/'),
|
||||
underlineSuite = bootstrap.getTestSuite('test/features/underline/'),
|
||||
literalMidWordUnderscoresSuite = bootstrap.getTestSuite('test/features/literalMidWordUnderscores/'),
|
||||
literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/');
|
||||
literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/'),
|
||||
completeHTMLOutputSuite = bootstrap.getTestSuite('test/features/completeHTMLOutput/'),
|
||||
metadataSuite = bootstrap.getTestSuite('test/features/metadata/');
|
||||
|
||||
describe('makeHtml() features testsuite', function () {
|
||||
'use strict';
|
||||
|
@ -231,4 +233,35 @@ describe('makeHtml() features testsuite', function () {
|
|||
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/** test completeHTMLDocument option **/
|
||||
describe('completeHTMLDocument option', function () {
|
||||
var converter,
|
||||
suite = completeHTMLOutputSuite;
|
||||
for (var i = 0; i < suite.length; ++i) {
|
||||
converter = new showdown.Converter({completeHTMLDocument: true});
|
||||
|
||||
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||
}
|
||||
});
|
||||
|
||||
/** test metadata option **/
|
||||
describe('metadata option', function () {
|
||||
var converter,
|
||||
suite = metadataSuite;
|
||||
|
||||
for (var i = 0; i < suite.length; ++i) {
|
||||
if (suite[i].name === 'embeded-in-output' ||
|
||||
suite[i].name === 'embeded-two-consecutive-metadata-blocks' ||
|
||||
suite[i].name === 'embeded-two-consecutive-metadata-blocks-different-symbols') {
|
||||
converter = new showdown.Converter({metadata: true, completeHTMLDocument: true});
|
||||
} else if (suite[i].name === 'ignore-metadata') {
|
||||
converter = new showdown.Converter({metadata: false});
|
||||
} else {
|
||||
converter = new showdown.Converter({metadata: true});
|
||||
}
|
||||
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user