lib/octopress-escape-code.rb in octopress-escape-code-2.0.1 vs lib/octopress-escape-code.rb in octopress-escape-code-2.0.3
- old
+ new
@@ -3,10 +3,12 @@
module Octopress
module EscapeCode
class EscapePage < Octopress::Hooks::Page
+ priority :lowest
+
def pre_render(page)
if Octopress::EscapeCode.escape_enabled?(page)
page.content = Octopress::EscapeCode.escape(page)
end
end
@@ -15,10 +17,12 @@
Octopress::EscapeCode.unescape_raw(page)
end
end
class EscapePost < Octopress::Hooks::Post
+ priority :lowest
+
def pre_render(page)
if Octopress::EscapeCode.escape_enabled?(page)
page.content = Octopress::EscapeCode.escape(page)
end
end
@@ -56,20 +60,14 @@
content = content.gsub(/% (end)?raw %/, '*-\1raw-*')
# Escape markdown style code blocks
if md_ext.include?(ext)
- # Escape four space indented code blocks
- content = content.gsub /^( {4}[^\n].+?)\n($|\S)/m do
- "{% raw %}#{$1}\n{% endraw %}#{$2}"
+ # Escape four tab or space indented code blocks
+ content = content.gsub /^((\t| {4})[^\n].+?)\n($|\S)/m do
+ "{% raw %}#{$1}\n{% endraw %}#{$3}"
end
-
-
- # Escape tab indented code blocks
- content = content.gsub /^(\t[^\n].+?)\n($|\S)/m do
- "{% raw %}#{$1}\n{% endraw %}#{$2}"
- end
# Escape in-line code backticks
content = content.gsub /(`[^`\n]+?`)/ do
"{% raw %}#{$1}{% endraw %}"
end
@@ -77,22 +75,16 @@
# Escape in-line code double backticks
content = content.gsub /(``[^\n]+?``)/ do
"{% raw %}#{$1}{% endraw %}"
end
- # Remove internal raw tags within space intented codeblocks
- content = content.gsub /( {4}[^\n].+?)\n($|\S)/m do
+ # Remove internal raw tags within tab or space intented codeblocks
+ content = content.gsub /^({% raw %})?((\t| {4})[^\n].+?)\n($|\S)/m do
c1 = $1
c2 = $2
+ c4 = $4
- "#{c1.gsub(/{% (end)?raw %}/, '')}\n#{c2}"
- end
-
- # Remove internal raw tags within tab intented codeblocks
- content = content.gsub /(\t[^\n].+?)\n($|\S)/m do
- c1 = $1
- c2 = $2
- "#{c1.gsub(/{% (end)?raw %}/, '')}\n#{c2}"
+ "#{c1}#{c2.gsub(/{% (end)?raw %}/, '')}\n#{c4}"
end
end
# Escape codefenced codeblocks
content = content.gsub /^(`{3}.+?`{3})/m do