lib/rouge/formatter.rb in rouge-1.11.1 vs lib/rouge/formatter.rb in rouge-2.0.0
- old
+ new
@@ -23,10 +23,14 @@
# Format a token stream. Delegates to {#format}.
def self.format(tokens, opts={}, &b)
new(opts).format(tokens, &b)
end
+ def initialize(opts={})
+ # pass
+ end
+
# Format a token stream.
def format(tokens, &b)
return stream(tokens, &b) if block_given?
out = ''
@@ -44,7 +48,28 @@
# @abstract
# yield strings that, when concatenated, form the formatted output
def stream(tokens, &b)
raise 'abstract'
end
+
+ protected
+ def token_lines(tokens, &b)
+ return enum_for(:lines, tokens) unless block_given?
+
+ out = []
+ tokens.each do |tok, val|
+ val.scan /\n|[^\n]+/ do |s|
+ if s == "\n"
+ yield out
+ out = []
+ else
+ out << [tok, s]
+ end
+ end
+ end
+
+ # for inputs not ending in a newline
+ yield out if out.any?
+ end
+
end
end