Add support using github backtick code blocks without supplying a language

source
Brandon Mathis 2011-07-28 15:59:27 -04:00
parent 2af038a725
commit 49a67785dc
1 changed files with 19 additions and 7 deletions

View File

@ -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('&lt;','<').gsub('&gt;','>')
highlight(str, lang)
if lang != ''
str = $2.gsub('&lt;','<').gsub('&gt;','>')
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('&lt;','<').gsub('&gt;','>').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('<','&lt;').gsub('>','&gt;')}</code></pre>"
end
end
end