Skip to content
This repository has been archived by the owner on Nov 1, 2017. It is now read-only.

Commit

Permalink
Merge pull request #41 from github/skip-links-not-items-with-links
Browse files Browse the repository at this point in the history
Updates should not ignore items with links
  • Loading branch information
mtodd committed Sep 26, 2014
2 parents b3b4514 + 9bd8e69 commit b43e109
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
11 changes: 7 additions & 4 deletions app/assets/javascripts/task_list.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ itemPattern = ///
#{escapePattern(complete)}|
#{escapePattern(incomplete)}
)
(?! # is not a link
\s* # with optional whitespace
(?:\(.*?\)|\[.*?\]) # because of destination or reference
\s+ # is followed by whitespace
(?!
\(.*?\) # is not part of a [foo](url) link
)
(?= # and is followed by zero or more links
(?:\[.*?\]\s*(?:\[.*?\]|\(.*?\))\s*)*
(?:[^\[]|$) # and either a non-link or the end of the string
)
(?=\s) # is followed by whitespace
///

# Used to filter out code fences from the source for comparison only.
Expand Down
58 changes: 58 additions & 0 deletions test/unit/test_updates.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -506,3 +506,61 @@ asyncTest "update ignores items that look like Task List items but are links", -
, 20

item2Checkbox.click()

asyncTest "updates items followed by links", ->
expect 3

$('#qunit-fixture').empty()

container = $ '<div>', class: 'js-task-list-container'

list = $ '<ul>', class: 'task-list'

item1 = $ '<li>', class: 'task-list-item'
item1Checkbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: false

item2 = $ '<li>', class: 'task-list-item'
item2Checkbox = $ '<input>',
type: 'checkbox'
class: 'task-list-item-checkbox'
disabled: true
checked: false

field = $ '<textarea>', class: 'js-task-list-field', text: """
- [ ] [link label](link)
- [ ] [reference label][reference]
"""

changes = """
- [ ] [link label](link)
- [x] [reference label][reference]
"""

item1.append item1Checkbox
list.append item1
item1.expectedIndex = 1

item2.append item2Checkbox
list.append item2
item2.expectedIndex = 2

container.append list
container.append field

$('#qunit-fixture').append(container)
container.taskList()

field.on 'tasklist:changed', (event, index, checked) =>
ok checked
equal index, item2.expectedIndex
equal field.val(), changes

setTimeout ->
start()
, 20

item2Checkbox.click()

0 comments on commit b43e109

Please sign in to comment.