Skip to content

Commit c87241b

Browse files
committed
Put script blocks in single tokens
1 parent 4c25606 commit c87241b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/htmldiff.coffee

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,24 @@ html_to_tokens = (html)->
1919

2020
for char in html
2121
switch mode
22-
when 'tag'
22+
when 'script'
2323
if is_end_of_tag char
24+
current_word += '>'
25+
end = current_word.substr current_word.length - 8
26+
if end is '</script>'
27+
words.push current_word
28+
current_word = ''
29+
if is_whitespace char
30+
mode = 'whitespace'
31+
else
32+
mode = 'char'
33+
else
34+
current_word += char
35+
when 'tag'
36+
if current_word is '<script'
37+
mode = 'script'
38+
current_word += char
39+
else if is_end_of_tag char
2440
current_word += '>'
2541
words.push current_word
2642
current_word = ''

test/html_to_tokens.spec.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ describe 'html_to_tokens', ->
2828
it 'should identify self closing tags as tokens', ->
2929
(expect @cut '<p>hello</br>goodbye</p>')
3030
.eql ['<p>', 'hello', '</br>', 'goodbye', '</p>']
31+
32+
it 'should identify scripts as single tokens', ->
33+
(expect @cut '<script>int bob = 0;</script>')
34+
.eql ['<script>int bob = 0;</script>']

0 commit comments

Comments
 (0)