all repos — h3rald @ 6ed04d62656d222df819ecfd406a5afb3166d316

The sources of https://h3rald.com

lib/highlighter.rb

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
# Monkey patch Nanoc::Helpers::Filtering

module Nanoc3::Helpers::Filtering

	def highlight(syntax, &block)
		# Seamlessly ripped off from the filter method...
		# Capture block
		data = capture(&block)
		# Reconvert <% %>
		data.gsub! /&lt;%/, '<%'
		data.gsub! /%&gt;/, '%>'
		# Filter captured data
		filtered_data = "\n<notextile>"+Albino.colorize(data, syntax)+"</notextile>\n" rescue data 
		# Append filtered data to buffer
		buffer = eval('_erbout', block.binding)
		buffer << filtered_data
	end

end

include Nanoc3::Helpers::Filtering