Skip to content

Commit 864a7b2

Browse files
committed
Cleaner way to separate whitespace runs from fluff
1 parent 162ccf9 commit 864a7b2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lib/coderay/scanners/lua.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,9 @@ def scan_tokens(tokens, options)
148148
# We use the block form of gsub instead of the StringScanner capabilities because StringScanner does not support named captures in 1.9
149149
remainder_index = 0
150150

151-
boring_kinds = [:space,:content]
152151
add_boring = ->(fluff) do
153-
fluff.split(/(\S+)/).each.with_index do |text,i|
154-
tokens.text_token(text, boring_kinds[i%2]) unless text.empty?
152+
fluff.scan(/((\s+)|(\S+))/).each do |text,ws,nws|
153+
tokens.text_token(text, ws ? :space : :content)
155154
end
156155
end
157156

0 commit comments

Comments
 (0)