PREFIX = '
' POSTFIX = '' Jekyll::Hooks.register [:documents, :pages], :post_render do |doc| if doc.output_ext == ".html" && doc.type != :slides code_block_counter = 1 doc.output = doc.output.gsub(/
[\n0-9]+<\/pre>/) do |match| line_numbers = match .gsub(/([\n0-9]+)<\/pre>/, '\1') .split("\n") anchored_line_numbers_array = line_numbers.map do |n| id = "B#{code_block_counter}-L#{n}" "#{n}" end code_block_counter += 1 PREFIX + anchored_line_numbers_array.join("\n") + POSTFIX end end end