diff options
author | Brandon Mathis <brandon@imathis.com> | 2011-07-28 15:59:27 -0400 |
---|---|---|
committer | Brandon Mathis <brandon@imathis.com> | 2011-07-28 15:59:50 -0400 |
commit | 49a67785dcdfbdeca751ea600f0386080349a8ef (patch) | |
tree | 17f25c0c7714ee243fb975fe19811b18822a9b29 /plugins | |
parent | 2af038a7253682eac5ca108f24e98535cabc9dc0 (diff) | |
download | my_new_personal_website-49a67785dcdfbdeca751ea600f0386080349a8ef.tar.xz my_new_personal_website-49a67785dcdfbdeca751ea600f0386080349a8ef.zip |
Add support using github backtick code blocks without supplying a language
Diffstat (limited to '')
-rw-r--r-- | plugins/octopress_filters.rb | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index 21c24eed..f2a5073b 100644 --- a/plugins/octopress_filters.rb +++ b/plugins/octopress_filters.rb @@ -27,24 +27,36 @@ module OctopressFilters # ``` def backtick_codeblock(input) # Markdown support - input = input.gsub /<p>`{3}\s(\w+)<\/p>\s*<pre><code>\s*(.+?)\s*<\/code><\/pre>\s*<p>`{3}<\/p>/m do + input = input.gsub /<p>`{3}\s*(\w+)?<\/p>\s*<pre><code>\s*(.+?)\s*<\/code><\/pre>\s*<p>`{3}<\/p>/m do lang = $1 - str = $2.gsub('<','<').gsub('>','>') - highlight(str, lang) + if lang != '' + str = $2.gsub('<','<').gsub('>','>') + highlight(str, lang) + else + "<pre><code>#{$2}</code></pre>" + end end # Textile support - input = input.gsub /<p>`{3}\s(\w+)<br\s*\/>\n(.+?)`{3}<\/p>/m do + input = input.gsub /<p>`{3}\s*(\w+)?<br\s*\/>\n(.+?)`{3}<\/p>/m do lang = $1 str = $2.gsub('<','<').gsub('>','>').gsub(/^\s{4}/, '').gsub(/(<br\s\/>)?$/, '') - highlight(str, lang) + if lang != '' + highlight(str, lang) + else + "<pre><code>#{$2}</code></pre>" + end end # Regular HTML support - input.gsub /^`{3}\s(\w+)\n(.+?)\n`{3}/m do + input.gsub /^`{3}\s*(\w+)?\n(.+?)\n`{3}/m do lang = $1 str = $2.gsub(/^\s{4}/, '') - highlight(str, lang) + if lang != '' + highlight(str, lang) + else + "<pre><code>#{$2.gsub('<','<').gsub('>','>')}</code></pre>" + end end end |