... | ... |
@@ -27,24 +27,36 @@ module OctopressFilters |
27 | 27 |
# ``` |
28 | 28 |
def backtick_codeblock(input) |
29 | 29 |
# Markdown support |
30 |
- input = input.gsub /<p>`{3}\s(\w+)<\/p>\s*<pre><code>\s*(.+?)\s*<\/code><\/pre>\s*<p>`{3}<\/p>/m do |
|
30 |
+ input = input.gsub /<p>`{3}\s*(\w+)?<\/p>\s*<pre><code>\s*(.+?)\s*<\/code><\/pre>\s*<p>`{3}<\/p>/m do |
|
31 | 31 |
lang = $1 |
32 |
- str = $2.gsub('<','<').gsub('>','>') |
|
33 |
- highlight(str, lang) |
|
32 |
+ if lang != '' |
|
33 |
+ str = $2.gsub('<','<').gsub('>','>') |
|
34 |
+ highlight(str, lang) |
|
35 |
+ else |
|
36 |
+ "<pre><code>#{$2}</code></pre>" |
|
37 |
+ end |
|
34 | 38 |
end |
35 | 39 |
|
36 | 40 |
# Textile support |
37 |
- input = input.gsub /<p>`{3}\s(\w+)<br\s*\/>\n(.+?)`{3}<\/p>/m do |
|
41 |
+ input = input.gsub /<p>`{3}\s*(\w+)?<br\s*\/>\n(.+?)`{3}<\/p>/m do |
|
38 | 42 |
lang = $1 |
39 | 43 |
str = $2.gsub('<','<').gsub('>','>').gsub(/^\s{4}/, '').gsub(/(<br\s\/>)?$/, '') |
40 |
- highlight(str, lang) |
|
44 |
+ if lang != '' |
|
45 |
+ highlight(str, lang) |
|
46 |
+ else |
|
47 |
+ "<pre><code>#{$2}</code></pre>" |
|
48 |
+ end |
|
41 | 49 |
end |
42 | 50 |
|
43 | 51 |
# Regular HTML support |
44 |
- input.gsub /^`{3}\s(\w+)\n(.+?)\n`{3}/m do |
|
52 |
+ input.gsub /^`{3}\s*(\w+)?\n(.+?)\n`{3}/m do |
|
45 | 53 |
lang = $1 |
46 | 54 |
str = $2.gsub(/^\s{4}/, '') |
47 |
- highlight(str, lang) |
|
55 |
+ if lang != '' |
|
56 |
+ highlight(str, lang) |
|
57 |
+ else |
|
58 |
+ "<pre><code>#{$2.gsub('<','<').gsub('>','>')}</code></pre>" |
|
59 |
+ end |
|
48 | 60 |
end |
49 | 61 |
end |
50 | 62 |
|