Skip to content

Commit 53a0097

Browse files
committed
adds showdown as a parsing possibility
1 parent dd4fea4 commit 53a0097

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

build/make_default_helpers.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var escape = require('escape-html');
66
var striptags = require('striptags');
77
var DocMapInfo = require("../doc-map-info");
88
var unescapeHTML = require("unescape-html");
9-
9+
var makeShowdown = require("../showdown_to_html");
1010

1111
function escapeOnlySingleElements(text) {
1212
//This could be an alternate way of detecting if markdown escaped
@@ -63,6 +63,12 @@ var httpRegExp = /^http/;
6363
module.exports = function(docMap, config, getCurrent, Handlebars){
6464
var docMapInfo = new DocMapInfo(docMap, getCurrent);
6565

66+
var showdown_to_html;
67+
if(config.showdown) {
68+
showdown_to_html = makeShowdown(config.showdown);
69+
}
70+
71+
6672
var urlTo = function(name){
6773
var currentDir = path.dirname( path.join(config.dest, docsFilename( getCurrent(), config)) );
6874
var toPath = path.join(config.dest,docsFilename( docMap[name] || name, config));
@@ -382,7 +388,11 @@ module.exports = function(docMap, config, getCurrent, Handlebars){
382388
return value;
383389
},
384390
makeHtml: function(content){
385-
return stmd_to_html(content);
391+
if(config.showdown) {
392+
return showdown_to_html(content)
393+
} else {
394+
return stmd_to_html(content);
395+
}
386396
},
387397
renderAsTemplate: function(content) {
388398
var templateRender = config.templateRender || getCurrent().templateRender;

html_test.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,34 @@ describe("bit-docs-generate-html", function(){
286286
assert.ok(typeof siteConfig.html.dependencies === "object", "is an object")
287287
}
288288
});
289-
})
289+
});
290+
291+
it("showdown works", function(){
292+
this.timeout(240000);
293+
return rmdir(path.join(__dirname, "test", "tmp")).then(function(){
294+
var options = {
295+
dest: path.join(__dirname, "test", "tmp"),
296+
parent: "index",
297+
showdown: {
298+
tasklists: true
299+
}
300+
};
301+
302+
var docMap = Q.Promise(function(resolve){
303+
resolve(_.assign({
304+
index: {
305+
name: "index",
306+
type: "page",
307+
body: "- [x] first\n- [ ] end"
308+
}
309+
}));
310+
});
311+
312+
return html.generate(docMap,options);
313+
}).then(function(){
314+
return readFile(path.join(__dirname, "test", "tmp", "index.html"));
315+
}).then(function(data){
316+
assert.ok( (""+data).indexOf('<input type="checkbox"') !== -1, "has checkbox" );
317+
});
318+
});
290319
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"lodash": "~4.13.1",
3535
"md5": "2.1.0",
3636
"q": "^1.5.0",
37+
"showdown": "^1.9.0",
3738
"steal-tools": "^1.8.0",
3839
"striptags": "^2.1.1",
3940
"unescape-html": "^1.0.0"

showdown_to_html.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var showdown = require("showdown");
2+
3+
module.exports = function(showdownOptions){
4+
var converter = new showdown.Converter(showdownOptions);
5+
return function(content){
6+
return converter.makeHtml(content);
7+
};
8+
};

0 commit comments

Comments
 (0)