markdown-it-task-checkbox
Advanced tools
Comparing version 1.0.5 to 1.0.6
@@ -78,3 +78,3 @@ // Markdown-it plugin to render GitHub-style task lists; see | ||
checkbox.attrs = [["type", "checkbox"], ["id", id]]; | ||
var checked = (token.content.indexOf('[x] ') === 0 || token.content.indexOf('[X] ') === 0) | ||
var checked = /^\[[xX]\][ \u00A0]/.test(token.content); // if token.content starts with '[x] ' or '[X] ' | ||
if (checked === true) { | ||
@@ -119,4 +119,6 @@ checkbox.attrs.push(["checked", "true"]); | ||
function startsWithTodoMarkdown(token) { | ||
// leading whitespace in a list item is already trimmed off by markdown-it | ||
return token.content.indexOf('[ ] ') === 0 || token.content.indexOf('[x] ') === 0 || token.content.indexOf('[X] ') === 0; | ||
// The leading whitespace in a list item (token.content) is already trimmed off by markdown-it. | ||
// The regex below checks for '[ ] ' or '[x] ' or '[X] ' at the start of the string token.content, | ||
// where the space is either a normal space or a non-breaking space (character 160 = \u00A0). | ||
return /^\[[xX \u00A0]\][ \u00A0]/.test(token.content); | ||
} |
{ | ||
"name": "markdown-it-task-checkbox", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "A markdown-it plugin to create GitHub-style task lists", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -8,1 +8,22 @@ - [ ] unchecked todo item 1 | ||
- [x] todo item 6 | ||
- [ X] not a todo item 7 | ||
- [X ] not a todo item 8 | ||
- [ X ] not a todo item 9 | ||
- [X] todo item 10 | ||
- [ ] unchecked todo item with non-breaking space 11 | ||
- [ ] | ||
- [ ] not a todo item with 2 non-breaking spaces 12 | ||
- [ ] not a todo item with 1 non-breaking space and 1 space 13 | ||
- [ ] not a todo item with 1 space and 1 non-breaking space 14 | ||
- [ x] not a todo item with non-breaking space 15 | ||
- [x ] not a todo item with non-breaking space 16 | ||
- [ x ] not a todo item with 2 non-breaking spaces 17 | ||
- [ x ] not a todo item with 1 non-breaking space and 1 space 18 | ||
- [ x ] not a todo item with 1 space and 1 non-breaking space 19 | ||
- [x] todo item with non-breaking space 20 | ||
- [ X] not a todo item with non-breaking space 21 | ||
- [X ] not a todo item with non-breaking space 22 | ||
- [ X ] not a todo item with 2 non-breaking spaces 23 | ||
- [ X ] not a todo item with 1 space and 1 non-breaking space 24 | ||
- [ X ] not a todo item with 1 non-breaking space and 1 space 25 | ||
- [X] todo item with non-breaking space 26 |
1. [x] checked ordered 1 | ||
2. [ ] unchecked ordered 2 | ||
3. [x] checked ordered 3 | ||
3. [X] checked ordered 3 | ||
4. [ ] unchecked ordered 4 | ||
5. [x] checked ordered non-breaking-space 5 | ||
6. [ ] unchecked ordered non-breaking-space 6 | ||
7. [X] checked ordered non-breaking-space 7 | ||
8. [ ] unchecked ordered non-breaking-space 8 |
@@ -40,3 +40,3 @@ /* globals before, describe, it */ | ||
it('renders items marked up as [ ] as unchecked', function () { | ||
var shouldBeUnchecked = (fixtures.ordered.match(/[\.\*\+-]\s+\[ \]/g) || []).length; | ||
var shouldBeUnchecked = (fixtures.ordered.match(/[\.\*\+-]\s+\[[ \u00A0]\]/g) || []).length; | ||
assert.equal($.ordered('input[type=checkbox]:not(:checked)').length, shouldBeUnchecked); | ||
@@ -73,2 +73,11 @@ }); | ||
assert(~html.indexOf('<li>[ x ]')); | ||
assert(~html.indexOf('<li>[  ]')); | ||
assert(~html.indexOf('<li>[  ]')); | ||
assert(~html.indexOf('<li>[  ]')); | ||
assert(~html.indexOf('<li>[ ]</li>')); | ||
assert(~html.indexOf('<li>[x ]')); | ||
assert(~html.indexOf('<li>[ x]')); | ||
assert(~html.indexOf('<li>[ x ]')); | ||
assert(~html.indexOf('<li>[ x ]')); | ||
assert(~html.indexOf('<li>[ x ]')); | ||
}); | ||
@@ -75,0 +84,0 @@ |
76885
185