Skip to content
This repository was archived by the owner on Aug 27, 2021. It is now read-only.

Commit 4a56735

Browse files
committed
added support for github style backtick code blocks
1 parent 2e66d1e commit 4a56735

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

.themes/classic/source/_layouts/default.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<nav role=navigation>{% include navigation.html %}</nav>
66
<div id="main">
77
<div id="content">
8-
{{ content | expand_urls: root_url | smart_quotes }}
8+
{{ content | expand_urls: root_url | backtick_codeblock | smart_quotes }}
99
{% unless page.sidebar == false %}
1010
<aside role=sidebar>{% include sidebar.html %}</aside>
1111
{% endunless %}

plugins/octopress_filters.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#custom filters for Octopress
2+
require './plugins/pygments_code'
23

34
module OctopressFilters
5+
include HighlightCode
46
# Used on the blog index to split posts on the <!--more--> marker
57
def excerpt(input)
68
if input.index(/<!--\s*more\s*-->/i)
@@ -19,6 +21,18 @@ def summary(input)
1921
end
2022
end
2123

24+
# for Github style codeblocks eg.
25+
# ``` ruby
26+
# code snippet
27+
# ```
28+
def backtick_codeblock(input)
29+
input.gsub /<p>`{3}\s(\w+)<\/p>.+<pre><code>(.+)<\/code><\/pre>.+`{3}<\/p>/m do
30+
lang = $1
31+
str = $2.gsub(/^\s{4}/, '').gsub('&lt;','<').gsub('&gt;','>')
32+
highlight(str, lang)
33+
end
34+
end
35+
2236
# Replaces relative urls with full urls
2337
def expand_urls(input, url='')
2438
url ||= '/'

0 commit comments

Comments
 (0)