summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mehren2021-05-06 21:07:21 +0200
committerGitHub2021-05-06 21:07:21 +0200
commit9d3902d208aa1e4f87f2e06bfbbb9b9dce1fba78 (patch)
tree4949d58d7d7a7c6e5f7fadc01143c53f2542ef2b
parentf48e36d2052bcae56081bee3c281bfc69fe7f70d (diff)
parent7f8be22e97a29eb54f22aff1ea377973417d45d4 (diff)
Merge pull request #1234 from hedgedoc/fix/numbered-task-lists
Fix click handler for numbered task lists
-rw-r--r--public/js/extra.js12
1 files changed, 6 insertions, 6 deletions
diff --git a/public/js/extra.js b/public/js/extra.js
index 7f06ebda..c71475b5 100644
--- a/public/js/extra.js
+++ b/public/js/extra.js
@@ -266,9 +266,9 @@ export function finishView (view) {
li.innerHTML = html
let disabled = 'disabled'
if (typeof editor !== 'undefined' && window.havePermission()) { disabled = '' }
- if (/^\s*\[[x ]\]\s*/.test(html)) {
- li.innerHTML = html.replace(/^\s*\[ \]\s*/, `<input type="checkbox" class="task-list-item-checkbox "${disabled}><label></label>`)
- .replace(/^\s*\[x\]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`)
+ if (/^\s*\[[xX ]]\s*/.test(html)) {
+ li.innerHTML = html.replace(/^\s*\[ ]\s*/, `<input type="checkbox" class="task-list-item-checkbox" ${disabled}><label></label>`)
+ .replace(/^\s*\[[xX]]\s*/, `<input type="checkbox" class="task-list-item-checkbox" checked ${disabled}><label></label>`)
if (li.tagName.toLowerCase() !== 'li') {
li.parentElement.setAttribute('class', 'task-list-item')
} else {
@@ -705,11 +705,11 @@ $.fn.sortByDepth = function () {
function toggleTodoEvent (e) {
const startline = $(this).closest('li').attr('data-startline') - 1
const line = window.editor.getLine(startline)
- const matches = line.match(/^[>\s-]*[-+*]\s\[([x ])\]/)
+ const matches = line.match(/^[>\s-]*(?:[-+*]|\d+[.)])\s\[([xX ])]/)
if (matches && matches.length >= 2) {
let checked = null
- if (matches[1] === 'x') { checked = true } else if (matches[1] === ' ') { checked = false }
- const replacements = matches[0].match(/(^[>\s-]*[-+*]\s\[)([x ])(\])/)
+ if (matches[1].toLowerCase() === 'x') { checked = true } else if (matches[1] === ' ') { checked = false }
+ const replacements = matches[0].match(/(^[>\s-]*(?:[-+*]|\d+[.)])\s\[)([xX ])(])/)
window.editor.replaceRange(checked ? ' ' : 'x', {
line: startline,
ch: replacements[1].length