./lib/dolt/view/blob.rb in dolt-0.2.1 vs ./lib/dolt/view/blob.rb in dolt-0.2.2

- old
+ new

@@ -18,15 +18,19 @@ require "htmlentities" module Dolt module View module Blob - def format_blob(path, content) + def entityfy(content) @coder ||= HTMLEntities.new - multiline(@coder.encode(content)) + @coder.encode(content) end + def format_blob(path, content) + multiline(entityfy(content)) + end + def blob_url(repository, ref, path) repo_url(repository, "/blob/#{ref}:#{path}") end def blame_url(repository, ref, path) @@ -39,17 +43,24 @@ def raw_url(repository, ref, path) repo_url(repository, "/raw/#{ref}:#{path}") end + def format_whitespace(text) + text + end + def multiline(blob, options = {}) class_names = options[:class_names] || [] class_names << "prettyprint" << "linenums" num = 0 lines = blob.split("\n").inject("") do |html, line| num += 1 - line = line.gsub(/\t/, " ") + # Empty elements causes annoying rendering artefacts + # Forcing one space on each line affects copy-paste negatively + # TODO: Don't force one space, find CSS fix + line = format_whitespace(line).sub(/^$/, " ") "#{html}<li class=\"L#{num}\"><span class=\"line\">#{line}</span></li>" end "<pre class=\"#{class_names.join(' ')}\">" + "<ol class=\"linenums\">#{lines}</ol></pre>"