Open platform to collect and prioritize feedback
tooling: replace markdown-it with marked (#643)
Guilherme Oenningf5b0b3a2aefb
diff --git a/package-lock.json b/package-lock.jsonindex 2dc528e06..81c2224a1 100644--- a/package-lock.json+++ b/package-lock.json@@ -105,10 +105,10 @@"parse5": "^4.0.0"}},- "@types/markdown-it": {- "version": "0.0.6",- "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-0.0.6.tgz",- "integrity": "sha512-BJc/VKKKvLAnpsanrnEhXItJeFHrOJhWgeOj7Jfe/OdmwOsbCycpaizf29j9FfR+p77sVbLb50pWCHRkfLfVnA==",+ "@types/marked": {+ "version": "0.4.2",+ "resolved": "https://registry.npmjs.org/@types/marked/-/marked-0.4.2.tgz",+ "integrity": "sha512-cDB930/7MbzaGF6U3IwSQp6XBru8xWajF5PV2YZZeV8DyiliTuld11afVztGI9+yJZ29il5E+NpGA6ooV/Cjkg==","dev": true},"@types/node": {@@ -562,6 +562,7 @@"version": "1.0.10","resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz","integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",+ "dev": true,"requires": {"sprintf-js": "~1.0.2"}@@ -2350,7 +2351,8 @@"entities": {"version": "1.1.2","resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz",- "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w=="+ "integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w==",+ "dev": true},"enzyme": {"version": "3.7.0",@@ -6159,14 +6161,6 @@"integrity": "sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=","dev": true},- "linkify-it": {- "version": "2.0.3",- "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.0.3.tgz",- "integrity": "sha1-2UpGSPmxwXnWT6lykSaL22zpQ08=",- "requires": {- "uc.micro": "^1.0.1"- }- },"load-json-file": {"version": "1.1.0","resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz",@@ -6357,17 +6351,10 @@"object-visit": "^1.0.0"}},- "markdown-it": {- "version": "8.4.2",- "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-8.4.2.tgz",- "integrity": "sha512-GcRz3AWTqSUphY3vsUqQSFMbgR38a4Lh3GWlHRh/7MRwz8mcu9n2IO7HOh+bXHrR9kOPDl5RNCaEsrneb+xhHQ==",- "requires": {- "argparse": "^1.0.7",- "entities": "~1.1.1",- "linkify-it": "^2.0.0",- "mdurl": "^1.0.1",- "uc.micro": "^1.0.5"- }+ "marked": {+ "version": "0.5.1",+ "resolved": "https://registry.npmjs.org/marked/-/marked-0.5.1.tgz",+ "integrity": "sha512-iUkBZegCZou4AdwbKTwSW/lNDcz5OuRSl3qdcl31Ia0B2QPG0Jn+tKblh/9/eP9/6+4h27vpoh8wel/vQOV0vw=="},"math-random": {"version": "1.0.1",@@ -6386,11 +6373,6 @@"safe-buffer": "^5.1.2"}},- "mdurl": {- "version": "1.0.1",- "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",- "integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4="- },"media-typer": {"version": "0.3.0","resolved": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",@@ -8922,7 +8904,8 @@"sprintf-js": {"version": "1.0.3","resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",- "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="+ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",+ "dev": true},"sshpk": {"version": "1.15.2",@@ -9713,11 +9696,6 @@"integrity": "sha512-tDMYfVtvpb96msS1lDX9MEdHrW4yOuZ4Kdc4Him9oU796XldPYF/t2+uKoX0BBa0hXXwDlqYQbXY5Rzjzc5hBA==","dev": true},- "uc.micro": {- "version": "1.0.5",- "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.5.tgz",- "integrity": "sha512-JoLI4g5zv5qNyT09f4YAvEZIIV1oOjqnewYg5D38dkQljIzpPT296dbIGvKro3digYI1bkb7W6EP1y4uDlmzLg=="- },"uglify-js": {"version": "3.4.9","resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.9.tgz",diff --git a/package.json b/package.jsonindex 5fbc0bbfc..6ef22a121 100644--- a/package.json+++ b/package.json@@ -4,7 +4,7 @@"repository": "https://github.com/getfider/fider","private": true,"dependencies": {- "markdown-it": "8.4.2",+ "marked": "0.5.1","react": "16.6.3","react-dom": "16.6.3","react-icons": "3.2.2",@@ -18,7 +18,7 @@"@types/enzyme-adapter-react-16": "1.0.3","@types/jest": "23.3.9","@types/jsdom": "12.2.0",- "@types/markdown-it": "0.0.6",+ "@types/marked": "0.4.2","@types/node": "10.12.7","@types/puppeteer": "1.10.0","@types/react": "16.7.4",diff --git a/public/services/markdown.spec.ts b/public/services/markdown.spec.tsindex 45e72521a..7f27aa01d 100644--- a/public/services/markdown.spec.ts+++ b/public/services/markdown.spec.ts@@ -8,8 +8,30 @@ const testCases = [},{input: "My Picture ",- expectedFull: '<p>My Picture <img src="http://demo.dev.fider.io:3000/images/100/28" alt="" /></p>',- expectedSimple: '<p>My Picture !<a href="http://demo.dev.fider.io:3000/images/100/28" target="_blank"></a></p>'+ expectedFull: '<p>My Picture <img src="http://demo.dev.fider.io:3000/images/100/28" alt=""/></p>',+ expectedSimple: "<p>My Picture </p>"+ },+ {+ input: "# Hello World",+ expectedFull: "<h1>Hello World</h1>",+ expectedSimple: "<p>Hello World</p>"+ },+ {+ input: "~~Option 3~~",+ expectedFull: "<p><del>Option 3</del></p>",+ expectedSimple: "<p><del>Option 3</del></p>"+ },+ {+ input: "Check this out: `HEEEY`",+ expectedFull: "<p>Check this out: <code>HEEEY</code></p>",+ expectedSimple: "<p>Check this out: <code>HEEEY</code></p>"+ },+ {+ input: `# Hello World+How are you?`,+ expectedFull: `<h1>Hello World</h1>+<p>How are you?</p>`,+ expectedSimple: `<p>Hello World</p><p>How are you?</p>`}];diff --git a/public/services/markdown.ts b/public/services/markdown.tsindex 1a8e4780b..38f8dd909 100644--- a/public/services/markdown.ts+++ b/public/services/markdown.ts@@ -1,34 +1,29 @@-import md from "markdown-it";--const fullMarkdown = md("commonmark", {- html: false,- breaks: true,- linkify: true-}).enable(["linkify", "strikethrough"]);--const simpleMarkdown = md("commonmark", { html: false, breaks: true, linkify: true })- .enable(["linkify", "strikethrough"])- .disable(["heading", "image"]);--const linkOpen = (tokens: md.Token[], idx: number, options: any, env: any, self: md.Renderer) => {- const aIndex = tokens[idx].attrIndex("target");-- if (aIndex < 0) {- tokens[idx].attrPush(["target", "_blank"]);- } else {- tokens[idx].attrs[aIndex][1] = "_blank";- }-- return self.renderToken(tokens, idx, options);+import marked from "marked";++marked.setOptions({+ headerIds: false,+ xhtml: true,+ smartLists: true,+ gfm: true+});++const link = (href: string, title: string, text: string) => {+ const titleAttr = title ? ` title=${title}` : "";+ return `<a href="${href}"${titleAttr} target="_blank">${text}</a>`;};-fullMarkdown.renderer.rules.link_open = linkOpen;-simpleMarkdown.renderer.rules.link_open = linkOpen;+const simpleRenderer = new marked.Renderer();+simpleRenderer.heading = (text, level, raw) => `<p>${raw}</p>`;+simpleRenderer.image = (href, title, text) => "";+simpleRenderer.link = link;++const fullRenderer = new marked.Renderer();+fullRenderer.link = link;export const full = (input: string): string => {- return fullMarkdown.render(input).trim();+ return marked(input, { renderer: fullRenderer }).trim();};export const simple = (input: string): string => {- return simpleMarkdown.render(input).trim();+ return marked(input, { renderer: simpleRenderer }).trim();};diff --git a/tsconfig.json b/tsconfig.jsonindex 559a2f5f3..81948cf7e 100755--- a/tsconfig.json+++ b/tsconfig.json@@ -8,7 +8,7 @@"strict": true,"sourceMap": true,"types": [- "markdown-it",+ "marked","react","react-dom","react-textarea-autosize",diff --git a/webpack.config.js b/webpack.config.jsindex 6bf19f18e..9775a2ece 100755--- a/webpack.config.js+++ b/webpack.config.js@@ -44,7 +44,7 @@ module.exports = {"react","react-dom","tslib",- "markdown-it",+ "marked","react-textarea-autosize","react-toastify","react-loadable",