Permalink
Browse files

support for code block titles

  • Loading branch information...
1 parent f0c0298 commit bec53deadd92f5e7eed9bc283f4cb026140b7b8e @adamcooke adamcooke committed Oct 29, 2013
Showing with 28 additions and 3 deletions.
  1. +21 −1 app/assets/stylesheets/page.scss
  2. +7 −2 lib/shoppe/markdown_renderer.rb
@@ -155,11 +155,31 @@ section.page {
ul li { background:image-url('icons/pin.svg') no-repeat 0 4px; background-size:16px; padding-left:25px;}
ol { margin-left:40px;}
+ p.codeTitle {
+ background:#f7f7f7;
+ margin-bottom:0;
+ line-height:1;
+ border-top-left-radius:6px;
+ border-top-right-radius:6px;
+ padding:7px 10px;
+ font-size:1.0em;
+ font-weight:600;
+ color:#666;
+ border:1px solid #ddd;
+ border-bottom:0;
+ }
+
+ p.codeTitle + div.highlight pre {
+ margin-top:0 !important;
+ border-top-left-radius:0;
+ border-top-right-radius:0;
+ }
+
pre {
margin:25px 0;
line-height:1.4;
padding:10px;
- border-radius:4px;
+ border-radius:6px;
overflow-x:auto;
word-wrap: normal;
white-space: pre;
@@ -6,9 +6,14 @@ def header(text, header_level)
end
def block_code(code, language)
- Pygments.highlight(code, :lexer => language)
+ title = nil
+ code.gsub!(/\A\:\:(.*)$/) { title = $1 ; nil }
+ String.new.tap do |s|
+ s << "<p class='codeTitle'>#{title}</p>" if title
+ s << Pygments.highlight(code, :lexer => language)
+ end
rescue
- content_tag(:pre, code)
+ "<div class='highlight'><pre>#{code}</pre></div>"
end
end

0 comments on commit bec53de

Please sign in to comment.