github-markup 1.4.9 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/github-markup.gemspec +1 -0
- data/lib/github-markup.rb +1 -1
- data/lib/github/markup.rb +24 -10
- data/lib/github/markup/command_implementation.rb +2 -2
- data/lib/github/markup/gem_implementation.rb +2 -2
- data/lib/github/markup/implementation.rb +14 -4
- data/lib/github/markup/markdown.rb +3 -1
- data/lib/github/markup/rdoc.rb +1 -1
- data/lib/github/markups.rb +7 -6
- data/test/markup_test.rb +18 -18
- metadata +21 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3873917ff6bcce326f3db9af115b479093b5bd41
|
4
|
+
data.tar.gz: 390eb33b65634cf8a3821d83c35157bc7940b565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2428b43fe04c56a03fb6508aa87bec722edb08cd5afaad71c46977892943e9cf6a3c1281bd73750fb90bb27610de38a5fe947f255454004ade830eb083367472
|
7
|
+
data.tar.gz: fc853cfc772810f6456c9b7933b722461adcafa109fddd78198972c34855e8355e3257e622a92af41b63e3465b325c72340630695f801106a76f49925a5addf4
|
data/github-markup.gemspec
CHANGED
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'sanitize', '~> 2.1', '>= 2.1.0'
|
25
25
|
s.add_development_dependency 'nokogiri', '1.6.8.1'
|
26
26
|
s.add_development_dependency 'nokogiri-diff', '~> 0.2.0'
|
27
|
+
s.add_development_dependency "github-linguist", "~> 5.0", ">= 5.0.8"
|
27
28
|
end
|
data/lib/github-markup.rb
CHANGED
data/lib/github/markup.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
begin
|
2
|
+
require "linguist"
|
3
|
+
rescue LoadError
|
4
|
+
# Rely on extensions instead.
|
5
|
+
end
|
6
|
+
|
1
7
|
require "github/markup/command_implementation"
|
2
8
|
require "github/markup/gem_implementation"
|
3
9
|
|
@@ -37,7 +43,7 @@ module GitHub
|
|
37
43
|
def render(filename, content = nil)
|
38
44
|
content ||= File.read(filename)
|
39
45
|
|
40
|
-
if impl = renderer(filename)
|
46
|
+
if impl = renderer(filename, content)
|
41
47
|
impl.render(content)
|
42
48
|
else
|
43
49
|
content
|
@@ -53,9 +59,9 @@ module GitHub
|
|
53
59
|
content
|
54
60
|
end
|
55
61
|
end
|
56
|
-
|
57
|
-
def markup(symbol,
|
58
|
-
markup_impl(symbol, GemImplementation.new(
|
62
|
+
|
63
|
+
def markup(symbol, gem_name, regexp, languages, opts = {}, &block)
|
64
|
+
markup_impl(symbol, GemImplementation.new(regexp, languages, gem_name, &block))
|
59
65
|
end
|
60
66
|
|
61
67
|
def markup_impl(symbol, impl)
|
@@ -65,24 +71,32 @@ module GitHub
|
|
65
71
|
markups[symbol] = impl
|
66
72
|
end
|
67
73
|
|
68
|
-
def command(symbol, command, regexp, name, &block)
|
74
|
+
def command(symbol, command, regexp, languages, name, &block)
|
69
75
|
if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
|
70
76
|
command = file
|
71
77
|
end
|
72
78
|
|
73
|
-
markup_impl(symbol, CommandImplementation.new(regexp, command, name, &block))
|
79
|
+
markup_impl(symbol, CommandImplementation.new(regexp, languages, command, name, &block))
|
74
80
|
end
|
75
81
|
|
76
|
-
def can_render?(filename)
|
77
|
-
!!renderer(filename)
|
82
|
+
def can_render?(filename, content)
|
83
|
+
!!renderer(filename, content)
|
78
84
|
end
|
79
85
|
|
80
|
-
def renderer(filename)
|
86
|
+
def renderer(filename, content)
|
87
|
+
language = language(filename, content)
|
81
88
|
markup_impls.find { |impl|
|
82
|
-
impl.match?(filename)
|
89
|
+
impl.match?(filename, language)
|
83
90
|
}
|
84
91
|
end
|
85
92
|
|
93
|
+
def language(filename, content)
|
94
|
+
if defined?(::Linguist)
|
95
|
+
blob = Linguist::Blob.new(filename, content)
|
96
|
+
return Linguist.detect(blob, allow_empty: true)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
86
100
|
# Define markups
|
87
101
|
markups_rb = File.dirname(__FILE__) + '/markups.rb'
|
88
102
|
instance_eval File.read(markups_rb), markups_rb
|
@@ -15,8 +15,8 @@ module GitHub
|
|
15
15
|
class CommandImplementation < Implementation
|
16
16
|
attr_reader :command, :block, :name
|
17
17
|
|
18
|
-
def initialize(regexp, command, name, &block)
|
19
|
-
super
|
18
|
+
def initialize(regexp, languages, command, name, &block)
|
19
|
+
super(regexp, languages)
|
20
20
|
@command = command.to_s
|
21
21
|
@block = block
|
22
22
|
@name = name
|
@@ -5,8 +5,8 @@ module GitHub
|
|
5
5
|
class GemImplementation < Implementation
|
6
6
|
attr_reader :gem_name, :renderer
|
7
7
|
|
8
|
-
def initialize(regexp, gem_name, &renderer)
|
9
|
-
super
|
8
|
+
def initialize(regexp, languages, gem_name, &renderer)
|
9
|
+
super(regexp, languages)
|
10
10
|
@gem_name = gem_name.to_s
|
11
11
|
@renderer = renderer
|
12
12
|
end
|
@@ -2,9 +2,14 @@ module GitHub
|
|
2
2
|
module Markup
|
3
3
|
class Implementation
|
4
4
|
attr_reader :regexp
|
5
|
+
attr_reader :languages
|
5
6
|
|
6
|
-
def initialize(regexp)
|
7
|
+
def initialize(regexp, languages)
|
7
8
|
@regexp = regexp
|
9
|
+
|
10
|
+
if defined?(::Linguist)
|
11
|
+
@languages = languages.map {|l| Linguist::Language[l]}
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
10
15
|
def load
|
@@ -15,11 +20,16 @@ module GitHub
|
|
15
20
|
raise NotImplementedError, "subclasses of GitHub::Markup::Implementation must define #render"
|
16
21
|
end
|
17
22
|
|
18
|
-
def match?(filename)
|
19
|
-
|
23
|
+
def match?(filename, language)
|
24
|
+
if defined?(::Linguist)
|
25
|
+
languages.include? language
|
26
|
+
else
|
27
|
+
file_ext_regexp =~ filename
|
28
|
+
end
|
20
29
|
end
|
21
30
|
|
22
|
-
|
31
|
+
private
|
32
|
+
|
23
33
|
def file_ext_regexp
|
24
34
|
@file_ext_regexp ||= /\.(#{regexp})\z/
|
25
35
|
end
|
data/lib/github/markup/rdoc.rb
CHANGED
data/lib/github/markups.rb
CHANGED
@@ -4,30 +4,30 @@ require "shellwords"
|
|
4
4
|
|
5
5
|
markup_impl(::GitHub::Markups::MARKUP_MARKDOWN, ::GitHub::Markup::Markdown.new)
|
6
6
|
|
7
|
-
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile
|
7
|
+
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile/, ["Textile"]) do |content|
|
8
8
|
RedCloth.new(content).to_html
|
9
9
|
end
|
10
10
|
|
11
11
|
markup_impl(::GitHub::Markups::MARKUP_RDOC, GitHub::Markup::RDoc.new)
|
12
12
|
|
13
|
-
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org
|
13
|
+
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org/, ["Org"]) do |content|
|
14
14
|
Orgmode::Parser.new(content, {
|
15
15
|
:allow_include_files => false,
|
16
16
|
:skip_syntax_highlight => true
|
17
17
|
}).to_html
|
18
18
|
end
|
19
19
|
|
20
|
-
markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole
|
20
|
+
markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole/, ["Creole"]) do |content|
|
21
21
|
Creole.creolize(content)
|
22
22
|
end
|
23
23
|
|
24
|
-
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki
|
24
|
+
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki/, ["MediaWiki"]) do |content|
|
25
25
|
wikicloth = WikiCloth::WikiCloth.new(:data => content)
|
26
26
|
WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS << 'tt' unless WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS.include?('tt')
|
27
27
|
wikicloth.to_html(:noedit => true)
|
28
28
|
end
|
29
29
|
|
30
|
-
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)
|
30
|
+
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)?/, ["AsciiDoc"]) do |content|
|
31
31
|
Asciidoctor::Compliance.unique_id_start_index = 1
|
32
32
|
Asciidoctor.convert(content, :safe => :secure, :attributes => %w(showtitle=@ idprefix idseparator=- env=github env-github source-highlighter=html-pipeline))
|
33
33
|
end
|
@@ -36,7 +36,8 @@ command(
|
|
36
36
|
::GitHub::Markups::MARKUP_RST,
|
37
37
|
"python2 -S #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html",
|
38
38
|
/re?st(\.txt)?/,
|
39
|
+
["reStructuredText"],
|
39
40
|
"restructuredtext"
|
40
41
|
)
|
41
42
|
|
42
|
-
command(::GitHub::Markups::MARKUP_POD, :pod2html, /pod/, "pod")
|
43
|
+
command(::GitHub::Markups::MARKUP_POD, :pod2html, /pod/, ["Pod"], "pod")
|
data/test/markup_test.rb
CHANGED
@@ -77,24 +77,24 @@ message
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def test_knows_what_it_can_and_cannot_render
|
80
|
-
assert_equal false, GitHub::Markup.can_render?('README.html')
|
81
|
-
assert_equal true, GitHub::Markup.can_render?('README.markdown')
|
82
|
-
assert_equal true, GitHub::Markup.can_render?('README.rmd')
|
83
|
-
assert_equal true, GitHub::Markup.can_render?('README.Rmd')
|
84
|
-
assert_equal false, GitHub::Markup.can_render?('README.cmd')
|
85
|
-
assert_equal true, GitHub::Markup.can_render?('README.litcoffee')
|
80
|
+
assert_equal false, GitHub::Markup.can_render?('README.html', '<h1>Title</h1>')
|
81
|
+
assert_equal true, GitHub::Markup.can_render?('README.markdown', '=== Title')
|
82
|
+
assert_equal true, GitHub::Markup.can_render?('README.rmd', '=== Title')
|
83
|
+
assert_equal true, GitHub::Markup.can_render?('README.Rmd', '=== Title')
|
84
|
+
assert_equal false, GitHub::Markup.can_render?('README.cmd', 'echo 1')
|
85
|
+
assert_equal true, GitHub::Markup.can_render?('README.litcoffee', 'Title')
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_each_render_has_a_name
|
89
|
-
assert_equal "markdown", GitHub::Markup.renderer('README.md').name
|
90
|
-
assert_equal "redcloth", GitHub::Markup.renderer('README.textile').name
|
91
|
-
assert_equal "rdoc", GitHub::Markup.renderer('README.rdoc').name
|
92
|
-
assert_equal "org-ruby", GitHub::Markup.renderer('README.org').name
|
93
|
-
assert_equal "creole", GitHub::Markup.renderer('README.creole').name
|
94
|
-
assert_equal "wikicloth", GitHub::Markup.renderer('README.wiki').name
|
95
|
-
assert_equal "asciidoctor", GitHub::Markup.renderer('README.adoc').name
|
96
|
-
assert_equal "restructuredtext", GitHub::Markup.renderer('README.rst').name
|
97
|
-
assert_equal "pod", GitHub::Markup.renderer('README.pod').name
|
89
|
+
assert_equal "markdown", GitHub::Markup.renderer('README.md', '=== Title').name
|
90
|
+
assert_equal "redcloth", GitHub::Markup.renderer('README.textile', '* One').name
|
91
|
+
assert_equal "rdoc", GitHub::Markup.renderer('README.rdoc', '* One').name
|
92
|
+
assert_equal "org-ruby", GitHub::Markup.renderer('README.org', '* Title').name
|
93
|
+
assert_equal "creole", GitHub::Markup.renderer('README.creole', '= Title =').name
|
94
|
+
assert_equal "wikicloth", GitHub::Markup.renderer('README.wiki', '<h1>Title</h1>').name
|
95
|
+
assert_equal "asciidoctor", GitHub::Markup.renderer('README.adoc', '== Title').name
|
96
|
+
assert_equal "restructuredtext", GitHub::Markup.renderer('README.rst', 'Title').name
|
97
|
+
assert_equal "pod", GitHub::Markup.renderer('README.pod', '=begin').name
|
98
98
|
end
|
99
99
|
|
100
100
|
def test_rendering_by_symbol
|
@@ -102,10 +102,10 @@ message
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_raises_error_if_command_exits_non_zero
|
105
|
-
GitHub::Markup.command(:doesntmatter, 'test/fixtures/fail.sh', /fail/, 'fail')
|
106
|
-
assert GitHub::Markup.can_render?('README.
|
105
|
+
GitHub::Markup.command(:doesntmatter, 'test/fixtures/fail.sh', /fail/, ['Java'], 'fail')
|
106
|
+
assert GitHub::Markup.can_render?('README.java', 'stop swallowing errors')
|
107
107
|
begin
|
108
|
-
GitHub::Markup.render('README.
|
108
|
+
GitHub::Markup.render('README.java', "stop swallowing errors")
|
109
109
|
rescue GitHub::Markup::CommandError => e
|
110
110
|
assert_equal "failure message", e.message
|
111
111
|
else
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
@@ -134,6 +134,26 @@ dependencies:
|
|
134
134
|
- - "~>"
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: 0.2.0
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: github-linguist
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '5.0'
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 5.0.8
|
147
|
+
type: :development
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '5.0'
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 5.0.8
|
137
157
|
description: This gem is used by GitHub to render any fancy markup such as Markdown,
|
138
158
|
Textile, Org-Mode, etc. Fork it and add your own!
|
139
159
|
email: chris@ozmm.org
|