octopress-pygments 1.1.0 → 1.2.0

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzYxMGQ3ZWMxMzg3OGQxY2MyMWMzMDQ1YmQ0OTk1ZTU0MmFlNDkxMA==
5
+ data.tar.gz: !binary |-
6
+ MzQxMjhkMTE4NWVlNzYyMWYyMzgzOWViNDFjNzYxYjVhODAyZmQwYg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDUwMTY2ZWZjMzA0NDZlMDNjNDEzZDRlNTZhZDgwZTdiNDUzZmU2OWUxNzY1
10
+ M2QyM2E2MjIyMGViODFjODI5N2E0YjUwYWRlOWI0YzllMGRmYWI5NzdjNWNk
11
+ ZmI1Njc5ZDU2NDVkZTIzZDkzZTc0NGY2YWEwZjI3M2Y2MWI4NDg=
12
+ data.tar.gz: !binary |-
13
+ YWMwYzRhZDIyZWIyMWE1MGRmY2ExOWM2NzBjNGM0NmE4NWFjMzFhZDA3M2I5
14
+ NDllNTNiNGE3NWI5OTQ1NjA0MmEzM2Q3MjJjZWQ3ODQ0NWE0YWQwMzI5Njcw
15
+ MmZkYjAwODgxMTAzMTIzYTVhN2NlOWM4ZTA0NjliZTk0MTM0MGI=
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .pygments-cache
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 1.2.0
4
+ - Added method for users to specify lexer aliases
5
+ - Removed default aliases:
6
+ - ru, yml, coffee - now handled by Pygments correctly
7
+ - pl, m - match multiple languages, enforcing an alias is inappropriate
8
+
9
+ ## 1.1.0
10
+ - Boring bug fixes
11
+
12
+ ## 1.0.0
13
+ - Initial release
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Octopress::Pygments
1
+ # Octopress Pygments
2
+
3
+ [![Build Status](https://travis-ci.org/octopress/octopress-pygments.png)](https://travis-ci.org/octopress/octopress-pygments)
2
4
 
3
5
  TODO: Write a gem description
4
6
 
@@ -6,36 +6,38 @@ module Octopress
6
6
  def initialize(code, options = {})
7
7
  @code = code
8
8
  @options = options
9
- @lang = determine_lang
9
+ @aliases = @options[:aliases]
10
+ @aliases = (@aliases ? stringify_keys(@aliases) : {})
11
+ @lang = determine_lang(@options[:lang])
10
12
  end
11
13
 
12
14
  def highlight
13
15
  @options[:title] ||= ' ' if @options[:url]
14
- cache = Cache.fetch_from_cache(code, options)
16
+ cache = Cache.fetch_from_cache(code, @options)
15
17
  unless cache
16
18
  if @lang == 'plain'
17
19
  rendered_code = code.to_s.gsub('<','&lt;')
18
20
  else
19
- rendered_code = render_pygments(code, options[:lang]).match(/<pre>(.+)<\/pre>/m)[1].gsub(/ *$/, '') #strip out divs <div class="highlight">
21
+ rendered_code = render_pygments(code, @lang).match(/<pre>(.+)<\/pre>/m)[1].gsub(/ *$/, '') #strip out divs <div class="highlight">
20
22
  end
21
- rendered_code = tableize_code(rendered_code, options[:lang], {linenos: options[:linenos], start: options[:start], marks: options[:marks]})
22
- title = captionize(options[:title], options[:url], options[:link_text]) if options[:title]
23
+ rendered_code = tableize_code(rendered_code, @lang, {linenos: @options[:linenos], start: @options[:start], marks: @options[:marks]})
24
+ title = captionize(@options[:title], @options[:url], @options[:link_text]) if @options[:title]
23
25
  rendered_code = "<figure class='code'>#{title}#{rendered_code}</figure>"
24
- Cache.write_to_cache(rendered_code, options) unless options[:no_cache]
26
+ Cache.write_to_cache(rendered_code, @options) unless @options[:no_cache]
25
27
  end
26
28
  cache || rendered_code
27
29
  end
28
30
 
29
- def determine_lang
30
- lang = options[:lang]
31
- lang = 'ruby' if lang == 'ru'
32
- lang = 'objc' if lang == 'm'
33
- lang = 'perl' if lang == 'pl'
34
- lang = 'yaml' if lang == 'yml'
35
- lang = 'coffeescript' if lang == 'coffee'
36
- lang = 'csharp' if lang == 'cs'
37
- lang = 'plain' if lang == '' or lang.nil? or !lang
38
- options[:lang] = lang
31
+ def determine_lang(lang)
32
+ if lang == '' or lang.nil? or !lang
33
+ lang = 'plain'
34
+ elsif ::Pygments::Lexer.find lang
35
+ lang
36
+ elsif !@aliases[lang].nil? and ::Pygments::Lexer.find @aliases[lang]
37
+ @aliases[lang]
38
+ else
39
+ 'plain'
40
+ end
39
41
  end
40
42
 
41
43
  def render_pygments(code, lang)
@@ -106,6 +108,23 @@ module Octopress
106
108
  code.gsub(/{{/, '&#x7b;&#x7b;')
107
109
  .gsub(/{%/, '&#x7b;&#x25;')
108
110
  end
111
+
112
+ private
113
+
114
+ def stringify_keys(hash)
115
+ hash.inject({}){|result, (key, value)|
116
+ new_key = case key
117
+ when String then key.to_s
118
+ else key
119
+ end
120
+ new_value = case value
121
+ when Hash then stringify_keys(value)
122
+ else value
123
+ end
124
+ result[new_key] = new_value
125
+ result
126
+ }
127
+ end
109
128
  end
110
129
  end
111
130
  end
@@ -1,5 +1,5 @@
1
1
  module Octopress
2
2
  module Pygments
3
- VERSION = "1.1.0"
3
+ VERSION = "1.2.0"
4
4
  end
5
5
  end
@@ -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: 'ruby' })).to eql(expected_output_lang_ruby.chop)
113
+ expect(described_class.highlight(code, { lang: 'abc', aliases: {'abc'=>'ruby'} })).to eql(expected_output_lang_ruby.chop)
114
114
  end
115
115
  end
116
116
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octopress-pygments
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
5
- prerelease:
4
+ version: 1.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brandon Mathis
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-09-11 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: pygments.rb
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: colorator
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ~>
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ~>
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -85,6 +76,7 @@ files:
85
76
  - .gitignore
86
77
  - .rspec
87
78
  - .travis.yml
79
+ - CHANGELOG.md
88
80
  - Gemfile
89
81
  - LICENSE.txt
90
82
  - README.md
@@ -101,26 +93,25 @@ files:
101
93
  homepage: https://github.com/octopress/octopress-pygments
102
94
  licenses:
103
95
  - MIT
96
+ metadata: {}
104
97
  post_install_message:
105
98
  rdoc_options: []
106
99
  require_paths:
107
100
  - lib
108
101
  required_ruby_version: !ruby/object:Gem::Requirement
109
- none: false
110
102
  requirements:
111
103
  - - ! '>='
112
104
  - !ruby/object:Gem::Version
113
105
  version: '0'
114
106
  required_rubygems_version: !ruby/object:Gem::Requirement
115
- none: false
116
107
  requirements:
117
108
  - - ! '>='
118
109
  - !ruby/object:Gem::Version
119
110
  version: '0'
120
111
  requirements: []
121
112
  rubyforge_project:
122
- rubygems_version: 1.8.23
113
+ rubygems_version: 2.0.7
123
114
  signing_key:
124
- specification_version: 3
115
+ specification_version: 4
125
116
  summary: Octopress's core plugin for rendering nice code blocks
126
117
  test_files: []