Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions libs/htmlWhitelistPost.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"allowedTags": [
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"h7",
"h8",
"p",
"div",
"blockquote",
"pre",
"b",
"i",
"strong",
"em",
"tt",
"code",
"ins",
"del",
"sup",
"sub",
"kbd",
"samp",
"q",
"var",
"ol",
"ul",
"li",
"dl",
"dt",
"dd",
"table",
"thead",
"tbody",
"tfoot",
"tr",
"td",
"th",
"br",
"hr",
"ruby",
"rt",
"rp"
],
"allowedAttributes": {
"a": [
"href"
],
"img": [
"src"
],
"div": [
"itemscope",
"itemtype"
]
},
"selfClosing": [
"img",
"br",
"hr",
"area",
"base",
"basefont",
"input",
"link",
"meta"
],
"allowedSchemes": [
"http",
"https",
"mailto"
]
}
7 changes: 4 additions & 3 deletions libs/markdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var marked = require('marked');
var hljs = require('highlight.js');
var xss = require('simple-xss');
var sanitizeHtml = require('sanitize-html');
var htmlWhitelistPost = require('./htmlWhitelistPost.json');
var renderer = new marked.Renderer();

// Automatically generate an anchor for each header
Expand Down Expand Up @@ -33,11 +34,11 @@ marked.setOptions({
tables: true,
breaks: true,
pedantic: false,
sanitize: false, // we use xss to sanitize HTML
sanitize: false, // we use sanitize-html to sanitize HTML
smartLists: true,
smartypants: false
});

exports.renderMd = function (text) {
return xss(marked(text));
return marked(sanitizeHtml(text), htmlWhitelistPost);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"async": "*",
"aws-sdk": "*",
"toobusy-js": "*",
"simple-xss": "*",
"sanitize-html": "*",
"underscore": "*",
"moment": "*",
"github": "*",
Expand Down