Skip to content

Commit e402929

Browse files
Ryota KusanoRokt33r
authored andcommitted
Fix regular expression related checkbox logic
1 parent 052fb3d commit e402929

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

browser/components/MarkdownEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class MarkdownEditor extends React.Component {
159159
e.preventDefault()
160160
e.stopPropagation()
161161
const idMatch = /checkbox-([0-9]+)/
162-
const checkedMatch = /^\s*[\+\-\*] \[x\]/i
163-
const uncheckedMatch = /^\s*[\+\-\*] \[ \]/
162+
const checkedMatch = /^\s*>?\s*[\+\-\*] \[x\]/i
163+
const uncheckedMatch = /^\s*>?\s*[\+\-\*] \[ \]/
164164
const checkReplace = /\[x\]/i
165165
const uncheckReplace = /\[ \]/
166166
if (idMatch.test(e.target.getAttribute('id'))) {

browser/components/MarkdownSplitEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class MarkdownSplitEditor extends React.Component {
7878
e.preventDefault()
7979
e.stopPropagation()
8080
const idMatch = /checkbox-([0-9]+)/
81-
const checkedMatch = /^\s*[\+\-\*] \[x\]/i
82-
const uncheckedMatch = /^\s*[\+\-\*] \[ \]/
81+
const checkedMatch = /^\s*>?\s*[\+\-\*] \[x\]/i
82+
const uncheckedMatch = /^\s*>?\s*[\+\-\*] \[ \]/
8383
const checkReplace = /\[x\]/i
8484
const uncheckReplace = /\[ \]/
8585
if (idMatch.test(e.target.getAttribute('id'))) {

browser/lib/getTodoStatus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function getTodoStatus (content) {
44
let numberOfCompletedTodo = 0
55

66
splitted.forEach((line) => {
7-
const trimmedLine = line.trim()
7+
const trimmedLine = line.trim().replace(/^>\s*/, '')
88
if (trimmedLine.match(/^[\+\-\*] \[(\s|x)\] ./i)) {
99
numberOfTodo++
1010
}

tests/lib/get-todo-status-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ test('getTodoStatus should return a correct hash object', t => {
2828
['- [x] `- [x] a`\n', { total: 1, completed: 1 }],
2929
['- [X] `- [X] a`\n', { total: 1, completed: 1 }],
3030
[' \t - [X] `- [X] a`\n', { total: 1, completed: 1 }],
31-
[' \t - [X] `- [X] a`\n \t - [ ] `- [X] a`\n', { total: 2, completed: 1 }]
31+
[' \t - [X] `- [X] a`\n \t - [ ] `- [X] a`\n', { total: 2, completed: 1 }],
32+
['> - [ ] a\n', { total: 1, completed: 0 }],
33+
['> - [ ] a\n- [x] a\n', { total: 2, completed: 1 }],
34+
['> + [ ] a\n+ foo [x]bar a\n', { total: 1, completed: 0 }],
35+
['> - [X] `- [X] a`\n', { total: 1, completed: 1 }],
36+
['> \t - [X] `- [X] a`\n', { total: 1, completed: 1 }]
3237
]
3338

3439
testCases.forEach(testCase => {

0 commit comments

Comments
 (0)