octopress-escape-code 2.0.4 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f9cd2dff39bb81d753dd1148b61c1c98e95f5ce0
4
- data.tar.gz: 21b9bc401c836632d65a8ecbfd50037688fa6bd6
3
+ metadata.gz: 6cbc0881b03f94478b02987c58fa37613ad6f870
4
+ data.tar.gz: 80995e2e9a41ea8bdce646a15242c9a6a84b8303
5
5
  SHA512:
6
- metadata.gz: d9482fbcdb4ea1b80637abaac324444c44a1770077c88dcb8d8991a212d87e49285a38fc38175a9073f25fa8afa1c453900a15068b900a72c6fcda9915cef16b
7
- data.tar.gz: 4447be2b8f732654a54fb96b590ae514c47cdcccfde5a3f877bf14826c22a0e24c34b570f78183f09bbb64f60e443739bacec876a1a2bb679bf0dd185a428fd9
6
+ metadata.gz: 0a160b60d9a79a12ea62eca8d08e899ba432bf27a322402cb514930351cc3839448c2bbefe29033836e28885e4bd610bdd06257e5bdd9219ef35e9000bdd3203
7
+ data.tar.gz: 40f698c97e87c299be2c0efd0c4130de9841cb5ef49b4383610ef8a57463c90c5dea12fd7ed8eff2cc587a86c24fe0f4cae1dbda7b97609a53169fe276287889
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 2.0.5 - 2015-01-04
4
+ - Simplified code escaping system, reducing use of raw tags.
5
+
3
6
  ### 2.0.4 - 2015-01-03
4
7
  - Updated regex order to allow different nested code block types.
5
8
 
@@ -14,7 +14,7 @@ module Octopress
14
14
  end
15
15
 
16
16
  def post_render(page)
17
- Octopress::EscapeCode.unescape_raw(page)
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.unescape_raw(page)
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
- "{% raw %}#{$1}\n{% endraw %}#{$3}"
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
- "{% raw %}#{$1}{% endraw %}"
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
- "{% raw %}#{$1}{% endraw %}"
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*endhighlight\s*%}/m do
97
- "#{$1}{% raw %}#{$2.gsub(/{% (end)?raw %}/, '')}{% endraw %}{% endhighlight %}"
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 %}/, '').gsub(/{% endraw %}/, '')
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 %}"
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module EscapeCode
3
- VERSION = "2.0.4"
3
+ VERSION = "2.0.5"
4
4
  end
5
5
  end
@@ -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'>&#x7b;% some tag that should break %&#x7d;
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">&quot;Check if a number is</span>
3
- <span class="s2">prime&quot;</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">&quot;Check if a number is prime&quot;</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"> (&#39;1&#39; * self) !~ /^1?$|^(11+?)\1+$/</span>
@@ -4,8 +4,7 @@
4
4
  hey
5
5
 
6
6
  ```ruby
7
- {% codeblock lang:ruby title:"Check if a number is
8
- prime" mark:3 %}
7
+ {% codeblock lang:ruby title:"Check if a number is prime" mark:3 %}
9
8
  class Fixnum
10
9
  def prime?
11
10
  ('1' * self) !~ /^1?$|^(11+?)\1+$/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-escape-code
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 2.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis