Skip to content

Commit baa788e

Browse files
committed
Clean up script detection
1 parent 914407a commit baa788e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/htmldiff.coffee

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ is_start_of_tag = (char)-> char is '<'
33
is_whitespace = (char)-> /^\s+$/.test char
44
is_tag = (token)-> /^\s*<[^>]+>\s*$/.test token
55
isnt_tag = (token)-> not is_tag token
6+
is_script_tag = (token) -> token is '<script'
7+
ends_in_end_script_tag = (token) ->
8+
token_end = token.substr token.length - 9
9+
token_end is '</script>'
610

711
class Match
812
constructor: (@start_in_before, @start_in_after, @length)->
@@ -22,8 +26,7 @@ html_to_tokens = (html)->
2226
when 'script'
2327
if is_end_of_tag char
2428
current_word += '>'
25-
end = current_word.substr current_word.length - 9
26-
if end is '</script>'
29+
if ends_in_end_script_tag current_word
2730
words.push current_word
2831
current_word = ''
2932
if is_whitespace char
@@ -33,7 +36,7 @@ html_to_tokens = (html)->
3336
else
3437
current_word += char
3538
when 'tag'
36-
if current_word is '<script'
39+
if is_script_tag current_word
3740
mode = 'script'
3841
current_word += char
3942
else if is_end_of_tag char

0 commit comments

Comments
 (0)