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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 079e97612136f122c4f4d65390b4b7c510224531
4
- data.tar.gz: 207db8ce9d4a6d229b03c22113ec4d4423d61c68
3
+ metadata.gz: 8cf91fcf2397937d4668c385b12e2bea4e1e63e9
4
+ data.tar.gz: a4f0427b86e1d9eb0f095c18be9ad4b9dd54e4bd
5
5
  SHA512:
6
- metadata.gz: e5597a5f945a0fc346427b8d23cff62344c2592bca272f012e70fdadaf7a422ef7aa624d92a7e33efbbb7df919a49f8860c3ad33050b9d5f85bcd9b8fc487b93
7
- data.tar.gz: 7471c4ae95368acbe10fe2dcf96286c845c5c2583c8e006be9b45bbcc08b470dd098203e58e1933d01d7eb7a4e3b5bbd03ec3a24b74c033de4b422be3d9dccbb
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](http://www.textism.com/tools/textile/) -- `gem install RedCloth`
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`
@@ -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
@@ -1,6 +1,6 @@
1
1
  module GitHub
2
2
  module Markup
3
- VERSION = '1.4.8'
3
+ VERSION = '1.4.9'
4
4
  Version = VERSION
5
5
  end
6
6
  end
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, content)
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, gem_name, pattern, opts = {}, &block)
58
- markup_impl(symbol, GemImplementation.new(pattern, gem_name, &block))
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, languages, name, &block)
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(languages, command, name, &block))
73
+ markup_impl(symbol, CommandImplementation.new(regexp, command, name, &block))
74
74
  end
75
75
 
76
- def can_render?(filename, content)
77
- !!renderer(filename, content)
76
+ def can_render?(filename)
77
+ !!renderer(filename)
78
78
  end
79
79
 
80
- def renderer(filename, content)
81
- language = language(filename, content)
80
+ def renderer(filename)
82
81
  markup_impls.find { |impl|
83
- impl.match?(language)
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(languages, command, name, &block)
19
- super languages
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(languages, gem_name, &renderer)
9
- super languages
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 :languages
4
+ attr_reader :regexp
5
5
 
6
- def initialize(languages)
7
- @languages = languages
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?(language)
19
- languages.include? language
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
@@ -28,7 +28,7 @@ module GitHub
28
28
  }
29
29
 
30
30
  def initialize
31
- super([Linguist::Language["Markdown"], Linguist::Language["RMarkdown"], Linguist::Language["Literate CoffeeScript"]])
31
+ super(/md|rmd|mkdn?|mdwn|mdown|markdown|litcoffee/i)
32
32
  end
33
33
 
34
34
  def load
@@ -6,7 +6,7 @@ module GitHub
6
6
  module Markup
7
7
  class RDoc < Implementation
8
8
  def initialize
9
- super([Linguist::Language["RDoc"]])
9
+ super(/rdoc/)
10
10
  end
11
11
 
12
12
  def render(content)
@@ -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, [Linguist::Language["Textile"]]) do |content|
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', [Linguist::Language["Org"]]) do |content|
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, [Linguist::Language["Creole"]]) do |content|
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, [Linguist::Language["MediaWiki"]]) do |content|
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, [Linguist::Language["AsciiDoc"]]) do |content|
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
- [Linguist::Language["reStructuredText"]],
38
+ /re?st(\.txt)?/,
40
39
  "restructuredtext"
41
40
  )
42
41
 
43
- command(::GitHub::Markups::MARKUP_POD, :pod2html, [Linguist::Language["Pod"]], "pod")
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', '<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')
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', '=== 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
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', [Linguist::Language['Java']], 'fail')
106
- assert GitHub::Markup.can_render?('README.java', 'stop swallowing errors')
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.java', "stop swallowing errors")
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.8
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-22 00:00:00.000000000 Z
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