From 9d0d851c2e60711e309d0fb00d9672edfb78a9b1 Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Wed, 13 Jan 2016 13:10:46 +0900 Subject: [PATCH] markdown strike bug fixed, no emoji shortcut, checkbox syntax added --- browser/components/MarkdownPreview.js | 8 +++++++- browser/lib/markdown.js | 5 ++++- browser/styles/mixins/marked.styl | 2 +- package.json | 1 + webpack-skeleton.js | 3 ++- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 352a7c91..50e521ac 100644 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -14,7 +14,7 @@ const katex = window.katex const sanitizeOpts = { allowedTags: [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'p', 'a', 'ul', 'ol', 'nl', 'li', 'b', 'i', 'strong', 'em', 'strike', 'code', 'hr', 'br', 'div', - 'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'img', 'span', 'cite', 'del', 'u', 'sub', 'sup' ], + 'table', 'thead', 'caption', 'tbody', 'tr', 'th', 'td', 'pre', 'img', 'span', 'cite', 'del', 'u', 'sub', 'sup', 's', 'input', 'label' ], allowedClasses: { 'a': ['lineAnchor'], 'div': ['math'], @@ -24,14 +24,20 @@ const sanitizeOpts = { allowedAttributes: { a: ['href', 'data-key'], img: [ 'src' ], + label: ['for'], + input: ['checked', 'type'], '*': ['id', 'name'] }, transformTags: { '*': function (tagName, attribs) { let href = attribs.href + if (tagName === 'input' && attribs.type !== 'checkbox') { + return false + } if (_.isString(href) && href.match(/^#.+$/)) attribs.href = href.replace(/^#/, '#md-anchor-') if (attribs.id) attribs.id = 'md-anchor-' + attribs.id if (attribs.name) attribs.name = 'md-anchor-' + attribs.name + if (attribs.for) attribs.for = 'md-anchor-' + attribs.for return { tagName: tagName, attribs: attribs diff --git a/browser/lib/markdown.js b/browser/lib/markdown.js index 3ba78b5c..eaa55297 100644 --- a/browser/lib/markdown.js +++ b/browser/lib/markdown.js @@ -17,7 +17,9 @@ var md = markdownit({ return str } }) -md.use(emoji) +md.use(emoji, { + shortcuts: {} +}) md.use(math, { inlineRenderer: function (str) { return `${str}` @@ -26,6 +28,7 @@ md.use(math, { return `
${str}
` } }) +md.use(require('markdown-it-checkbox')) let originalRenderToken = md.renderer.renderToken md.renderer.renderToken = function renderToken (tokens, idx, options) { diff --git a/browser/styles/mixins/marked.styl b/browser/styles/mixins/marked.styl index 7f82a9ec..cfa893b1 100644 --- a/browser/styles/mixins/marked.styl +++ b/browser/styles/mixins/marked.styl @@ -78,7 +78,7 @@ marked() font-weight bold em, i font-style italic - s + s, del, strike text-decoration line-through u text-decoration underline diff --git a/package.json b/package.json index 650c6953..e83573d7 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "highlight.js": "^8.9.1", "lodash": "^3.10.1", "markdown-it": "^4.4.0", + "markdown-it-checkbox": "^1.1.0", "markdown-it-emoji": "^1.1.0", "markdown-it-math": "^3.0.2", "md5": "^2.0.0", diff --git a/webpack-skeleton.js b/webpack-skeleton.js index b9b21fdf..68b3f760 100644 --- a/webpack-skeleton.js +++ b/webpack-skeleton.js @@ -32,7 +32,8 @@ var config = { 'markdown-it-emoji', 'fs-jetpack', 'markdown-it-math', - '@rokt33r/sanitize-html' + '@rokt33r/sanitize-html', + 'markdown-it-checkbox' ] }