Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Evernote task lists. #468

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ Thumbs.db

# Build directory
dist

# JetBrains WebStorm
.idea
9 changes: 9 additions & 0 deletions contributors/makethemo.md
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions src/common/markdown-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,28 @@ function markdownRender(mdText, userprefs, marked, hljs) {
return defaultLinkRenderer.call(this, href, title, text);
};

var defaultListRenderer = markedRenderer.list;
markedRenderer.list = function(body, ordered) {
if (userprefs['evernote-task-lists-enabled'] && /<.*en-todo.*>/.test(body)) {
return '<div>' + body + '</div>\n';
}
return defaultListRenderer.call(this, body, ordered);
};

var defaultListItemRenderer = markedRenderer.listitem;
markedRenderer.listitem = function(text) {
if (userprefs['evernote-task-lists-enabled'] && /\s*\[[x ]\]\s*/.test(text)) {
var todoImg = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
text = text
.replace(/\s*\[ \]\s*/g, '<img class="en-todo" src="' + todoImg + '"> ')
.replace(/\s*\[x\]\s*/g, '<img class="en-todo en-todo-checked" src="' + todoImg + '"> ');
return '<div>' + text + '</div>\n';
}
else {
return defaultListItemRenderer.call(this, text);
}
};

var markedOptions = {
renderer: markedRenderer,
gfm: true,
Expand Down
5 changes: 5 additions & 0 deletions src/common/mdh-html-to-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ MdhHtmlToText.prototype._preprocess = function() {
/&lt;<a (href="mailto:[^>]+)>([^<]*)<\/a>&gt;/ig,
'&lt;&lt;a $1&gt;$2&lt;\/a&gt;&gt;');

// Support Evernote task lists.
// This code must be executed before handling <img>.
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.
// Note that we can't use excludeTagBlocks because there's no closing tag.
Expand Down
7 changes: 7 additions & 0 deletions src/common/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,13 @@ <h1>
</label>
</div>
<hr/>
<div>
<input type="checkbox" id="evernote-task-lists-enabled"/>
<label for="evernote-task-lists-enabled" data-i18n="evernote_task_lists_enabled_label">
<b>Enable Evernote task lists.</b>
</label>
</div>
<hr/>
</div>

<div class="control-group">
Expand Down
10 changes: 7 additions & 3 deletions src/common/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down