github-markup 1.4.8 → 1.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/github-markup.gemspec +0 -1
- data/lib/github-markup.rb +1 -1
- data/lib/github/markup.rb +10 -16
- data/lib/github/markup/command_implementation.rb +2 -2
- data/lib/github/markup/gem_implementation.rb +2 -2
- data/lib/github/markup/implementation.rb +10 -5
- data/lib/github/markup/markdown.rb +1 -1
- data/lib/github/markup/rdoc.rb +1 -1
- data/lib/github/markups.rb +7 -8
- data/test/markup_test.rb +18 -18
- metadata +2 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cf91fcf2397937d4668c385b12e2bea4e1e63e9
|
4
|
+
data.tar.gz: a4f0427b86e1d9eb0f095c18be9ad4b9dd54e4bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12d5875aa247c073d2d37ee029b74a0b2a75d8cfa90669184145fbadf8d0786c071d9f637569a6fbdd96e345c170d86c471ec8f0aa9cb4ad785b685de0e39ff9
|
7
|
+
data.tar.gz: 91deab9ed4aa53b369f7d941f4bd1b14d7416950ed397174a8c9d5936ff9fc82bf116fac240672673dcdcb7980273cb439c29b69d5652cd13e648ecf64ca7e5f
|
data/README.md
CHANGED
@@ -20,7 +20,7 @@ The following markups are supported. The dependencies listed are required if
|
|
20
20
|
you wish to run the library. You can also run `script/bootstrap` to fetch them all.
|
21
21
|
|
22
22
|
* [.markdown, .mdown, .mkdn, .md](http://daringfireball.net/projects/markdown/) -- `gem install commonmarker` (https://github.com/gjtorikian/commonmarker)
|
23
|
-
* [.textile](
|
23
|
+
* [.textile](https://www.promptworks.com/textile) -- `gem install RedCloth`
|
24
24
|
* [.rdoc](https://rdoc.github.io/rdoc/) -- `gem install rdoc -v 3.6.1`
|
25
25
|
* [.org](http://orgmode.org/) -- `gem install org-ruby`
|
26
26
|
* [.creole](http://wikicreole.org/) -- `gem install creole`
|
data/github-markup.gemspec
CHANGED
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
17
17
|
s.require_paths = %w[lib]
|
18
18
|
|
19
|
-
s.add_dependency "github-linguist", "~> 5.0", ">= 5.0.8"
|
20
19
|
s.add_dependency "rinku"
|
21
20
|
s.add_development_dependency 'rake', '~> 12'
|
22
21
|
s.add_development_dependency 'activesupport', '~> 4.0'
|
data/lib/github-markup.rb
CHANGED
data/lib/github/markup.rb
CHANGED
@@ -37,7 +37,7 @@ module GitHub
|
|
37
37
|
def render(filename, content = nil)
|
38
38
|
content ||= File.read(filename)
|
39
39
|
|
40
|
-
if impl = renderer(filename
|
40
|
+
if impl = renderer(filename)
|
41
41
|
impl.render(content)
|
42
42
|
else
|
43
43
|
content
|
@@ -53,9 +53,9 @@ module GitHub
|
|
53
53
|
content
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
|
-
def markup(symbol,
|
58
|
-
markup_impl(symbol, GemImplementation.new(pattern,
|
56
|
+
|
57
|
+
def markup(symbol, file, pattern, opts = {}, &block)
|
58
|
+
markup_impl(symbol, GemImplementation.new(pattern, file, &block))
|
59
59
|
end
|
60
60
|
|
61
61
|
def markup_impl(symbol, impl)
|
@@ -65,30 +65,24 @@ module GitHub
|
|
65
65
|
markups[symbol] = impl
|
66
66
|
end
|
67
67
|
|
68
|
-
def command(symbol, command,
|
68
|
+
def command(symbol, command, regexp, name, &block)
|
69
69
|
if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
|
70
70
|
command = file
|
71
71
|
end
|
72
72
|
|
73
|
-
markup_impl(symbol, CommandImplementation.new(
|
73
|
+
markup_impl(symbol, CommandImplementation.new(regexp, command, name, &block))
|
74
74
|
end
|
75
75
|
|
76
|
-
def can_render?(filename
|
77
|
-
!!renderer(filename
|
76
|
+
def can_render?(filename)
|
77
|
+
!!renderer(filename)
|
78
78
|
end
|
79
79
|
|
80
|
-
def renderer(filename
|
81
|
-
language = language(filename, content)
|
80
|
+
def renderer(filename)
|
82
81
|
markup_impls.find { |impl|
|
83
|
-
impl.match?(
|
82
|
+
impl.match?(filename)
|
84
83
|
}
|
85
84
|
end
|
86
85
|
|
87
|
-
def language(filename, content)
|
88
|
-
blob = Linguist::Blob.new(filename, content)
|
89
|
-
return Linguist.detect(blob, allow_empty: true)
|
90
|
-
end
|
91
|
-
|
92
86
|
# Define markups
|
93
87
|
markups_rb = File.dirname(__FILE__) + '/markups.rb'
|
94
88
|
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(
|
19
|
-
super
|
18
|
+
def initialize(regexp, command, name, &block)
|
19
|
+
super regexp
|
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(
|
9
|
-
super
|
8
|
+
def initialize(regexp, gem_name, &renderer)
|
9
|
+
super regexp
|
10
10
|
@gem_name = gem_name.to_s
|
11
11
|
@renderer = renderer
|
12
12
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module GitHub
|
2
2
|
module Markup
|
3
3
|
class Implementation
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :regexp
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(regexp)
|
7
|
+
@regexp = regexp
|
8
8
|
end
|
9
9
|
|
10
10
|
def load
|
@@ -15,8 +15,13 @@ module GitHub
|
|
15
15
|
raise NotImplementedError, "subclasses of GitHub::Markup::Implementation must define #render"
|
16
16
|
end
|
17
17
|
|
18
|
-
def match?(
|
19
|
-
|
18
|
+
def match?(filename)
|
19
|
+
file_ext_regexp =~ filename
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def file_ext_regexp
|
24
|
+
@file_ext_regexp ||= /\.(#{regexp})\z/
|
20
25
|
end
|
21
26
|
end
|
22
27
|
end
|
data/lib/github/markup/rdoc.rb
CHANGED
data/lib/github/markups.rb
CHANGED
@@ -1,34 +1,33 @@
|
|
1
1
|
require "github/markup/markdown"
|
2
2
|
require "github/markup/rdoc"
|
3
3
|
require "shellwords"
|
4
|
-
require "linguist"
|
5
4
|
|
6
5
|
markup_impl(::GitHub::Markups::MARKUP_MARKDOWN, ::GitHub::Markup::Markdown.new)
|
7
6
|
|
8
|
-
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth,
|
7
|
+
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, /textile/) do |content|
|
9
8
|
RedCloth.new(content).to_html
|
10
9
|
end
|
11
10
|
|
12
11
|
markup_impl(::GitHub::Markups::MARKUP_RDOC, GitHub::Markup::RDoc.new)
|
13
12
|
|
14
|
-
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby',
|
13
|
+
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', /org/) do |content|
|
15
14
|
Orgmode::Parser.new(content, {
|
16
15
|
:allow_include_files => false,
|
17
16
|
:skip_syntax_highlight => true
|
18
17
|
}).to_html
|
19
18
|
end
|
20
19
|
|
21
|
-
markup(::GitHub::Markups::MARKUP_CREOLE, :creole,
|
20
|
+
markup(::GitHub::Markups::MARKUP_CREOLE, :creole, /creole/) do |content|
|
22
21
|
Creole.creolize(content)
|
23
22
|
end
|
24
23
|
|
25
|
-
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth,
|
24
|
+
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, /mediawiki|wiki/) do |content|
|
26
25
|
wikicloth = WikiCloth::WikiCloth.new(:data => content)
|
27
26
|
WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS << 'tt' unless WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS.include?('tt')
|
28
27
|
wikicloth.to_html(:noedit => true)
|
29
28
|
end
|
30
29
|
|
31
|
-
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor,
|
30
|
+
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, /adoc|asc(iidoc)?/) do |content|
|
32
31
|
Asciidoctor::Compliance.unique_id_start_index = 1
|
33
32
|
Asciidoctor.convert(content, :safe => :secure, :attributes => %w(showtitle=@ idprefix idseparator=- env=github env-github source-highlighter=html-pipeline))
|
34
33
|
end
|
@@ -36,8 +35,8 @@ end
|
|
36
35
|
command(
|
37
36
|
::GitHub::Markups::MARKUP_RST,
|
38
37
|
"python2 -S #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html",
|
39
|
-
|
38
|
+
/re?st(\.txt)?/,
|
40
39
|
"restructuredtext"
|
41
40
|
)
|
42
41
|
|
43
|
-
command(::GitHub::Markups::MARKUP_POD, :pod2html,
|
42
|
+
command(::GitHub::Markups::MARKUP_POD, :pod2html, /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')
|
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')
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_each_render_has_a_name
|
89
|
-
assert_equal "markdown", GitHub::Markup.renderer('README.md'
|
90
|
-
assert_equal "redcloth", GitHub::Markup.renderer('README.textile'
|
91
|
-
assert_equal "rdoc", GitHub::Markup.renderer('README.rdoc'
|
92
|
-
assert_equal "org-ruby", GitHub::Markup.renderer('README.org'
|
93
|
-
assert_equal "creole", GitHub::Markup.renderer('README.creole'
|
94
|
-
assert_equal "wikicloth", GitHub::Markup.renderer('README.wiki'
|
95
|
-
assert_equal "asciidoctor", GitHub::Markup.renderer('README.adoc'
|
96
|
-
assert_equal "restructuredtext", GitHub::Markup.renderer('README.rst'
|
97
|
-
assert_equal "pod", GitHub::Markup.renderer('README.pod'
|
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
|
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',
|
106
|
-
assert GitHub::Markup.can_render?('README.
|
105
|
+
GitHub::Markup.command(:doesntmatter, 'test/fixtures/fail.sh', /fail/, 'fail')
|
106
|
+
assert GitHub::Markup.can_render?('README.fail')
|
107
107
|
begin
|
108
|
-
GitHub::Markup.render('README.
|
108
|
+
GitHub::Markup.render('README.fail', "stop swallowing errors")
|
109
109
|
rescue GitHub::Markup::CommandError => e
|
110
110
|
assert_equal "failure message", e.message
|
111
111
|
else
|
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-markup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: github-linguist
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '5.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 5.0.8
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '5.0'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 5.0.8
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: rinku
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|