octopress-escape-code 1.0.3 → 1.0.4

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: 080cc036a9e132f9d0b5f6c4c7531e59e63d134a
4
- data.tar.gz: 447d073260a2e42364acb4b929edd8749c2e67a0
3
+ metadata.gz: 4781e02240e67f367bed8d7ea219bd5087915b28
4
+ data.tar.gz: 875502e016e25e1ff6228221b8fc9fa8144735cb
5
5
  SHA512:
6
- metadata.gz: 64a4526d32f633c54b0fc7635b675d588ee5c32ffbb00073b9d1c29d396c975649cc2288e9b1bac5b5854b3ce95c949bb91ce51fbbbb99a416321e9340f91e03
7
- data.tar.gz: 131b1115d49a0f29ad0c63be42f41a5930bece31344ce4766f9610e15125bc9f49ecdbb4d42e26c4507e70b495d2be63c514da1c7a52ab17b136052240e7c0dc
6
+ metadata.gz: 6d7a1b6d6bca0d9b5dc5332699682d12cd1186e49762198f2fe98216ec632676643869571cdcccf45fc2daa985f376bd064b4fb63acc8cd99eba1989645c679e
7
+ data.tar.gz: 6ba3c05c61ae02c72acdc3c87af69ca63a9518f2307a55dbb1014e5a0e5f500c336dbf0dc6b90c1510300cd1862c0e9e3bb0db9104f6f66fc4a63148f9b4cac8
data/CHANGELOG.md CHANGED
@@ -1,7 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ### 1.0.3 - 2014-12-10
3
+ ### 1.0.4 - 2014-12-10
4
+ - Added support for documentation in Octopress docs.
5
+ - Now preserving hand written raw tags inside of code blocks.
4
6
 
7
+ ### 1.0.3 - 2014-12-10
5
8
  Fixes:
6
9
  - Random tabs don't trigger escapes.
7
10
  - Raw tags inside of code fences are properly stripped.
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ <!---
2
+ escape_raw: true
3
+ --->
1
4
  # Octopress Escape Code
2
5
 
3
6
  Automatically escape code blocks so you can use liquid tags without worry having to surround them with unsightly
@@ -62,7 +65,7 @@ If you are using Markdown, you may create a code blocks by indenting four spaces
62
65
  {% endraw %}
