octopress-pygments 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzlhODVlOTQ5MGMzYWJkOGQyNDQ1OTZjNGEwMTRjNWI3ODQ2NThhNQ==
5
- data.tar.gz: !binary |-
6
- N2YzYTQ3OGMxODkzMzgzNjJjNWJjYmM2YWVmODg5NTdhMmU2YzI2ZA==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- YzA3NWJmYzliMWFiMjJhODVjNzI0NDYwZTY1YTMzZmJmMDA2NzdkNWFhN2Vl
10
- MDk3MjM4OTMyNmRhN2VjNjI5OGQ2MzNmZmY2MDAyM2JlNjczZTc3NjM0N2Zh
11
- ZmU2ZmRhYjM5ZmU0MzBkZmIwYzVlNzI1MzUzNjc4ODYxY2Y5M2Q=
12
- data.tar.gz: !binary |-
13
- Y2FiMWMwZWYyZmYwMjY2MzMyMThiMmI1NGYyOTEwMjE5ZGE3ZTVmNjA2YjRk
14
- NDliMzQ5MGQ0ODc4MTYyZWQzMDAzMGY3MWYzM2FmOTkzMjE0OTNjM2ZmNmMw
15
- MzkyNmQxMDRiYzMyNzQ0ZmEwZDFhYTJiZjIyMWZmZjU0Mjg0NTc=
2
+ SHA1:
3
+ metadata.gz: 80e23f910131a9d50e5ece2741af1dfa8e742439
4
+ data.tar.gz: 2b86308f5194af2974532336a415c07d729b6ec5
5
+ SHA512:
6
+ metadata.gz: f27c24996a09b278cc82e146474eff2539992a06f9098a3aaee47c4bed11ef37ca39534b855dc158dc69d9c1c53eb25bb936eb80ab58f94ab85502b6d5b43fd8
7
+ data.tar.gz: 81e3b650f069ae5026cd2142657c9270aeecd7b060696f598d5781a0b2b4e1ca32543661b137554793c574c06de36bc4b8716134ae9c5e2aad50a46199665576
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.0
4
+ - Added `escape` option which wraps code in {% raw %} tags to escape liquid. Defaults to true.
5
+
3
6
  ## 1.2.3
4
7
  - Fixed: figcaptions now work when specifying a title.
5
8
 
@@ -1,3 +1,6 @@
1
+ class String
2
+ end
3
+
1
4
  module Octopress
2
5
  module Pygments
3
6
  class OptionsParser
@@ -17,6 +20,7 @@ module Octopress
17
20
  .sub(/\s*start:\s*\d+/i,'')
18
21
  .sub(/\s*end:\s*\d+/i,'')
19
22
  .sub(/\s*range:\s*\d+-\d+/i,'')
23
+ .sub(/\s*escape:\s*\w+/i,'')
20
24
  end
21
25
 
22
26
  def parse_markup(defaults = {})
@@ -28,12 +32,13 @@ module Octopress
28
32
  marks: marks,
29
33
  link_text: link_text,
30
34
  start: start,
31
- end: endline
35
+ end: endline,
36
+ escape: escape
32
37
  }
33
38
  options = options.delete_if { |k,v| v.nil? }
34
39
  defaults.merge(options)
35
40
  end
36
-
41
+
37
42
  def lang
38
43
  extract(/\s*lang:\s*(\S+)/i)
39
44
  end
@@ -47,7 +52,11 @@ module Octopress
47
52
  end
48
53
 
49
54
  def linenos
50
- extract(/\s*linenos:\s*(\w+)/i)
55
+ boolize(extract(/\s*linenos:\s*(\w+)/i))
56
+ end
57
+
58
+ def escape
59
+ boolize(extract(/\s*escape:\s*(\w+)/i))
51
60
  end
52
61
 
53
62
  # Public: Matches pattern for line marks and returns array of line
@@ -78,7 +87,7 @@ module Octopress
78
87
  if range
79
88
  range.first
80
89
  else
81
- extract(/\s*start:\s*(\d+)/i).to_i
90
+ extract(/\s*start:\s*(\d+)/i, [1], 1).to_i
82
91
  end
83
92
  end
84
93
 
@@ -106,6 +115,13 @@ module Octopress
106
115
  end
107
116
  end
108
117
  end
118
+
119
+ def boolize(str)
120
+ return nil if str.nil?
121
+ return true if str == true || str =~ (/(true|t|yes|y|1)$/i)
122
+ return false if str == false || str =~ (/(false|f|no|n|0)$/i) || str.strip.size > 1
123
+ return str
124
+ end
109
125
  end
110
126
  end
111
127
  end
@@ -5,7 +5,8 @@ module Octopress
5
5
 
6
6
  def initialize(code, options = {})
7
7
  @code = code
8
- @options = options
8
+ @options = options.delete_if { |k,v| v.nil? }
9
+ @options = DEFAULTS.merge(@options)
9
10
  @aliases = @options[:aliases]
10
11
  @aliases = (@aliases ? stringify_keys(@aliases) : {})
11
12
  @lang = determine_lang(@options[:lang])
@@ -24,13 +25,14 @@ module Octopress
24
25
  rendered_code = tableize_code(rendered_code, @lang, {linenos: @options[:linenos], start: @options[:start], marks: @options[:marks]})
25
26
  title = captionize(@options[:title], @options[:url], @options[:link_text]) if @options[:title]
26
27
  rendered_code = "<figure class='code'>#{title}#{rendered_code}</figure>"
28
+ rendered_code = "{% raw %}#{rendered_code}{% endraw %}" if @options[:escape]
27
29
  Cache.write_to_cache(rendered_code, @options) unless @options[:no_cache]
