octopress-code-highlighter 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/octopress-code-highlighter/options_parser.rb +7 -1
- data/lib/octopress-code-highlighter/renderer.rb +6 -2
- data/lib/octopress-code-highlighter/version.rb +1 -1
- data/octopress-code-highlighter.gemspec +2 -2
- data/spec/pygments_spec.rb +20 -19
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46baa2ce8aa0f668a09c0bc698c0f82b2700abbd
|
4
|
+
data.tar.gz: ffd4f5ef8d71d0f9ba00551b2c4e2712a251aa0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38044e87197659c0434f711ffef5f679923960c93076e704792b0e8df66fad89cee746b2c03fc4b0017ff4cdea90e5a98e669bc0c07d82bd6cea4a1a50ea5146
|
7
|
+
data.tar.gz: e2241329385980c82d7901ed16fcbd1199279e7a5d94b2b50361bc3c6d5c3340cfae6a21e14b5f855a12ac7752d32bca9aabdb1de7370e58214e99be6da820b7
|
data/CHANGELOG.md
CHANGED
@@ -19,6 +19,7 @@ module Octopress
|
|
19
19
|
.sub(/\s*range:\s*\d+-\d+/i,'')
|
20
20
|
.sub(/\s*escape:\s*\w+/i,'')
|
21
21
|
.sub(/\s*startinline:\s*\w+/i,'')
|
22
|
+
.sub(/\s*class:\s*(("(.+?)")|('(.+?)')|(\S+))/i,'')
|
22
23
|
end
|
23
24
|
|
24
25
|
def parse_markup(defaults = {})
|
@@ -32,7 +33,8 @@ module Octopress
|
|
32
33
|
start: start,
|
33
34
|
end: endline,
|
34
35
|
escape: escape,
|
35
|
-
startinline: startinline
|
36
|
+
startinline: startinline,
|
37
|
+
class: classnames
|
36
38
|
}
|
37
39
|
options = options.delete_if { |k,v| v.nil? }
|
38
40
|
defaults.merge(options)
|
@@ -46,6 +48,10 @@ module Octopress
|
|
46
48
|
boolize(extract(/\s*startinline:\s*(\w+)/i))
|
47
49
|
end
|
48
50
|
|
51
|
+
def classnames
|
52
|
+
extract(/\s*class:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6])
|
53
|
+
end
|
54
|
+
|
49
55
|
def url
|
50
56
|
extract(/\s*url:\s*(("(.+?)")|('(.+?)')|(\S+))/i, [3, 5, 6])
|
51
57
|
end
|
@@ -45,7 +45,11 @@ module Octopress
|
|
45
45
|
rendered_code = render
|
46
46
|
rendered_code = escape_characters(rendered_code)
|
47
47
|
rendered_code = tableize_code(rendered_code)
|
48
|
-
|
48
|
+
classnames = 'code-highlight-figure'
|
49
|
+
if options[:class]
|
50
|
+
classnames << ' ' + options[:class]
|
51
|
+
end
|
52
|
+
rendered_code = "<figure class='#{classnames}'>#{caption}#{rendered_code}</figure>"
|
49
53
|
rendered_code = "{% raw %}#{rendered_code}{% endraw %}" if options[:escape]
|
50
54
|
Cache.write_to_cache(rendered_code, options) unless options[:no_cache]
|
51
55
|
rendered_code
|
@@ -98,7 +102,7 @@ module Octopress
|
|
98
102
|
|
99
103
|
def render_rouge
|
100
104
|
if lexer = Rouge::Lexer.find(lang) || Rouge::Lexer.find(@aliases[lang])
|
101
|
-
formatter = ::Rouge::Formatters::HTML.new()
|
105
|
+
formatter = ::Rouge::Formatters::HTML.new(wrap: false)
|
102
106
|
formatter.format(lexer.lex(@code))
|
103
107
|
else
|
104
108
|
render_plain
|
@@ -13,12 +13,12 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.homepage = "https://github.com/octopress/code-highlighter"
|
14
14
|
gem.license = "MIT"
|
15
15
|
|
16
|
-
gem.add_runtime_dependency 'colorator', '~> 0.1
|
16
|
+
gem.add_runtime_dependency 'colorator', '~> 0.1'
|
17
17
|
|
18
18
|
gem.add_development_dependency 'pry-debugger'
|
19
19
|
gem.add_development_dependency 'rake'
|
20
20
|
gem.add_development_dependency 'rspec'
|
21
|
-
gem.add_development_dependency 'rouge', '~> 1.3
|
21
|
+
gem.add_development_dependency 'rouge', '~> 1.3'
|
22
22
|
|
23
23
|
gem.files = `git ls-files`.split($/).reject {|f| f =~ /^demo\// }
|
24
24
|
gem.require_paths = ["lib"]
|
data/spec/pygments_spec.rb
CHANGED
@@ -14,12 +14,12 @@ describe Octopress::CodeHighlighter do
|
|
14
14
|
|
15
15
|
let(:expected_output_no_options) do
|
16
16
|
stuff = <<-EOF
|
17
|
-
<figure class='code-highlight-figure'><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='1' class='code-highlight-row numbered'><div class='code-highlight-line'>
|
18
|
-
</div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'>
|
19
|
-
</div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'>
|
20
|
-
</div></div><div data-line='5' class='code-highlight-row numbered'><div class='code-highlight-line'>
|
21
|
-
</div></div><div data-line='6' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='7' class='code-highlight-row numbered'><div class='code-highlight-line'>
|
22
|
-
</div></div><div data-line='8' class='code-highlight-row numbered'><div class='code-highlight-line'
|
17
|
+
<figure class='code-highlight-figure'><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='1' class='code-highlight-row numbered'><div class='code-highlight-line'>require "hi-there-honey"
|
18
|
+
</div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'>def hi-there-honey
|
19
|
+
</div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'> HiThereHoney.new("your name")
|
20
|
+
</div></div><div data-line='5' class='code-highlight-row numbered'><div class='code-highlight-line'>end
|
21
|
+
</div></div><div data-line='6' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='7' class='code-highlight-row numbered'><div class='code-highlight-line'>hi-there-honey
|
22
|
+
</div></div><div data-line='8' class='code-highlight-row numbered'><div class='code-highlight-line'># => "Hi, your name"
|
23
23
|
</div></div></pre></div></figure>
|
24
24
|
EOF
|
25
25
|
stuff.strip
|
@@ -27,25 +27,26 @@ EOF
|
|
27
27
|
|
28
28
|
let(:expected_output_lang_ruby) do
|
29
29
|
stuff = <<-EOF
|
30
|
-
{% raw %}<figure class='code-highlight-figure'><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='1' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="nb">require</span> <span class="s2">"hi-there-honey"</span>
|
31
|
-
</div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'
|
32
|
-
</div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'>
|
33
|
-
</div></div><div data-line='5' class='code-highlight-row numbered'><div class='code-highlight-line'
|
34
|
-
</div></div><div data-line='6' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='7' class='code-highlight-row numbered'><div class='code-highlight-line'
|
35
|
-
</div></div><div data-line='8' class='code-highlight-row numbered'><div class='code-highlight-line'
|
30
|
+
{% raw %}<figure class='code-highlight-figure awesome'><div class='code-highlight'><pre class='code-highlight-pre'><div data-line='1' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="nb">require</span> <span class="s2">"hi-there-honey"</span>
|
31
|
+
</div></div><div data-line='2' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='3' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="k">def</span> <span class="nf">hi</span><span class="o">-</span><span class="n">there</span><span class="o">-</span><span class="n">honey</span>
|
32
|
+
</div></div><div data-line='4' class='code-highlight-row numbered'><div class='code-highlight-line'> <span class="no">HiThereHoney</span><span class="p">.</span><span class="nf">new</span><span class="p">(</span><span class="s2">"your name"</span><span class="p">)</span>
|
33
|
+
</div></div><div data-line='5' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="k">end</span>
|
34
|
+
</div></div><div data-line='6' class='code-highlight-row numbered'><div class='code-highlight-line'> </div></div><div data-line='7' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="n">hi</span><span class="o">-</span><span class="n">there</span><span class="o">-</span><span class="n">honey</span>
|
35
|
+
</div></div><div data-line='8' class='code-highlight-row numbered'><div class='code-highlight-line'><span class="c1"># => "Hi, your name"</span>
|
36
|
+
</div></div></pre></div></figure>{% endraw %}
|
36
37
|
EOF
|
37
38
|
end
|
38
39
|
|
39
40
|
let(:code) do
|
40
41
|
<<-EOF
|
41
|
-
|
42
|
+
require "hi-there-honey"
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def hi-there-honey
|
45
|
+
HiThereHoney.new("your name")
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
-
|
48
|
+
hi-there-honey
|
49
|
+
# => "Hi, your name"
|
49
50
|
EOF
|
50
51
|
end
|
51
52
|
|
@@ -103,7 +104,7 @@ EOF
|
|
103
104
|
|
104
105
|
context "with a language" do
|
105
106
|
it "returns the right HTML for a given set of code" do
|
106
|
-
expect(described_class.highlight(code, { lang: 'abc', aliases: {'abc'=>'ruby'}, escape: true })).to eql(expected_output_lang_ruby.chop)
|
107
|
+
expect(described_class.highlight(code, { lang: 'abc', aliases: {'abc'=>'ruby'}, escape: true, class: 'awesome' })).to eql(expected_output_lang_ruby.chop)
|
107
108
|
end
|
108
109
|
end
|
109
110
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: octopress-code-highlighter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.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: 2014-06-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorator
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.1
|
19
|
+
version: '0.1'
|
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
|
-
version: 0.1
|
26
|
+
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry-debugger
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 1.3
|
75
|
+
version: '1.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 1.3
|
82
|
+
version: '1.3'
|
83
83
|
description: Octopress's core plugin for rendering nice code blocks
|
84
84
|
email:
|
85
85
|
- brandon@imathis.com
|