From 597cc3977e050fa15913ef3803a47511cdac28fc Mon Sep 17 00:00:00 2001 From: Opportunity Date: Fri, 17 Aug 2018 11:49:27 +0800 Subject: [PATCH 1/3] Update index.js --- src/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 405090a..bd7a089 100644 --- a/src/index.js +++ b/src/index.js @@ -1,11 +1,20 @@ import mermaid from 'mermaid' +function escapeHtml(unsafe) { + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); +} + const mermaidChart = (code) => { try { mermaid.parse(code) - return `
${code}
` + return `
${escapeHtml(code)}
` } catch ({ str, hash }) { - return `
${str}
` + return `
${escapeHtml(str)}
` } } From 58bd5cf8b9b715184a4558216d8a439ca388375e Mon Sep 17 00:00:00 2001 From: Opportunity Date: Sat, 18 Aug 2018 17:08:59 +0800 Subject: [PATCH 2/3] Update index.js --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index bd7a089..b262a26 100644 --- a/src/index.js +++ b/src/index.js @@ -14,7 +14,7 @@ const mermaidChart = (code) => { mermaid.parse(code) return `
${escapeHtml(code)}
` } catch ({ str, hash }) { - return `
${escapeHtml(str)}
` + return `
${escapeHtml(str)}
` } } From d53af133c7139fffb9402c46f682e8ca90e9fb27 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 27 Dec 2018 13:23:33 +0800 Subject: [PATCH 3/3] add htmlmin ignore --- src/index.js | 60 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/index.js b/src/index.js index b262a26..10cd950 100644 --- a/src/index.js +++ b/src/index.js @@ -1,41 +1,52 @@ import mermaid from 'mermaid' -function escapeHtml(unsafe) { - return unsafe - .replace(/&/g, "&") - .replace(//g, ">") - .replace(/"/g, """) - .replace(/'/g, "'"); +function escapeHtml(unsafe) +{ + return unsafe + .replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); } -const mermaidChart = (code) => { - try { +const mermaidChart = (code) => +{ + try + { mermaid.parse(code) - return `
${escapeHtml(code)}
` - } catch ({ str, hash }) { + return `
${escapeHtml(code)}
` + } catch ({ str, hash }) + { return `
${escapeHtml(str)}
` } } -const MermaidPlugin = (md) => { +const MermaidPlugin = (md) => +{ md.mermaid = mermaid - mermaid.loadPreferences = (preferenceStore) => { + mermaid.loadPreferences = (preferenceStore) => + { let mermaidTheme = preferenceStore.get('mermaid-theme') - if (mermaidTheme === undefined) { + if (mermaidTheme === undefined) + { mermaidTheme = 'default' } let ganttAxisFormat = preferenceStore.get('gantt-axis-format') - if (ganttAxisFormat === undefined) { + if (ganttAxisFormat === undefined) + { ganttAxisFormat = '%Y-%m-%d' } mermaid.initialize({ theme: mermaidTheme, - gantt: { axisFormatter: [ - [ganttAxisFormat, (d) => { - return d.getDay() === 1 - }] - ]} + gantt: { + axisFormatter: [ + [ganttAxisFormat, (d) => + { + return d.getDay() === 1 + }] + ] + } }) return { 'mermaid-theme': mermaidTheme, @@ -44,14 +55,17 @@ const MermaidPlugin = (md) => { } const temp = md.renderer.rules.fence.bind(md.renderer.rules) - md.renderer.rules.fence = (tokens, idx, options, env, slf) => { + md.renderer.rules.fence = (tokens, idx, options, env, slf) => + { const token = tokens[idx] const code = token.content.trim() - if (token.info === 'mermaid') { + if (token.info === 'mermaid') + { return mermaidChart(code) } const firstLine = code.split(/\n/)[0].trim() - if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) { + if (firstLine === 'gantt' || firstLine === 'sequenceDiagram' || firstLine.match(/^graph (?:TB|BT|RL|LR|TD);?$/)) + { return mermaidChart(code) } return temp(tokens, idx, options, env, slf)