added support for github style backtick code blocks

This commit is contained in:
Brandon Mathis 2011-07-26 23:37:31 -04:00
parent 786b8e8783
commit 6e2beaa969
2 changed files with 15 additions and 1 deletions

View File

@ -5,7 +5,7 @@
<nav role=navigation>{% include navigation.html %}</nav> <nav role=navigation>{% include navigation.html %}</nav>
<div id="main"> <div id="main">
<div id="content"> <div id="content">
{{ content | expand_urls: root_url | smart_quotes }} {{ content | expand_urls: root_url | backtick_codeblock | smart_quotes }}
{% unless page.sidebar == false %} {% unless page.sidebar == false %}
<aside role=sidebar>{% include sidebar.html %}</aside> <aside role=sidebar>{% include sidebar.html %}</aside>
{% endunless %} {% endunless %}

View File

@ -1,6 +1,8 @@
#custom filters for Octopress #custom filters for Octopress
require './plugins/pygments_code'
module OctopressFilters module OctopressFilters
include HighlightCode
# Used on the blog index to split posts on the <!--more--> marker # Used on the blog index to split posts on the <!--more--> marker
def excerpt(input) def excerpt(input)
if input.index(/<!--\s*more\s*-->/i) if input.index(/<!--\s*more\s*-->/i)
@ -19,6 +21,18 @@ module OctopressFilters
end end
end end
# for Github style codeblocks eg.
# ``` ruby
# code snippet
# ```
def backtick_codeblock(input)
input.gsub /<p>`{3}\s(\w+)<\/p>.+<pre><code>(.+)<\/code><\/pre>.+`{3}<\/p>/m do
lang = $1
str = $2.gsub(/^\s{4}/, '').gsub('&lt;','<').gsub('&gt;','>')
highlight(str, lang)
end
end
# Replaces relative urls with full urls # Replaces relative urls with full urls
def expand_urls(input, url='') def expand_urls(input, url='')
url ||= '/' url ||= '/'