23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/rack/codehighlighter.rb', line 23
def call(env)
began_at = Time.now
status, , response = @app.call(env)
= HeaderHash.new()
if !STATUS_WITH_NO_ENTITY_BODY.include?(status) &&
!['transfer-encoding'] &&
['content-type'] &&
['content-type'].include?("text/html")
content = ""
response.each { |part| content += part }
doc = Nokogiri::HTML(content)
nodes = doc.search(@opts[:element])
nodes.each do |node|
s = node.inner_html || "[++where is the code?++]"
if @opts[:markdown]
node.parent.swap(send(@highlighter, s))
else
node.swap(send(@highlighter, s))
end
end
body = doc.to_html
['content-length'] = bytesize(body).to_s
log(env, status, , began_at) if @opts[:logging]
[status, , [body]]
else
[status, , response]
end
end
|