From 15e91c09ac32819316a0ec3168c4a890d05890b3 Mon Sep 17 00:00:00 2001 From: Peter Stuifzand Date: Wed, 24 Jun 2020 20:45:03 +0200 Subject: [PATCH] Show checkbox for TODO / DONE and update --- editor/package-lock.json | 6 +++--- editor/package.json | 2 +- editor/src/index.js | 30 +++++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/editor/package-lock.json b/editor/package-lock.json index 5d42712..b1d6ea2 100644 --- a/editor/package-lock.json +++ b/editor/package-lock.json @@ -9241,9 +9241,9 @@ } }, "wiki-list-editor": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/wiki-list-editor/-/wiki-list-editor-0.8.3.tgz", - "integrity": "sha512-ZBSk3V2ln8359+8P+2Mj/kiz+F1V5sKR01/pchwIEQYLc+JbgplTJXIKenpxdneD0KKitCMt7oEI5ur+MKqBLg==", + "version": "0.8.7", + "resolved": "https://registry.npmjs.org/wiki-list-editor/-/wiki-list-editor-0.8.7.tgz", + "integrity": "sha512-93pNyMljk+/v4jFE2fEamK42zwzzQ5DUyEXAAkrMsRuZSQvo2s8sC0O6nUMcJwn32s8vqIhdCx6KFSeCFbfWcA==", "requires": { "dragula": "^3.7.2", "he": "^1.2.0", diff --git a/editor/package.json b/editor/package.json index 24ea95f..0259d4a 100644 --- a/editor/package.json +++ b/editor/package.json @@ -38,7 +38,7 @@ "vis-data": "^6.6.1", "vis-network": "^7.6.10", "vis-util": "^4.3.2", - "wiki-list-editor": "^0.8.3" + "wiki-list-editor": "^0.8.7" }, "scripts": { "test": "node_modules/.bin/mocha -r esm", diff --git a/editor/src/index.js b/editor/src/index.js index bb5d9ce..47dd9b8 100644 --- a/editor/src/index.js +++ b/editor/src/index.js @@ -205,13 +205,41 @@ if (holder) { const options = { transform(text, element) { - let converted = (text.startsWith("```", 0)) ? MD.render(text) : MD.renderInline(text) + let converted = text + if (converted.startsWith("```", 0)) { + converted = MD.render(converted) + } else { + if (text.match(/#\[\[TODO]]/)) { + converted = converted.replace('#[[TODO]]', '') + } else if (text.match(/#\[\[DONE]]/)) { + converted = converted.replace('#[[DONE]]', '') + } + MD.options.html = true + converted = MD.renderInline(converted) + MD.options.html = false + } + element.html(converted) } } let editor = listEditor(holder, JSON.parse(holder.dataset.input), options); + $(document).on('click', '.content input[type="checkbox"]', function (event) { + let that = this + let id = $(this).closest('.list-item').data('id') + editor.update(id, function (item, prev, next) { + if (that.checked) { + item.text = item.text.replace('#[[TODO]]', '#[[DONE]]') + } else { + item.text = item.text.replace('#[[DONE]]', '#[[TODO]]') + } + return item + }); + event.stopPropagation() + return true + }) + editor.on('change', function () { let element = document.getElementById('editor'); let indicator = Indicator(document.getElementById('save-indicator'), 2);