Skip to content

Commit a8427c9

Browse files
committed
feat(completeHTMLOutput): add option to output a complete HTML document
1 parent cc19d9b commit a8427c9

File tree

10 files changed

+89
-6
lines changed

10 files changed

+89
-6
lines changed

dist/showdown.js

+27-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/converter.js

+3
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ showdown.Converter = function (converterOptions) {
314314
// attacklab: Restore tremas
315315
text = text.replace(/¨T/g, '¨');
316316

317+
// render a complete html document instead of a partial if the option is enabled
318+
text = showdown.subParser('completeHTMLOutput')(text, options, globals);
319+
317320
// Run output modifiers
318321
showdown.helper.forEach(outputModifiers, function (ext) {
319322
text = showdown.subParser('runExtension')(ext, text, options, globals);

src/options.js

+5
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,11 @@ function getDefaultOpts (simple) {
150150
defaultValue: false,
151151
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>`',
152152
type: 'boolean'
153+
},
154+
completeHTMLOutput: {
155+
defaultValue: false,
156+
description: 'Outputs a complete html document, including `<html>`, `<head>` and `<body>` tags',
157+
type: 'boolean'
153158
}
154159
};
155160
if (simple === false) {

src/subParsers/completeHTMLOutput.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Turn Markdown link shortcuts into XHTML <a> tags.
3+
*/
4+
showdown.subParser('completeHTMLOutput', function (text, options, globals) {
5+
'use strict';
6+
7+
if (!options.completeHTMLOutput) {
8+
return text;
9+
}
10+
11+
text = globals.converter._dispatch('completeHTMLOutput.before', text, options, globals);
12+
13+
text = '<html>\n<head>\n<meta charset="UTF-8">\n</head>\n<body>\n' + text.trim() + '\n</body>\n</html>';
14+
15+
text = globals.converter._dispatch('completeHTMLOutput.after', text, options, globals);
16+
return text;
17+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<meta charset="UTF-8">
4+
</head>
5+
<body>
6+
<p>This is a <strong>markdown</strong> file</p>
7+
<p>Converted into a full HTML document</p>
8+
<ul>
9+
<li>this</li>
10+
<li>is</li>
11+
<li>awesome</li>
12+
</ul>
13+
</body>
14+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This is a **markdown** file
2+
3+
Converted into a full HTML document
4+
5+
- this
6+
- is
7+
- awesome

test/node/testsuite.features.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ var bootstrap = require('../bootstrap.js'),
1414
emojisSuite = bootstrap.getTestSuite('test/features/emojis/'),
1515
underlineSuite = bootstrap.getTestSuite('test/features/underline/'),
1616
literalMidWordUnderscoresSuite = bootstrap.getTestSuite('test/features/literalMidWordUnderscores/'),
17-
literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/');
17+
literalMidWordAsterisksSuite = bootstrap.getTestSuite('test/features/literalMidWordAsterisks/'),
18+
completeHTMLOutputSuite = bootstrap.getTestSuite('test/features/completeHTMLOutput/');
1819

1920
describe('makeHtml() features testsuite', function () {
2021
'use strict';
@@ -231,4 +232,14 @@ describe('makeHtml() features testsuite', function () {
231232
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
232233
}
233234
});
235+
236+
/** test completeHTMLOutput option **/
237+
describe('completeHTMLOutput option', function () {
238+
var converter,
239+
suite = completeHTMLOutputSuite;
240+
for (var i = 0; i < suite.length; ++i) {
241+
converter = new showdown.Converter({completeHTMLOutput: true});
242+
it(suite[i].name.replace(/-/g, ' '), assertion(suite[i], converter));
243+
}
244+
});
234245
});

0 commit comments

Comments
 (0)