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

Commit 6be4073

Browse files
committed
Support rendering incomplete task list items with non-breaking spaces
1 parent f345d13 commit 6be4073

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/task_list/filter.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ def self.filter(*args)
3131
# :task_list_items - An array of TaskList::Item objects.
3232
class Filter < HTML::Pipeline::Filter
3333

34-
Incomplete = "[ ]".freeze
35-
Complete = "[x]".freeze
34+
Incomplete = "[ ]".freeze
35+
IncompleteNBSP = "[\xC2\xA0]".freeze
36+
Complete = "[x]".freeze
3637

3738
# Pattern used to identify all task list items.
3839
# Useful when you need iterate over all items.
@@ -42,7 +43,8 @@ class Filter < HTML::Pipeline::Filter
4243
\s* # optional whitespace prefix
4344
( # checkbox
4445
#{Regexp.escape(Complete)}|
45-
#{Regexp.escape(Incomplete)}
46+
#{Regexp.escape(Incomplete)}|
47+
#{Regexp.escape(IncompleteNBSP)}
4648
)
4749
(?=\s) # followed by whitespace
4850
/x
@@ -51,9 +53,11 @@ class Filter < HTML::Pipeline::Filter
5153
# select UL/OL
5254
".//li[starts-with(text(),'[ ]')]/..",
5355
".//li[starts-with(text(),'[x]')]/..",
56+
".//li[starts-with(text(),'[\xC2\xA0]')]/..",
5457
# and those wrapped in Ps
5558
".//li/p[1][starts-with(text(),'[ ]')]/../..",
56-
".//li/p[1][starts-with(text(),'[x]')]/../.."
59+
".//li/p[1][starts-with(text(),'[x]')]/../..",
60+
".//li/p[1][starts-with(text(),'[\xC2\xA0]')]/../.."
5761
].join(' | ').freeze
5862

5963
# Selects all LIs from a TaskList UL/OL

test/task_list/filter_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ def test_handles_encoding_correctly
7878
assert_equal unicode, item.text.strip
7979
end
8080

81+
# NOTE: This is an edge case experienced regularly by users using a Swiss
82+
# German keyboard.
83+
def test_non_breaking_space_between_brackets
84+
text = "- [\xC2\xA0] ok"
85+
assert item = filter(text)[:output].css('.task-list-item').pop, "item expected"
86+
assert_equal 'ok', item.text.strip
87+
end
88+
8189
protected
8290

8391
def filter(input, context = @context, result = nil)

0 commit comments

Comments
 (0)