octopress-escape-code 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 265a17b0eb6c9ba1a4cbbaa1f01a456e958b0e8d
4
+ data.tar.gz: 65cbeed0d373060db77e0e08d9e81bbed0289574
5
+ SHA512:
6
+ metadata.gz: 94351ffb99649c83c509be109dbef8fcb95cd18890c66ab951625746e45bacfb9826e8849b6cee5de53e4c88746fbc4f99d6f23dc50204f32a14d95057c822e8
7
+ data.tar.gz: 8e608f4cd8974d0a473a2f1e4aba255913b5249ef2af06d652e429fb51956b9e22a8989d5bf801adc1baa79e27f90231335df2a260065d1e4a2c91d76b1baa84
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ _site
24
+ .code-highlighter-cache
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ script: cd test && bundle exec clash
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in octopress_render_tag.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brandon Mathis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Octopress Escape Code
2
+
3
+ Automatically escape code blocks so you can use liquid tags
4
+ without worry having to surround them with unsightly `{% raw %}` and
5
+ `{% endraw %}` tags.
6
+
7
+ [![Build Status](https://travis-ci.org/octopress/escape-code.svg)](https://travis-ci.org/octopress/escape-code)
8
+ [![Gem Version](http://img.shields.io/gem/v/octopress-escape-code.svg)](https://rubygems.org/gems/octopress-escape-code)
9
+ [![License](http://img.shields.io/:license-mit-blue.svg)](http://octopress.mit-license.org)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'octopress-escape-code'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install octopress-escape-code
24
+
25
+ Next add it to your gems list in Jekyll's `_config.yml`
26
+
27
+ gems:
28
+ - octopress-escape-code
29
+
30
+ ## Usage
31
+
32
+ ### Code plugins
33
+
34
+ Before Jekyll parses your pages and posts through Liquid, code is automatically wrapped with `{% raw %}` blocks,
35
+ ensuring that their contents aren't parsed by Liquid. For example, a `{% highlight %}` block's contents are wrapped like this.
36
+
37
+ {% highlight html %}{% raw %}
38
+ <article>{{ post.content }}</article>
39
+ {% endraw %}{% endhighlight %}
40
+
41
+ The `{% highlight %}` block is still interpreted by Liquid, but the contents are escaped. This will also escape the
42
+ [Octopress code block](https://github.com/octopress/code-block) plugin.
43
+
44
+ Some Markdown processors and the [Octopress codefence](https://github.com/octopress/code-block) plugin render code blocks which are
45
+ surrounded by three back ticks. These are also wrapped with `{% raw %}` tags.
46
+
47
+ {% raw %}
48
+ ```html
49
+ <article>{{ post.content }}</article>
50
+ ```
51
+ {% endraw %}
52
+
53
+ Liquid sees the raw tags and ignores the contents, but the code fences are still interpreted.
54
+
55
+ ### Standard Markdown code
56
+
57
+ If you are using Markdown, you may create a code blocks by indenting four spaces or a single tab. These code blocks are escaped like this.
58
+
59
+ ```
60
+ {% raw %}
61
+ <article>{{ post.content }}</article>
62
+ {% endraw %}
63
+ ```
64
+
65
+ You can also define in-line code tags by surrounding text with back ticks, like this ```some code``` which are automatically escaped as
66
+ well.
67
+
68
+ This inline {% raw %}`<code>`{% endraw %} tag is escaped.
69
+
70
+ This works with double back tick code tags as well.
71
+
72
+ ### Disable Automatic escaping
73
+
74
+ Adding this gem will automatically enable code escaping for your entire site. To disable code escaping for a single page, add this to the
75
+ page's YAML front-matter.
76
+
77
+ escape_code: fasle
78
+
79
+ If you prefer, you can enable it on a per page basis, by turning off automatic code escaping in your site's configuration.
80
+
81
+ // in Jekyll's _config.yml
82
+ escape_code: false
83
+
84
+ Then, to enable code escaping on a single page simply add `escape_code: true` to the page's YAML front-matter.
85
+
86
+
87
+ ## Contributing
88
+
89
+ 1. Fork it ( https://github.com/octopress/escape-code/fork )
90
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
91
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
92
+ 4. Push to the branch (`git push origin my-new-feature`)
93
+ 5. Create a new Pull Request
94
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ module Octopress
2
+ module EscapeCode
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,67 @@
1
+ require "octopress-escape-code/version"
2
+ require 'jekyll-page-hooks'
3
+
4
+ module Jekyll
5
+ class EscapeCode < PageHooks
6
+ def pre_render(page)
7
+ site_config = page.site.config['escape_code']
8
+ site_config = true if site_config.nil?
9
+
10
+ page_config = page.data['escape_code']
11
+ page_config = site_config if page_config.nil?
12
+
13
+ enabled = page_config
14
+
15
+ if enabled
16
+ page.content = Octopress::EscapeCode.escape(page.content, page.ext)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ module Octopress
23
+ module EscapeCode
24
+ def self.escape(content, ext)
25
+ ext = ext.downcase
26
+ content.encode!("UTF-8")
27
+ md_ext = %w{.markdown .mdown .mkdn .md .mkd .mdwn .mdtxt .mdtext}
28
+
29
+ # Escape codefenced codeblocks
30
+ content = content.gsub /^(`{3}.+?`{3})/m do
31
+ "{% raw %}\n#{$1}\n{% endraw %}"
32
+ end
33
+
34
+ # Escape markdown style code blocks
35
+ if md_ext.include?(ext)
36
+
37
+ # Escape four space indented code blocks
38
+ content = content.gsub /^(\s{4}.+?)\n($|[^\s{4}])/m do
39
+ "{% raw %}\n#{$1}\n{% endraw %}\n#{$2}"
40
+ end
41
+
42
+ # Escape tab indented code blocks
43
+ content = content.gsub /^(\t.+?)\n($|[^\t])/m do
44
+ "{% raw %}\n#{$1}\n{% endraw %}\n#{$2}"
45
+ end
46
+
47
+ # Escape in-line code backticks
48
+ content = content.gsub /(`{1,2}[^`\n]+?`{1,2})/ do
49
+ "{% raw %}#{$1}{% endraw %}"
50
+ end
51
+
52
+ end
53
+
54
+ # Escape codeblock tag contents
55
+ content = content.gsub /^({%\s*codeblock.+?%})(.+?)({%\s*endcodeblock\s*%})/m do
56
+ "#{$1}{% raw %}#{$2}{% endraw %}#{$3}"
57
+ end
58
+
59
+ # Escape highlight tag contents
60
+ content = content.gsub /^({%\s*highlight.+?%})(.+?)({%\s*endhighlight\s*%})/m do
61
+ "#{$1}{% raw %}#{$2}{% endraw %}#{$3}"
62
+ end
63
+
64
+ content
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'octopress-escape-code/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "octopress-escape-code"
8
+ spec.version = Octopress::EscapeCode::VERSION
9
+ spec.authors = ["Brandon Mathis"]
10
+ spec.email = ["brandon@imathis.com"]
11
+ spec.summary = %q{Return tag renders a variable with some nice features}
12
+ spec.description = %q{Return tag renders a variable with some nice features}
13
+ spec.homepage = "https://github.com/octopress/escape-code"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'jekyll-page-hooks', '~> 1.1'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "clash"
26
+ spec.add_development_dependency "octopress-codeblock"
27
+ end
data/test/.clash.yml ADDED
@@ -0,0 +1,2 @@
1
+ build: true
2
+ compare: _expected _site
data/test/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'octopress-escape-code', path: '../'
4
+ gem 'pry-debugger'
5
+ gem 'clash'
6
+ gem 'octopress-codeblock'
data/test/_config.yml ADDED
@@ -0,0 +1,16 @@
1
+ # Site settings
2
+ title: Your awesome title
3
+ email: your-email@domain.com
4
+ baseurl: ""
5
+ url: "http://yourdomain.com"
6
+ timezone: UTC
7
+ escape_code: true
8
+
9
+ exclude:
10
+ - Gemfile*
11
+
12
+ # Build settings
13
+ markdown: redcarpet
14
+ gems:
15
+ - octopress-escape-code
16
+ - octopress-codeblock
@@ -0,0 +1,22 @@
1
+ <p>Some text</p>
2
+ <div class="highlight"><pre><code class="language-text" data-lang="text">Some kind of example:
3
+ {% some tag that should break %}
4
+ Stuff!
5
+ </code></pre></div>
6
+ <p>guys!</p>
7
+
8
+ <p>Testing the <code>dobule ` type</code> of code thing.</p>
9
+
10
+ <p>So here&#39;s a <code>{% nonexistant tag %}</code> that should be escaped.</p>
11
+
12
+ <div class="highlight"><pre><code class="language-html" data-lang="html">Some kind of example:
13
+ {% some tag that should break %}
14
+ Stuff!</code></pre></div>
15
+
16
+ <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:
17
+ </div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'>&#x7b;% some tag that should break %&#x7d;
18
+ </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'>Stuff!</div></div></pre></div></figure>
19
+ <div class="highlight"><pre><code class="language-text" data-lang="text">stuff
20
+ asdfadsf
21
+ </code></pre></div>
22
+ <p>some text</p>
data/test/index.md ADDED
@@ -0,0 +1,34 @@
1
+ ---
2
+ escape_code: true
3
+ ---
4
+
5
+ Some text
6
+
7
+ ```
8
+ Some kind of example:
9
+ {% some tag that should break %}
10
+ Stuff!
11
+ ```
12
+ guys!
13
+
14
+ Testing the ``dobule ` type`` of code thing.
15
+
16
+ So here's a `{% nonexistant tag %}` that should be escaped.
17
+
18
+ {% highlight html %}
19
+ Some kind of example:
20
+ {% some tag that should break %}
21
+ Stuff!
22
+ {% endhighlight %}
23
+
24
+
25
+ {% codeblock html %}
26
+ Some kind of example:
27
+ {% some tag that should break %}
28
+ Stuff!
29
+ {% endcodeblock %}
30
+
31
+ stuff
32
+ asdfadsf
33
+
34
+ some text
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octopress-escape-code
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Mathis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jekyll-page-hooks
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: clash
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: octopress-codeblock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Return tag renders a variable with some nice features
84
+ email:
85
+ - brandon@imathis.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/octopress-escape-code.rb
97
+ - lib/octopress-escape-code/version.rb
98
+ - octopress-escape-code.gemspec
99
+ - test/.clash.yml
100
+ - test/Gemfile
101
+ - test/_config.yml
102
+ - test/_expected/index.html
103
+ - test/index.md
104
+ homepage: https://github.com/octopress/escape-code
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Return tag renders a variable with some nice features
128
+ test_files:
129
+ - test/.clash.yml
130
+ - test/Gemfile
131
+ - test/_config.yml
132
+ - test/_expected/index.html
133
+ - test/index.md