makeup 0.3.0 → 0.4.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.
- data/.gitignore +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +25 -4
- data/Rakefile +11 -0
- data/Readme.md +4 -0
- data/lib/makeup.rb +4 -6
- data/lib/makeup/syntax_highlighter.rb +8 -37
- data/lib/makeup/version.rb +28 -0
- data/makeup.gemspec +3 -2
- data/test/makeup/markup_test.rb +2 -2
- data/test/makeup/syntax_highlighter_test.rb +1 -32
- data/test/test_helper.rb +5 -0
- metadata +25 -5
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,30 +1,51 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
makeup (0.
|
|
4
|
+
makeup (0.4.0)
|
|
5
|
+
github-linguist (~> 2.8)
|
|
5
6
|
github-markup (~> 0.7)
|
|
6
7
|
htmlentities (~> 4.3)
|
|
7
|
-
pygments.rb (~> 0.
|
|
8
|
+
pygments.rb (~> 0.4)
|
|
8
9
|
|
|
9
10
|
GEM
|
|
10
11
|
remote: http://rubygems.org/
|
|
11
12
|
specs:
|
|
12
|
-
|
|
13
|
+
builder (3.2.2)
|
|
14
|
+
charlock_holmes (0.6.9.4)
|
|
15
|
+
ci_reporter (1.9.0)
|
|
16
|
+
builder (>= 2.1.2)
|
|
17
|
+
escape_utils (0.3.2)
|
|
18
|
+
github-linguist (2.8.5)
|
|
19
|
+
charlock_holmes (~> 0.6.6)
|
|
20
|
+
escape_utils (~> 0.3.1)
|
|
21
|
+
mime-types (~> 1.19)
|
|
22
|
+
pygments.rb (~> 0.4.2)
|
|
23
|
+
github-markup (0.7.5)
|
|
13
24
|
htmlentities (4.3.1)
|
|
25
|
+
mime-types (1.23)
|
|
14
26
|
minitest (2.12.1)
|
|
27
|
+
multi_json (1.7.7)
|
|
15
28
|
posix-spawn (0.3.6)
|
|
16
|
-
pygments.rb (0.
|
|
29
|
+
pygments.rb (0.4.2)
|
|
17
30
|
posix-spawn (~> 0.3.6)
|
|
18
31
|
yajl-ruby (~> 1.1.0)
|
|
19
32
|
rake (0.9.2.2)
|
|
33
|
+
rcov (1.0.0)
|
|
20
34
|
redcarpet (2.2.0)
|
|
35
|
+
simplecov (0.7.1)
|
|
36
|
+
multi_json (~> 1.0)
|
|
37
|
+
simplecov-html (~> 0.7.1)
|
|
38
|
+
simplecov-html (0.7.1)
|
|
21
39
|
yajl-ruby (1.1.0)
|
|
22
40
|
|
|
23
41
|
PLATFORMS
|
|
24
42
|
ruby
|
|
25
43
|
|
|
26
44
|
DEPENDENCIES
|
|
45
|
+
ci_reporter
|
|
27
46
|
makeup!
|
|
28
47
|
minitest (~> 2.0)
|
|
29
48
|
rake (~> 0.9)
|
|
49
|
+
rcov
|
|
30
50
|
redcarpet (= 2.2.0)
|
|
51
|
+
simplecov
|
data/Rakefile
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
require "rake/testtask"
|
|
2
|
+
require "ci/reporter/rake/minitest"
|
|
2
3
|
require "bundler/gem_tasks"
|
|
3
4
|
|
|
4
5
|
Rake::TestTask.new("test") do |test|
|
|
6
|
+
test.libs << "lib"
|
|
5
7
|
test.libs << "test"
|
|
6
8
|
test.pattern = "test/**/*_test.rb"
|
|
7
9
|
test.verbose = true
|
|
8
10
|
end
|
|
9
11
|
|
|
12
|
+
if RUBY_VERSION < "1.9"
|
|
13
|
+
require "rcov/rcovtask"
|
|
14
|
+
Rcov::RcovTask.new do |t|
|
|
15
|
+
t.libs << "test"
|
|
16
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
17
|
+
t.rcov_opts += %w{--exclude gems,ruby/1.}
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
10
21
|
task :default => :test
|
data/Readme.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Makeup
|
|
2
2
|
|
|
3
|
+
<a href="http://travis-ci.org/cjohansen/makeup" class="travis">
|
|
4
|
+
<img src="https://secure.travis-ci.org/cjohansen/makeup.png">
|
|
5
|
+
</a>
|
|
6
|
+
|
|
3
7
|
Makeup provides markup rendering and syntax highlighting in one glorious
|
|
4
8
|
package. It can also syntax highlight "fenced code blocks" in markdown files.
|
|
5
9
|
|
data/lib/makeup.rb
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
# --
|
|
3
3
|
# The MIT License (MIT)
|
|
4
|
+
# Christian Johansen
|
|
4
5
|
#
|
|
5
|
-
# Copyright (C)
|
|
6
|
+
# Copyright (C) 2013 Gitorious AS
|
|
6
7
|
#
|
|
7
8
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
9
|
# of this software and associated documentation files (the "Software"), to deal
|
|
@@ -22,9 +23,6 @@
|
|
|
22
23
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
24
|
# SOFTWARE.
|
|
24
25
|
#++
|
|
25
|
-
require "makeup/
|
|
26
|
+
require "makeup/version"
|
|
27
|
+
require "makeup/syntax_highlighter"
|
|
26
28
|
require "makeup/syntax_highlighter"
|
|
27
|
-
|
|
28
|
-
module Makeup
|
|
29
|
-
VERSION = "0.3.0"
|
|
30
|
-
end
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
#++
|
|
25
25
|
require "pygments"
|
|
26
26
|
require "htmlentities"
|
|
27
|
+
require "linguist"
|
|
27
28
|
|
|
28
29
|
module Makeup
|
|
29
30
|
CodeBlock = Struct.new(:lexer, :code)
|
|
@@ -36,43 +37,21 @@ module Makeup
|
|
|
36
37
|
def highlight(path, code, options = {})
|
|
37
38
|
options[:lexer] ||= lexer(path, code)
|
|
38
39
|
lexer = Pygments::Lexer.find(options[:lexer])
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
code = lexer.nil? ? code : Pygments.highlight(code, highlight_options(options))
|
|
41
|
+
CodeBlock.new(lexer && lexer.aliases.first, code)
|
|
41
42
|
rescue MentosError => e
|
|
42
43
|
# "MentosError" is what Pyments.rb raises when an unknown lexer is
|
|
43
44
|
# attempted used
|
|
44
45
|
CodeBlock.new(nil, @entities.encode(code))
|
|
45
46
|
end
|
|
46
47
|
|
|
47
|
-
def lexer(path, code = nil)
|
|
48
|
-
self.class.lexer(path
|
|
48
|
+
def lexer(path, code = nil, mode = nil)
|
|
49
|
+
self.class.lexer(path, code, mode)
|
|
49
50
|
end
|
|
50
51
|
|
|
51
|
-
def self.lexer(
|
|
52
|
-
|
|
53
|
-
lexer
|
|
54
|
-
return lexer.aliases.first || lexer.name if lexer
|
|
55
|
-
shebang_language(shebang(code)) || suffix
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def self.shebang(code)
|
|
59
|
-
first_line = (code || "").split("\n")[0]
|
|
60
|
-
first_line =~ /^#!/ ? first_line : nil
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def self.shebang_language(shebang)
|
|
64
|
-
shebang = @@lexer_shebangs.find { |s| (shebang || "") =~ s[:pattern] }
|
|
65
|
-
shebang && shebang[:lexer]
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def self.add_lexer_alias(extension, lexer)
|
|
69
|
-
@@lexer_aliases ||= {}
|
|
70
|
-
@@lexer_aliases[extension] = lexer
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def self.add_lexer_shebang(pattern, lexer)
|
|
74
|
-
@@lexer_shebangs ||= []
|
|
75
|
-
@@lexer_shebangs << { :pattern => pattern, :lexer => lexer }
|
|
52
|
+
def self.lexer(path, code = nil, mode = nil)
|
|
53
|
+
lexer = Linguist::Language.detect(path, code, mode)
|
|
54
|
+
lexer && (lexer.aliases.first || lexer.name)
|
|
76
55
|
end
|
|
77
56
|
|
|
78
57
|
private
|
|
@@ -84,11 +63,3 @@ module Makeup
|
|
|
84
63
|
end
|
|
85
64
|
end
|
|
86
65
|
end
|
|
87
|
-
|
|
88
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("txt", "text")
|
|
89
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("ru", "rb")
|
|
90
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("Rakefile", "rb")
|
|
91
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("Gemfile", "rb")
|
|
92
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("Gemfile.lock", "yaml")
|
|
93
|
-
|
|
94
|
-
Makeup::SyntaxHighlighter.add_lexer_shebang(/\bruby\b/, "rb")
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
# --
|
|
3
|
+
# The MIT License (MIT)
|
|
4
|
+
#
|
|
5
|
+
# Copyright (C) 2013 Gitorious AS
|
|
6
|
+
#
|
|
7
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
# in the Software without restriction, including without limitation the rights
|
|
10
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
# furnished to do so, subject to the following conditions:
|
|
13
|
+
#
|
|
14
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
# copies or substantial portions of the Software.
|
|
16
|
+
#
|
|
17
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
# SOFTWARE.
|
|
24
|
+
#++
|
|
25
|
+
|
|
26
|
+
module Makeup
|
|
27
|
+
VERSION = "0.4.0"
|
|
28
|
+
end
|
data/makeup.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
dir = File.expand_path(File.dirname(__FILE__))
|
|
3
|
-
require File.join(dir, "lib", "makeup")
|
|
3
|
+
require File.join(dir, "lib", "makeup/version.rb")
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |s|
|
|
6
6
|
s.name = "makeup"
|
|
@@ -17,7 +17,8 @@ markdown files.
|
|
|
17
17
|
|
|
18
18
|
s.rubyforge_project = "makeup"
|
|
19
19
|
|
|
20
|
-
s.add_dependency "pygments.rb", "~>0.
|
|
20
|
+
s.add_dependency "pygments.rb", "~>0.4"
|
|
21
|
+
s.add_dependency "github-linguist", "~>2.8"
|
|
21
22
|
s.add_dependency "github-markup", "~> 0.7"
|
|
22
23
|
s.add_dependency "htmlentities", "~> 4.3"
|
|
23
24
|
|
data/test/makeup/markup_test.rb
CHANGED
|
@@ -63,7 +63,7 @@ describe Makeup::Markup do
|
|
|
63
63
|
assert_equal 2, html.scan(/common-lisp/).length
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
|
-
|
|
66
|
+
|
|
67
67
|
describe "#render" do
|
|
68
68
|
it "should detect end of code blocks properly" do
|
|
69
69
|
html = @renderer.render("file.md", <<-MD)
|
|
@@ -87,7 +87,7 @@ class Bonjour
|
|
|
87
87
|
end
|
|
88
88
|
```
|
|
89
89
|
MD
|
|
90
|
-
|
|
90
|
+
|
|
91
91
|
assert_equal 2, html.scan(/rb/).length
|
|
92
92
|
end
|
|
93
93
|
end
|
|
@@ -62,14 +62,6 @@ describe Makeup::SyntaxHighlighter do
|
|
|
62
62
|
assert_match "Hey<span class=\"nt\"></h1></span>", html
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
it "highlights file with custom suffix" do
|
|
66
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("derp", "rb")
|
|
67
|
-
html = highlight("file.derp", "class File")
|
|
68
|
-
|
|
69
|
-
assert_match "<span class=\"k\">class</span>", html
|
|
70
|
-
assert_match "<span class=\"nc\">File</span>", html
|
|
71
|
-
end
|
|
72
|
-
|
|
73
65
|
it "skips highlighting if lexer is missing" do
|
|
74
66
|
html = highlight("file.trololol", "Yeah yeah yeah")
|
|
75
67
|
|
|
@@ -79,30 +71,7 @@ describe Makeup::SyntaxHighlighter do
|
|
|
79
71
|
|
|
80
72
|
describe "#lexer" do
|
|
81
73
|
it "uses known suffix" do
|
|
82
|
-
assert_equal "
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "uses registered suffix" do
|
|
86
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("blarg", "blarg")
|
|
87
|
-
assert_equal "blarg", @highlighter.lexer("file.blarg")
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
it "uses registered lexer" do
|
|
91
|
-
Makeup::SyntaxHighlighter.add_lexer_alias("bg", "blarg")
|
|
92
|
-
assert_equal "blarg", @highlighter.lexer("file.bg")
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
it "uses known shebang" do
|
|
96
|
-
assert_equal "rb", @highlighter.lexer("some-binary", "#!/usr/bin/env ruby\n")
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "uses registered shebang" do
|
|
100
|
-
Makeup::SyntaxHighlighter.add_lexer_shebang(/\bnode\b/, "js")
|
|
101
|
-
assert_equal "js", @highlighter.lexer("some-binary", "#!/usr/bin/env node\n")
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "uses filename for unknown lexer" do
|
|
105
|
-
assert_equal "some-binary", @highlighter.lexer("some-binary", "class Person\nend")
|
|
74
|
+
assert_equal "ruby", @highlighter.lexer("file.rb")
|
|
106
75
|
end
|
|
107
76
|
end
|
|
108
77
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: makeup
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: pygments.rb
|
|
@@ -18,7 +18,7 @@ dependencies:
|
|
|
18
18
|
requirements:
|
|
19
19
|
- - ~>
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: '0.
|
|
21
|
+
version: '0.4'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -26,7 +26,23 @@ dependencies:
|
|
|
26
26
|
requirements:
|
|
27
27
|
- - ~>
|
|
28
28
|
- !ruby/object:Gem::Version
|
|
29
|
-
version: '0.
|
|
29
|
+
version: '0.4'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: github-linguist
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '2.8'
|
|
38
|
+
type: :runtime
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '2.8'
|
|
30
46
|
- !ruby/object:Gem::Dependency
|
|
31
47
|
name: github-markup
|
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -121,6 +137,8 @@ executables: []
|
|
|
121
137
|
extensions: []
|
|
122
138
|
extra_rdoc_files: []
|
|
123
139
|
files:
|
|
140
|
+
- .gitignore
|
|
141
|
+
- .travis.yml
|
|
124
142
|
- Gemfile
|
|
125
143
|
- Gemfile.lock
|
|
126
144
|
- Rakefile
|
|
@@ -129,6 +147,7 @@ files:
|
|
|
129
147
|
- lib/makeup/code_block_parser.rb
|
|
130
148
|
- lib/makeup/markup.rb
|
|
131
149
|
- lib/makeup/syntax_highlighter.rb
|
|
150
|
+
- lib/makeup/version.rb
|
|
132
151
|
- makeup.gemspec
|
|
133
152
|
- test/makeup/markup_test.rb
|
|
134
153
|
- test/makeup/syntax_highlighter_test.rb
|
|
@@ -153,8 +172,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
153
172
|
version: '0'
|
|
154
173
|
requirements: []
|
|
155
174
|
rubyforge_project: makeup
|
|
156
|
-
rubygems_version: 1.8.
|
|
175
|
+
rubygems_version: 1.8.25
|
|
157
176
|
signing_key:
|
|
158
177
|
specification_version: 3
|
|
159
178
|
summary: Pretty markup
|
|
160
179
|
test_files: []
|
|
180
|
+
has_rdoc:
|