From 4895bc030e9ef5b4b2d1178c5540f51834eab3de Mon Sep 17 00:00:00 2001 From: makethemo Date: Sat, 11 Nov 2017 03:14:53 +0900 Subject: [PATCH 1/5] Add support Evernote task lists. --- .gitignore | 3 +++ src/common/markdown-render.js | 19 +++++++++++++++++++ src/common/options.html | 7 +++++++ src/common/options.js | 10 +++++++--- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 6cc0f8f5..e6c2cafa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,6 @@ Thumbs.db # Build directory dist + +# JetBrains WebStorm +.idea diff --git a/src/common/markdown-render.js b/src/common/markdown-render.js index c11ad8bf..8a296dd9 100644 --- a/src/common/markdown-render.js +++ b/src/common/markdown-render.js @@ -72,6 +72,25 @@ function markdownRender(mdText, userprefs, marked, hljs) { return defaultLinkRenderer.call(this, href, title, text); }; + var defaultLinkRenderer = markedRenderer.listitem; + markedRenderer.listitem = function(text) { + if (userprefs['evernote-task-lists-enabled']) { + if (/^\s*\[[x ]\]\s*/.test(text)) { + var todoImg = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; + text = text + .replace(/^\s*\[ \]\s*/, ' ') + .replace(/^\s*\[x\]\s*/, ' '); + return '
  • ' + text + '
  • '; + } + else { + return '
  • ' + text + '
  • '; + } + } + else { + return defaultLinkRenderer.call(this, text); + } + }; + var markedOptions = { renderer: markedRenderer, gfm: true, diff --git a/src/common/options.html b/src/common/options.html index c6f091b8..f8635ced 100644 --- a/src/common/options.html +++ b/src/common/options.html @@ -634,6 +634,13 @@


    +
    + + +
    +
    diff --git a/src/common/options.js b/src/common/options.js index 65b9c674..7639a019 100644 --- a/src/common/options.js +++ b/src/common/options.js @@ -16,7 +16,7 @@ var cssEdit, cssSyntaxEdit, cssSyntaxSelect, rawMarkdownIframe, savedMsg, mathEnable, mathEdit, hotkeyShift, hotkeyCtrl, hotkeyAlt, hotkeyKey, forgotToRenderCheckEnabled, headerAnchorsEnabled, gfmLineBreaksEnabled, - loaded = false; + evernoteTaskListsEnabled, loaded = false; function onLoad() { var xhr; @@ -41,6 +41,7 @@ function onLoad() { forgotToRenderCheckEnabled = document.getElementById('forgot-to-render-check-enabled'); headerAnchorsEnabled = document.getElementById('header-anchors-enabled'); gfmLineBreaksEnabled = document.getElementById('gfm-line-breaks-enabled'); + evernoteTaskListsEnabled = document.getElementById('evernote-task-lists-enabled'); // // Syntax highlighting styles and selection @@ -91,6 +92,8 @@ function onLoad() { gfmLineBreaksEnabled.checked = prefs['gfm-line-breaks-enabled']; + evernoteTaskListsEnabled.checked = prefs['evernote-task-lists-enabled']; + // Start watching for changes to the styles. setInterval(checkChange, 100); }); @@ -215,7 +218,7 @@ function checkChange() { mathEnable.checked + mathEdit.value + hotkeyShift.checked + hotkeyCtrl.checked + hotkeyAlt.checked + hotkeyKey.value + forgotToRenderCheckEnabled.checked + headerAnchorsEnabled.checked + - gfmLineBreaksEnabled.checked; + gfmLineBreaksEnabled.checked + evernoteTaskListsEnabled.checked; if (newOptions !== lastOptions) { // CSS has changed. @@ -246,7 +249,8 @@ function checkChange() { }, 'forgot-to-render-check-enabled': forgotToRenderCheckEnabled.checked, 'header-anchors-enabled': headerAnchorsEnabled.checked, - 'gfm-line-breaks-enabled': gfmLineBreaksEnabled.checked + 'gfm-line-breaks-enabled': gfmLineBreaksEnabled.checked, + 'evernote-task-lists-enabled' : evernoteTaskListsEnabled.checked }, function() { updateMarkdownRender(); From 7957b17ce8350278f501dd3b022deb125b32c13a Mon Sep 17 00:00:00 2001 From: makethemo Date: Sat, 11 Nov 2017 03:33:24 +0900 Subject: [PATCH 2/5] Add checking Evernote URL. --- src/common/markdown-render.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/markdown-render.js b/src/common/markdown-render.js index 8a296dd9..0da1e56c 100644 --- a/src/common/markdown-render.js +++ b/src/common/markdown-render.js @@ -74,7 +74,7 @@ function markdownRender(mdText, userprefs, marked, hljs) { var defaultLinkRenderer = markedRenderer.listitem; markedRenderer.listitem = function(text) { - if (userprefs['evernote-task-lists-enabled']) { + if (userprefs['evernote-task-lists-enabled'] && location.href.match('evernote.com')) { if (/^\s*\[[x ]\]\s*/.test(text)) { var todoImg = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; text = text From 542a0c6f5352d74d3d71751937c68dbc322d0ff1 Mon Sep 17 00:00:00 2001 From: makethemo Date: Sun, 12 Nov 2017 00:36:19 +0900 Subject: [PATCH 3/5] FIx bug. --- src/common/markdown-render.js | 35 +++++++++++++++++++--------------- src/common/mdh-html-to-text.js | 9 +++++++++ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/common/markdown-render.js b/src/common/markdown-render.js index 0da1e56c..572098f9 100644 --- a/src/common/markdown-render.js +++ b/src/common/markdown-render.js @@ -72,23 +72,28 @@ function markdownRender(mdText, userprefs, marked, hljs) { return defaultLinkRenderer.call(this, href, title, text); }; + var defaultLinkRenderer = markedRenderer.list; + markedRenderer.list = function(body, ordered) { + if (userprefs['evernote-task-lists-enabled'] && location.href.match(/evernote.com/) + && !ordered && /<.*en-todo.*>/.test(body)) { + return '
    ' + body + '
    \n'; + } + return defaultLinkRenderer.call(this, body, ordered); + }; + var defaultLinkRenderer = markedRenderer.listitem; markedRenderer.listitem = function(text) { - if (userprefs['evernote-task-lists-enabled'] && location.href.match('evernote.com')) { - if (/^\s*\[[x ]\]\s*/.test(text)) { - var todoImg = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; - text = text - .replace(/^\s*\[ \]\s*/, ' ') - .replace(/^\s*\[x\]\s*/, ' '); - return '
  • ' + text + '
  • '; - } - else { - return '
  • ' + text + '
  • '; - } - } - else { - return defaultLinkRenderer.call(this, text); - } + if (userprefs['evernote-task-lists-enabled'] && location.href.match(/evernote.com/) + && /\s*\[[x ]\]\s*/.test(text)) { + var todoImg = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'; + text = text + .replace(/\s*\[ \]\s*/g, ' ') + .replace(/\s*\[x\]\s*/g, ' '); + return '
    ' + text + '
    \n'; + } + else { + return defaultLinkRenderer.call(this, text); + } }; var markedOptions = { diff --git a/src/common/mdh-html-to-text.js b/src/common/mdh-html-to-text.js index 746d957c..468435dd 100644 --- a/src/common/mdh-html-to-text.js +++ b/src/common/mdh-html-to-text.js @@ -111,6 +111,15 @@ MdhHtmlToText.prototype._preprocess = function() { /< ') @@ -92,7 +90,7 @@ function markdownRender(mdText, userprefs, marked, hljs) { return '
    ' + text + '
    \n'; } else { - return defaultLinkRenderer.call(this, text); + return defaultListItemRenderer.call(this, text); } }; diff --git a/src/common/mdh-html-to-text.js b/src/common/mdh-html-to-text.js index 468435dd..a55e75ac 100644 --- a/src/common/mdh-html-to-text.js +++ b/src/common/mdh-html-to-text.js @@ -113,12 +113,8 @@ MdhHtmlToText.prototype._preprocess = function() { // Support Evernote task lists. // This code must be executed before handling . - if (location.href.match(/evernote.com/)) { - this.preprocessInfo.html = - this.preprocessInfo.html - .replace(/<.*en-todo-checked.*>/ig, '- [x]') - .replace(/<.*en-todo.*>/ig, '- [ ]'); - } + this.preprocessInfo.html = this.preprocessInfo.html.replace(/<.*en-todo-checked.*>/ig, '- [x]') + .replace(/<.*en-todo.*>/ig, '- [ ]'); // It's a deviation from Markdown, but we'd like to leave any rendered // images already in the email intact. So we'll escape their tags. From 7f504bf44ea48a268b681be77c41c1e46195a05d Mon Sep 17 00:00:00 2001 From: makethemo Date: Sun, 12 Nov 2017 01:36:19 +0900 Subject: [PATCH 5/5] Agree to Individual Contributor License Agreement. --- contributors/makethemo.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contributors/makethemo.md diff --git a/contributors/makethemo.md b/contributors/makethemo.md new file mode 100644 index 00000000..c86a1bd1 --- /dev/null +++ b/contributors/makethemo.md @@ -0,0 +1,9 @@ +2017-11-12 + +I hereby agree to the terms of the "Markdown Here Individual Contributor License Agreement", with MD5 checksum 6a31e08cf66139e91c0db5599b6ab084. + +I furthermore declare that I am authorized and able to make this agreement and sign this declaration. + +Signed, + +Jinseop Mo https://github.com/makethemo