28
30
  rendered_code
29
31
  end
30
32
  end
31
33
 
32
34
  def determine_lang(lang)
33
- if lang == '' or lang.nil? or !lang
35
+ if lang == ''
34
36
  lang = 'plain'
35
37
  elsif ::Pygments::Lexer.find lang
36
38
  lang
@@ -62,9 +64,9 @@ module Octopress
62
64
  end
63
65
 
64
66
  def tableize_code (code, lang, options = {})
65
- start = options[:start] || 1
66
- lines = options[:linenos] || true
67
- marks = options[:marks] || []
67
+ start = options[:start]
68
+ lines = options[:linenos]
69
+ marks = options[:marks]
68
70
  table = "<div class='highlight'><table><tr>"
69
71
  table += number_lines(start, code.lines.count, marks) if lines
70
72
  table += "<td class='main #{'unnumbered' unless lines} #{lang}'><pre>"
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Pygments
3
- VERSION = "1.2.3"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -9,6 +9,14 @@ FileUtils.mkdir_p(PYGMENTS_CACHE_DIR)
9
9
 
10
10
  module Octopress
11
11
  module Pygments
12
+ DEFAULTS = {
13
+ lang: 'plain',
14
+ linenos: true,
15
+ marks: [],
16
+ start: 1,
17
+ escape: true
18
+ }
19
+
12
20
  autoload :Cache, 'octopress-pygments/cache'
13
21
  autoload :OptionsParser, 'octopress-pygments/options_parser'
14
22
  autoload :Renderer, 'octopress-pygments/renderer'
@@ -4,7 +4,7 @@ describe Octopress::Pygments do
4
4
  let(:wrapper) do
5
5
  Proc.new do |stuff, numbers|
6
6
  [
7
- "<figure class='code'>",
7
+ "{% raw %}<figure class='code'>",
8
8
  "<div class='highlight'>",
9
9
  "<table><tr>",
10
10
  "<td class='line-numbers' aria-hidden='true'>",
@@ -13,20 +13,20 @@ describe Octopress::Pygments do
13
13
  "<td class='main plain'>",
14
14
  "<pre>#{stuff}</pre>",
15
15
  "</td></tr>",
16
- "</table></div></figure>"
16
+ "</table></div></figure>{% endraw %}"
17
17
  ].join
18
18
  end
19
19
  end
20
20
 
21
21
  let(:expected_output_no_options) do
22
22
  stuff = <<-EOF
23
- <figure class='code'><div class='highlight'><table><tr><td class='line-numbers' aria-hidden='true'><pre><div data-line='1' class='line-number'></div><div data-line='2' class='line-number'></div><div data-line='3' class='line-number'></div><div data-line='4' class='line-number'></div><div data-line='5' class='line-number'></div><div data-line='6' class='line-number'></div><div data-line='7' class='line-number'></div><div data-line='8' class='line-number'></div></pre></td><td class='main plain'><pre><div class='line'> require "hi-there-honey"
23
+ {% raw %}<figure class='code'><div class='highlight'><table><tr><td class='line-numbers' aria-hidden='true'><pre><div data-line='1' class='line-number'></div><div data-line='2' class='line-number'></div><div data-line='3' class='line-number'></div><div data-line='4' class='line-number'></div><div data-line='5' class='line-number'></div><div data-line='6' class='line-number'></div><div data-line='7' class='line-number'></div><div data-line='8' class='line-number'></div></pre></td><td class='main plain'><pre><div class='line'> require "hi-there-honey"
24
24
  </div><div class='line'> </div><div class='line'> def hi-there-honey
25
25
  </div><div class='line'> HiThereHoney.new("your name")
26
26
  </div><div class='line'> end
27
27
  </div><div class='line'> </div><div class='line'> hi-there-honey
28
28
  </div><div class='line'> # => "Hi, your name"
29
- </div></pre></td></tr></table></div></figure>
29
+ </div></pre></td></tr></table></div></figure>{% endraw %}
30
30
  EOF
31
31
  stuff.strip
32
32
  end
@@ -89,7 +89,7 @@ EOF
89
89
  lang: "abc",
90
90
  url: "http://something.com/hi/fuaiofnioaf.html",
91
91
  title: "Hello",
92
- linenos: "yes",
92
+ linenos: true,
93
93
  marks: [5, 8, 9, 10, 15],
94
94
  link_text: "get it here",
95
95
  start: 5,
@@ -110,7 +110,7 @@ EOF
110
110
 
111
111
  context "with a language" do
112
112
  it "returns the right HTML for a given set of code" do
113
- expect(described_class.highlight(code, { lang: 'abc', aliases: {'abc'=>'ruby'} })).to eql(expected_output_lang_ruby.chop)
113
+ expect(described_class.highlight(code, { lang: 'abc', aliases: {'abc'=>'ruby'}, escape: false })).to eql(expected_output_lang_ruby.chop)
114
114
  end
115
115
  end
116
116
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-pygments
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-28 00:00:00.000000000 Z
11
+ date: 2013-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pygments.rb
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
@@ -42,28 +42,28 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  description: Octopress's core plugin for rendering nice code blocks
@@ -100,17 +100,17 @@ require_paths:
100
100
  - lib
101
101
  required_ruby_version: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ! '>='
103
+ - - '>='
104
104
  - !ruby/object:Gem::Version
105
105
  version: '0'
106
106
  required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ! '>='
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.0.7
113
+ rubygems_version: 2.0.3
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Octopress's core plugin for rendering nice code blocks