63
66
  ```
64
67
 
65
- You can also define in-line code tags by surrounding text with back ticks, like this ```some code``` which are automatically escaped as
68
+ You can also define in-line code tags by surrounding text with back ticks, like this `` `some code` `` which are automatically escaped as
66
69
  well.
67
70
 
68
71
  This inline {% raw %}`<code>`{% endraw %} tag is escaped.
@@ -82,7 +85,6 @@ If you prefer, you can enable it on a per page basis, by turning off automatic c
82
85
 
83
86
  Then, add `escape_code: true` to the page's YAML front-matter to enable code escaping for a single page.
84
87
 
85
-
86
88
  ## Contributing
87
89
 
88
90
  1. Fork it ( https://github.com/octopress/escape-code/fork )
@@ -7,34 +7,54 @@ module Octopress
7
7
  class EscapePage < Octopress::Hooks::Page
8
8
  def pre_render(page)
9
9
  if Octopress::EscapeCode.escape_enabled?(page)
10
- page.content = Octopress::EscapeCode.escape(page.content, page.ext)
10
+ page.content = Octopress::EscapeCode.escape(page)
11
11
  end
12
12
  end
13
+
14
+ def post_render(page)
15
+ Octopress::EscapeCode.unescape_raw(page)
16
+ end
13
17
  end
14
18
 
15
19
  class EscapePost < Octopress::Hooks::Post
16
20
  def pre_render(page)
17
21
  if Octopress::EscapeCode.escape_enabled?(page)
18
- page.content = Octopress::EscapeCode.escape(page.content, page.ext)
22
+ page.content = Octopress::EscapeCode.escape(page)
19
23
  end
20
24
  end
25
+
26
+ def post_render(page)
27
+ Octopress::EscapeCode.unescape_raw(page)
28
+ end
29
+ end
30
+
31
+ def self.unescape_raw(page)
32
+ page.output.gsub!(/\*-(end)?raw-\*/, '% \1raw %')
21
33
  end
22
34
 
23
35
  def self.escape_enabled?(page)
24
- site_config = page.site.config['escape_code']
25
- site_config = true if site_config.nil?
36
+ get_config(page, 'escape_code', true)
37
+ end
26
38
 
27
- page_config = page.data['escape_code']
39
+ def self.get_config(page, config, default = true)
40
+ site_config = page.site.config[config]
41
+ site_config = default if site_config.nil?
42
+
43
+ page_config = page.data[config]
28
44
  page_config = site_config if page_config.nil?
29
45
 
30
- enabled = page_config
46
+ page_config
31
47
  end
32
48
 
33
- def self.escape(content, ext)
34
- ext = ext.downcase
35
- content.encode!("UTF-8")
49
+ def self.escape(page)
50
+ ext = page.ext.downcase
51
+ content = page.content.encode!("UTF-8")
36
52
  md_ext = %w{.markdown .mdown .mkdn .md .mkd .mdwn .mdtxt .mdtext}
37
53
 
54
+ # Escape existing raw tags
55
+ #
56
+ content = content.gsub(/% (end)?raw %/, '*-\1raw-*')
57
+
38
58
  # Escape markdown style code blocks
39
59
  if md_ext.include?(ext)
40
60
 
@@ -58,6 +78,18 @@ module Octopress
58
78
  "{% raw %}#{$1}{% endraw %}"
59
79
  end
60
80
 
81
+ content = content.gsub /^( {4}[^\n].+?)\n($|\S)/m do
82
+ c1 = $1
83
+ c2 = $2
84
+ "#{c1.gsub(/{% (end)?raw %}/, '')}\n#{c2}"
85
+ end
86
+
87
+ # Escape tab indented code blocks
88
+ content = content.gsub /^(\t[^\n].+?)\n($|\S)/m do
89
+ c1 = $1
90
+ c2 = $2
91
+ "#{c1.gsub(/{% (end)?raw %}/, '')}\n#{c2}"
92
+ end
61
93
  end
62
94
 
63
95
  # Escape codefenced codeblocks
@@ -87,3 +119,13 @@ module Octopress
87
119
  end
88
120
  end
89
121
  end
122
+
123
+ # Add documentation for this plugin
124
+ if defined? Octopress::Docs
125
+ Octopress::Docs.add({
126
+ name: "Octopress Escape Code",
127
+ description: "Automatically escape code with {% raw %} blocks, preventing internal Liquid processing.",
128
+ source_url: "https://github.com/octopress/escape-code",
129
+ path: File.expand_path(File.join(File.dirname(__FILE__), "../"))
130
+ })
131
+ end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module EscapeCode
3
- VERSION = "1.0.3"
3
+ VERSION = "1.0.4"
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ Stuff!
6
6
  </code></pre></div>
7
7
  <p>guys!</p>
8
8
 
9
- <p>Testing the <code>dobule {% _guys_ seriously? %} ` type</code> of code thing.</p>
9
+ <p>Testing the <code>double {% _guys_ seriously? %} ` type</code> of code thing.</p>
10
10
 
11
11
  <p>The random tab character below shouldn&#39;t trigger an escape.</p>
12
12
 
@@ -24,3 +24,10 @@ Stuff!</code></pre></div>
24
24
  {% foo %}
25
25
  </code></pre></div>
26
26
  <p>some text</p>
27
+ <div class="highlight"><pre><code class="language-text" data-lang="text">{% highlight html %}{% raw %}
28
+ &lt;article&gt;{{ post.content }}&lt;/article&gt;
29
+ {% endraw %}{% endhighlight %}
30
+ </code></pre></div>
31
+ <p>Test inner space block raw replacement:</p>
32
+ <div class="highlight"><pre><code class="language-text" data-lang="text">This inline {% raw %}`&lt;code&gt;`{% endraw %} tag is escaped.
33
+ </code></pre></div>
data/test/index.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  escape_code: true
3
+ escape_raw: true
3
4
  ---
4
5
 
5
6
  Some text
@@ -12,7 +13,7 @@ Stuff!
12
13
  ```
13
14
  guys!
14
15
 
15
- Testing the ``dobule {% _guys_ seriously? %} ` type`` of code thing.
16
+ Testing the ``double {% _guys_ seriously? %} ` type`` of code thing.
16
17
 
17
18
  The random tab character below shouldn't trigger an escape.
18
19
 
@@ -34,3 +35,11 @@ Stuff!
34
35
  stuff
35
36
  {% foo %}
36
37
  some text
38
+
39
+ {% highlight html %}{% raw %}
40
+ <article>{{ post.content }}</article>
41
+ {% endraw %}{% endhighlight %}
42
+
43
+ Test inner space block raw replacement:
44
+
45
+ This inline {% raw %}`<code>`{% endraw %} tag is escaped.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-escape-code
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-11 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octopress-hooks