Skip to content

Commit 7eca2c9

Browse files
committed
fix html attribute
1 parent 7a19124 commit 7eca2c9

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/coderay/scanners/liquid.rb

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Liquid < Scanner
55

66
register_for :liquid
77

8-
DIRECTIVE_KEYWORDS = "list|endlist|for|endfor|wrap|endwrap|if|endif|unless|endunless|elsif|assign|cycle|capture|end|capture|fill|iflist|endiflist|else"
8+
DIRECTIVE_KEYWORDS = "list|endlist|for|endfor|wrap|endwrap|if|endif|unless|endunless|elsif|assignlist|assign|cycle|capture|end|capture|fill|iflist|endiflist|else"
99

1010
DIRECTIVE_OPERATORS = "=|==|!=|>|<|<=|>=|contains"
1111

@@ -20,7 +20,7 @@ class Liquid < Scanner
2020
/x
2121

2222
def setup
23-
@html_scanner = CodeRay.scanner(:html, tokens: @tokens, keep_tokens: true, keep_state: false)
23+
@html_scanner = CodeRay.scanner(:html, tokens: @tokens, keep_tokens: true, keep_state: true)
2424
end
2525

2626
def scan_spaces(encoder)
@@ -31,7 +31,7 @@ def scan_spaces(encoder)
3131

3232
def scan_selector(encoder, options, match)
3333
scan_spaces(encoder)
34-
if match = scan(/in|with/)
34+
if match = scan(/in|with|script|tabs|items_per_tab/)
3535
Rails.logger.debug 'DEBUG: Scanning selector'
3636
scan_spaces(encoder)
3737
encoder.text_token match, :type
@@ -43,26 +43,29 @@ def scan_selector(encoder, options, match)
4343
encoder.text_token variable, :variable
4444
end
4545
scan_selector(encoder, options, match)
46+
else
47+
false
4648
end
4749
end
4850

4951
def scan_directive(encoder, options, match)
5052
Rails.logger.debug 'DEBUG: Scanning directive'
51-
encoder.text_token match, :key
53+
encoder.text_token match, :tag
5254
state = :liquid
5355
scan_spaces(encoder)
5456
#This regex doesn't work and I don't know why
5557
if match = scan(/#{DIRECTIVE_KEYWORDS}/)
5658
encoder.text_token match, :directive
5759
scan_spaces(encoder)
58-
if match =~ /if/
60+
if match =~ /if|assign|assignlist/
5961
if match = scan(/\w+\.?\w*/)
6062
encoder.text_token match, :variable
6163
end
6264
scan_spaces(encoder)
6365
if match = scan(/#{MATH}/)
6466
encoder.text_token match, :char
6567
scan_spaces(encoder)
68+
scan_selector(encoder, options, match)
6669
end
6770
if match = scan(/(\w+)|('\S+')|(".+")/)
6871
encoder.text_token match, :variable
@@ -73,7 +76,7 @@ def scan_directive(encoder, options, match)
7376
scan_selector(encoder, options, match)
7477
scan_spaces(encoder)
7578
if match = scan(/%}/)
76-
encoder.text_token match, :key
79+
encoder.text_token match, :tag
7780
state = :initial
7881
end
7982
end
@@ -98,18 +101,18 @@ def scan_output_filters(encoder, options, match)
98101

99102
def scan_output(encoder, options, match)
100103
Rails.logger.debug 'DEBUG: Scanning output'
101-
encoder.text_token match, :key
104+
encoder.text_token match, :tag
102105
state = :liquid
103106
scan_spaces(encoder)
104-
if match = scan(/(\w+)|('\S+')|("\w+")/)
107+
if match = scan(/(\w+\.?\w*)|('\S+')|("\w+")/)
105108
encoder.text_token match, :variable
106109
end
107110
if match = scan(/(\s\|\s)/)
108111
scan_output_filters(encoder, options, match)
109112
end
110113
scan_spaces(encoder)
111114
if match = scan(/}}/)
112-
encoder.text_token match, :key
115+
encoder.text_token match, :tag
113116
end
114117
state = :initial
115118
end
@@ -120,7 +123,13 @@ def scan_tokens(encoder, options)
120123

121124
until eos?
122125
if (match = scan_until(/(?=({{|{%))/) || scan_rest) and not match.empty? and state != :liquid
123-
@html_scanner.tokenize(match, tokens: encoder)
126+
Rails.logger.debug "DEBUG: HTML scanning: #{match}"
127+
if match =~ /^"|^'/
128+
#match = match.sub /^"|^'/, ''
129+
@html_scanner.tokenize(match, { tokens: encoder, state: :attribute_value_string })
130+
else
131+
@html_scanner.tokenize(match, tokens: encoder)
132+
end
124133
state = :initial
125134
scan_spaces(encoder)
126135
elsif match = scan(/{%/)

0 commit comments

Comments
 (0)