@@ -31,9 +31,11 @@ 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- IncompleteNBSP = "[\xC2 \xA0 ]" . freeze
36- Complete = "[x]" . freeze
34+ Incomplete = "[ ]" . freeze
35+ Complete = "[x]" . freeze
36+
37+ IncompletePattern = /\[ [[:space:]]\] / . freeze # matches all whitespace
38+ CompletePattern = Regexp . escape ( Complete ) . freeze
3739
3840 # Pattern used to identify all task list items.
3941 # Useful when you need iterate over all items.
@@ -42,9 +44,8 @@ class Filter < HTML::Pipeline::Filter
4244 (?:\s *[-+*]|(?:\d +\. ))? # optional list prefix
4345 \s * # optional whitespace prefix
4446 ( # checkbox
45- #{ Regexp . escape ( Complete ) } |
46- #{ Regexp . escape ( Incomplete ) } |
47- #{ Regexp . escape ( IncompleteNBSP ) }
47+ #{ CompletePattern } |
48+ #{ IncompletePattern }
4849 )
4950 (?=\s ) # followed by whitespace
5051 /x
@@ -53,11 +54,9 @@ class Filter < HTML::Pipeline::Filter
5354 # select UL/OL
5455 ".//li[starts-with(text(),'[ ]')]/.." ,
5556 ".//li[starts-with(text(),'[x]')]/.." ,
56- ".//li[starts-with(text(),'[\xC2 \xA0 ]')]/.." ,
5757 # and those wrapped in Ps
5858 ".//li/p[1][starts-with(text(),'[ ]')]/../.." ,
59- ".//li/p[1][starts-with(text(),'[x]')]/../.." ,
60- ".//li/p[1][starts-with(text(),'[\xC2 \xA0 ]')]/../.."
59+ ".//li/p[1][starts-with(text(),'[x]')]/../.."
6160 ] . join ( ' | ' ) . freeze
6261
6362 # Selects all LIs from a TaskList UL/OL
0 commit comments