octopress-escape-code 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/octopress-escape-code.rb +19 -30
- data/lib/octopress-escape-code/version.rb +1 -1
- data/test/_expected/index.html +1 -1
- data/test/_expected/nested-codeblocks.html +1 -2
- data/test/nested-codeblocks.md +1 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6cbc0881b03f94478b02987c58fa37613ad6f870
|
4
|
+
data.tar.gz: 80995e2e9a41ea8bdce646a15242c9a6a84b8303
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a160b60d9a79a12ea62eca8d08e899ba432bf27a322402cb514930351cc3839448c2bbefe29033836e28885e4bd610bdd06257e5bdd9219ef35e9000bdd3203
|
7
|
+
data.tar.gz: 40f698c97e87c299be2c0efd0c4130de9841cb5ef49b4383610ef8a57463c90c5dea12fd7ed8eff2cc587a86c24fe0f4cae1dbda7b97609a53169fe276287889
|
data/CHANGELOG.md
CHANGED
@@ -14,7 +14,7 @@ module Octopress
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def post_render(page)
|
17
|
-
Octopress::EscapeCode.
|
17
|
+
Octopress::EscapeCode.unescape_brackets(page.output)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -28,14 +28,10 @@ module Octopress
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def post_render(page)
|
31
|
-
Octopress::EscapeCode.
|
31
|
+
Octopress::EscapeCode.unescape_brackets(page.output)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
def self.unescape_raw(page)
|
36
|
-
page.output.gsub!(/\*-(end)?raw-\*/, '% \1raw %')
|
37
|
-
end
|
38
|
-
|
39
35
|
def self.escape_enabled?(page)
|
40
36
|
get_config(page, 'escape_code', false)
|
41
37
|
end
|
@@ -50,51 +46,44 @@ module Octopress
|
|
50
46
|
page_config
|
51
47
|
end
|
52
48
|
|
49
|
+
def self.escape_brackets(content)
|
50
|
+
content.gsub(/{/,'{').gsub(/}/, '}')
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.unescape_brackets(content)
|
54
|
+
content.gsub!(/&(amp;)?#x7b;/, '{')
|
55
|
+
content.gsub!(/&(amp;)?#x7d;/, '}')
|
56
|
+
content
|
57
|
+
end
|
58
|
+
|
53
59
|
def self.escape(page)
|
54
60
|
ext = page.ext.downcase
|
55
61
|
content = page.content.encode!("UTF-8")
|
56
62
|
md_ext = %w{.markdown .mdown .mkdn .md .mkd .mdwn .mdtxt .mdtext}
|
57
63
|
|
58
|
-
# Escape existing raw tags
|
59
|
-
#
|
60
|
-
content = content.gsub(/% (end)?raw %/, '*-\1raw-*')
|
61
|
-
|
62
64
|
# Escape markdown style code blocks
|
63
65
|
if md_ext.include?(ext)
|
64
66
|
|
65
67
|
# Escape four tab or space indented code blocks
|
66
68
|
content = content.gsub /^((\t| {4})[^\n].+?)\n($|\S)/m do
|
67
|
-
"{
|
69
|
+
"#{escape_brackets $1}\n#{$3}"
|
68
70
|
end
|
69
71
|
|
70
72
|
# Escape in-line code backticks
|
71
73
|
content = content.gsub /(`[^`\n]+?`)/ do
|
72
|
-
"{
|
74
|
+
"#{escape_brackets $1}"
|
73
75
|
end
|
74
76
|
|
75
77
|
# Escape in-line code double backticks
|
76
78
|
content = content.gsub /(``[^\n]+?``)/ do
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
# Remove internal raw tags within tab or space intented codeblocks
|
81
|
-
content = content.gsub /^({% raw %})?((\t| {4})[^\n].+?)\n($|\S)/m do
|
82
|
-
c1 = $1
|
83
|
-
c2 = $2
|
84
|
-
c4 = $4
|
85
|
-
|
86
|
-
"#{c1}#{c2.gsub(/{% (end)?raw %}/, '')}\n#{c4}"
|
79
|
+
escape_brackets $1
|
87
80
|
end
|
88
|
-
end
|
89
81
|
|
90
|
-
# Escape codeblock tag contents
|
91
|
-
content = content.gsub /^({%\s*codeblock.+?%})(.+?){%\s*endcodeblock\s*%}/m do
|
92
|
-
"#{$1}{% raw %}#{$2.gsub /{% (end)?raw %}/, ''}{% endraw %}{% endcodeblock %}"
|
93
82
|
end
|
94
83
|
|
95
|
-
# Escape highlight tag contents
|
96
|
-
content = content.gsub /^({%\s*highlight.+?%})(.+?){%\s*
|
97
|
-
"#{$1}{% raw %}#{$
|
84
|
+
# Escape highlight and codeblock tag contents
|
85
|
+
content = content.gsub /^({%\s*(codeblock|highlight).+?%})(.+?){%\s*end(codeblock|highlight)\s*%}/m do
|
86
|
+
"#{$1}{% raw %}#{unescape_brackets $3}{% endraw %}{% end#{$4} %}"
|
98
87
|
end
|
99
88
|
|
100
89
|
# Escape codefenced codeblocks
|
@@ -104,7 +93,7 @@ module Octopress
|
|
104
93
|
# as some of the regex above may have escaped contents
|
105
94
|
# of the codefence block
|
106
95
|
#
|
107
|
-
code = $1.gsub(/{% raw %}/, '')
|
96
|
+
code = unescape_brackets($1).gsub(/{% (end)?raw %}/, '')
|
108
97
|
|
109
98
|
# Wrap codefence content in raw tags
|
110
99
|
"{% raw %}\n#{code}\n{% endraw %}"
|
data/test/_expected/index.html
CHANGED
@@ -18,7 +18,7 @@ Stuff!</code></pre></div>
|
|
18
18
|
|
19
19
|
<figure class='code-highlight-figure'><figcaption class='code-highlight-caption'><span class='code-highlight-caption-title'>html</span></figcaption><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='1' class='code-highlight-row numbered'><div class='code-highlight-line'>Some kind of example:
|
20
20
|
</div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'> stuff
|
21
|
-
</div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'
|
21
|
+
</div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'>{% some tag that should break %}
|
22
22
|
</div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'>Stuff!</div></div></pre></div></figure>
|
23
23
|
<div class="highlight"><pre><code class="language-text" data-lang="text">stuff
|
24
24
|
{% foo %}
|
@@ -1,6 +1,5 @@
|
|
1
1
|
<p>hey</p>
|
2
|
-
<div class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="p">{</span><span class="o">%</span> <span class="n">codeblock</span> <span class="ss">lang</span><span class="p">:</span><span class="n">ruby</span> <span class="ss">title</span><span class="p">:</span><span class="s2">"Check if a number is</span>
|
3
|
-
<span class="s2">prime"</span> <span class="ss">mark</span><span class="p">:</span><span class="mi">3</span> <span class="sx">%}</span>
|
2
|
+
<div class="highlight"><pre><code class="language-ruby" data-lang="ruby"><span class="p">{</span><span class="o">%</span> <span class="n">codeblock</span> <span class="ss">lang</span><span class="p">:</span><span class="n">ruby</span> <span class="ss">title</span><span class="p">:</span><span class="s2">"Check if a number is prime"</span> <span class="ss">mark</span><span class="p">:</span><span class="mi">3</span> <span class="sx">%}</span>
|
4
3
|
<span class="sx">class Fixnum</span>
|
5
4
|
<span class="sx"> def prime?</span>
|
6
5
|
<span class="sx"> ('1' * self) !~ /^1?$|^(11+?)\1+$/</span>
|
data/test/nested-codeblocks.md
CHANGED