From 49a67785dcdfbdeca751ea600f0386080349a8ef Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Thu, 28 Jul 2011 15:59:27 -0400 Subject: [PATCH] Add support using github backtick code blocks without supplying a language --- plugins/octopress_filters.rb | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/plugins/octopress_filters.rb b/plugins/octopress_filters.rb index 21c24ee..f2a5073 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 /

`{3}\s(\w+)<\/p>\s*

\s*(.+?)\s*<\/code><\/pre>\s*

`{3}<\/p>/m do + input = input.gsub /

`{3}\s*(\w+)?<\/p>\s*

\s*(.+?)\s*<\/code><\/pre>\s*

`{3}<\/p>/m do lang = $1 - str = $2.gsub('<','<').gsub('>','>') - highlight(str, lang) + if lang != '' + str = $2.gsub('<','<').gsub('>','>') + highlight(str, lang) + else + "

#{$2}
" + end end # Textile support - input = input.gsub /

`{3}\s(\w+)\n(.+?)`{3}<\/p>/m do + input = input.gsub /

`{3}\s*(\w+)?\n(.+?)`{3}<\/p>/m do lang = $1 str = $2.gsub('<','<').gsub('>','>').gsub(/^\s{4}/, '').gsub(/()?$/, '') - highlight(str, lang) + if lang != '' + highlight(str, lang) + else + "

#{$2}
" + 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 + "
#{$2.gsub('<','<').gsub('>','>')}
" + end end end