Skip to content

Commit 7a2ce37

Browse files
authored
Merge pull request #9 from naqvis/fix-issue-8
Fix: spec issue and linting issues
2 parents 990093e + b66bf25 commit 7a2ce37

File tree

5 files changed

+34
-34
lines changed

5 files changed

+34
-34
lines changed

shard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
name: html5
2-
version: 0.4.0
2+
version: 0.5.0
33

44
authors:
55
- Ali Naqvi <[email protected]>
66
description: |
77
HTML5-compliant Parser and Tokenizer with XPath2 and CSS Selector support.
88
9-
crystal: ">= 0.36.0, < 2.0.0"
9+
crystal: ~> 1.0
1010

1111
dependencies:
1212
xpath2:

spec/token_spec.cr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -541,23 +541,23 @@ module HTML5
541541

542542
it "Test Convert New Lines" do
543543
tests = {
544-
"Mac\rDOS\r\nUnix\n" => "Mac\nDOS\nUnix\n",
545-
"Unix\nMac\rDOS\r\n" => "Unix\nMac\nDOS\n",
546-
"DOS\r\nDOS\r\nDOS\r\n": "DOS\nDOS\nDOS\n",
547-
"" => "",
548-
"\n" => "\n",
549-
"\n\r" => "\n\n",
550-
"\r" => "\n",
551-
"\r\n" => "\n",
552-
"\r\n\n" => "\n\n",
553-
"\r\n\r" => "\n\n",
554-
"\r\n\r\n" => "\n\n",
555-
"\r\r" => "\n\n",
556-
"\r\r\n" => "\n\n",
557-
"\r\r\n\n" => "\n\n\n",
558-
"\r\r\r\n" => "\n\n\n",
559-
"\r \n" => "\n \n",
560-
"xyz" => "xyz",
544+
"Mac\rDOS\r\nUnix\n" => "Mac\nDOS\nUnix\n",
545+
"Unix\nMac\rDOS\r\n" => "Unix\nMac\nDOS\n",
546+
"DOS\r\nDOS\r\nDOS\r\n" => "DOS\nDOS\nDOS\n",
547+
"" => "",
548+
"\n" => "\n",
549+
"\n\r" => "\n\n",
550+
"\r" => "\n",
551+
"\r\n" => "\n",
552+
"\r\n\n" => "\n\n",
553+
"\r\n\r" => "\n\n",
554+
"\r\n\r\n" => "\n\n",
555+
"\r\r" => "\n\n",
556+
"\r\r\n" => "\n\n",
557+
"\r\r\n\n" => "\n\n\n",
558+
"\r\r\r\n" => "\n\n\n",
559+
"\r \n" => "\n \n",
560+
"xyz" => "xyz",
561561
}
562562

563563
tests.each do |k, v|

src/html5.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Parsing is done by calling `HTML5.parse` with either a String containing HTML
1515
# or an IO instance. `HTML5.parse` returns a document root as `HTML5::Node` instance.
1616
module HTML5
17-
VERSION = "0.4.0"
17+
VERSION = "0.5.0"
1818

1919
class HTMLException < Exception
2020
end

src/html5/css/lexer.cr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ module CSS
269269
raise CSSException.new("expected ' or \" before calling parse_string") unless ['\'', '"'].includes?(schar)
270270
loop do
271271
case r = self.next
272-
when EOF then raise ("unmatched string quote")
273-
when '\n', '\r', '\f' then raise ("invalid unescaped string character")
272+
when EOF then raise("unmatched string quote")
273+
when '\n', '\r', '\f' then raise("invalid unescaped string character")
274274
when '\\'
275275
case self.peek
276276
when '\n', '\f' then self.next

src/html5/css/selector.cr

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,16 @@ module CSS
3535
def initialize(@sel_seq : SelectorSequence, @combs = Array(CombinatorSelector).new)
3636
end
3737

38-
def select(n : HTML5::Node, matched = [] of HTML5::Node) : Array(HTML5::Node)
39-
matched = @sel_seq.select(n, matched)
38+
def select(n : HTML5::Node, selected = [] of HTML5::Node) : Array(HTML5::Node)
39+
selected = @sel_seq.select(n, selected)
4040
@combs.each do |comb|
4141
comb_matched = [] of HTML5::Node
42-
matched.each do |m|
42+
selected.each do |m|
4343
comb_matched = comb.select(m, comb_matched)
4444
end
45-
matched = comb_matched
45+
selected = comb_matched
4646
end
47-
matched
47+
selected
4848
end
4949
end
5050

@@ -107,38 +107,38 @@ module CSS
107107
def initialize(@combinator : TokenType, @sel_seq : SelectorSequence)
108108
end
109109

110-
def select(n : HTML5::Node, matched = [] of HTML5::Node) : Array(HTML5::Node)
110+
def select(n : HTML5::Node, selected = [] of HTML5::Node) : Array(HTML5::Node)
111111
case @combinator
112112
when .greater?
113113
child = n.first_child
114114
while (child)
115-
matched << child if @sel_seq.matches(child) && !child.parent.nil?
115+
selected << child if @sel_seq.matches(child) && !child.parent.nil?
116116
child = child.next_sibling
117117
end
118118
when .tilde?
119119
sibl = n.next_sibling
120120
while (sibl)
121-
matched << sibl if @sel_seq.matches(sibl) && !matched.includes?(sibl)
121+
selected << sibl if @sel_seq.matches(sibl) && !selected.includes?(sibl)
122122
sibl = sibl.next_sibling
123123
end
124124
when .plus?
125125
sibl = n.next_sibling
126126
while (sibl)
127-
matched << sibl if @sel_seq.matches(sibl)
127+
selected << sibl if @sel_seq.matches(sibl)
128128
# check matches against only the first element
129129
break if sibl.element?
130130
sibl = sibl.next_sibling
131131
end
132132
when .not?
133-
matched << n if !@sel_seq.matches(n)
133+
selected << n if !@sel_seq.matches(n)
134134
else
135135
child = n.first_child
136136
while (child)
137-
matched = @sel_seq.select(child, matched)
137+
selected = @sel_seq.select(child, selected)
138138
child = child.next_sibling
139139
end
140140
end
141-
matched
141+
selected
142142
end
143143
end
144144

0 commit comments

Comments
 (0)