Skip to content

Commit

Permalink
Simplify code block line numbers
Browse files Browse the repository at this point in the history
This pretty much undoes ddf7c09. Check out that commit for motivation on
why it was that way.
  • Loading branch information
skanev committed Mar 22, 2013
1 parent bddd427 commit 9973f5c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
10 changes: 1 addition & 9 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ def tip_of_the_day
render 'common/tip_of_the_day', tip: Tip.current
end

# A *very* ugly way to get CodeRay to display formatted code in the way we
# want it. Naturally, using the table format in CodeRay is good enough for
# just showing it, but commenting on specific lines add a bunch of
# requirements on what we want to show.
def format_code(code)
content_tag :table, class: 'CodeRay' do
lines = CodeRay.scan(code, Language.language).html(line_numbers: :inline, bold_every: false, line_number_anchors: false, css: :class).lines
rows = lines.map { |line| line.sub %r{\A<span class="line-numbers">(\s*\d+)</span>(.*)\Z}, '<tr><td>\1</td><td>\2</td></tr>' }
rows.join("\n").html_safe
end
CodeRay.scan(code, Language.language).html(line_numbers: :table, bold_every: false, line_number_anchors: false, css: :class).html_safe
end
end
4 changes: 1 addition & 3 deletions vendor/assets/stylesheets/coderay.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ span.CodeRay { white-space: pre; border: 0px; padding: 2px }

table.CodeRay { border-collapse: collapse; width: 100%; padding: 2px }
table.CodeRay td { vertical-align: top; }
table.CodeRay td:first-child { width: 30px; padding-right: 10px; text-align: right; }
table.CodeRay tr:first-child td { padding-top: 1ex; }
table.CodeRay tr:last-child td { padding-bottom: 1ex; }
table.CodeRay td:first-child { width: 30px; text-align: right; }

.CodeRay .line-numbers, .CodeRay .no {
background-color: #ECECEC;
Expand Down

0 comments on commit 9973f5c

Please sign in to comment.