Skip to content

Commit 1c7658d

Browse files
committed
Merge master
2 parents 6055f94 + 0ad1e5d commit 1c7658d

24 files changed

+308
-191
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
language: ruby
12
before_install: sudo pip install docutils
23
rvm:
34
- 1.9.3
45
- 2.0.0
56
- 2.1.1
7+
- jruby-19mode
8+
jdk:
9+
- oraclejdk8
610
notifications:
7-
disabled: true
8-
bundler_args: --without development
11+
email: false

Gemfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
source "http://rubygems.org"
22
gemspec
3-
gem "redcarpet"
3+
4+
gem "posix-spawn", :platforms => :ruby
5+
gem "redcarpet", :platforms => :ruby
6+
gem "kramdown", :platforms => :jruby
47
gem "RedCloth"
58
gem "rdoc", "~>3.6"
69
gem "org-ruby", "= 0.9.9"
710
gem "creole", "~>0.3.6"
8-
gem "wikicloth", "=0.8.1"
11+
gem "wikicloth", "=0.8.1", :platforms => :ruby
912
gem "asciidoctor", "= 0.1.4"
10-
gem "rake"
13+
gem "rake"

HISTORY.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.3.1 (2014-11-13)
2+
3+
* Fix name error when trying to use newer versions of RedCarpet [#387](https://github.com/github/markup/pull/387)
4+
5+
[Full changelog](https://github.com/github/markup/compare/v1.3.0...v1.3.1)
6+
17
## 1.3.0 (2014-09-11)
28

39
* Extend the field limit for tables to 50 characters for RST [#306](https://github.com/github/markup/pull/306)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ you wish to run the library. You can also run `script/bootstrap` to fetch them a
1919
* [.rst](http://docutils.sourceforge.net/rst.html) -- `easy_install docutils`
2020
* [.asciidoc, .adoc, .asc](http://asciidoc.org/) -- `gem install asciidoctor` (http://asciidoctor.org)
2121
* [.pod](http://search.cpan.org/dist/perl/pod/perlpod.pod) -- `Pod::Simple::HTML`
22-
comes with Perl >= 5.10. Lower versions should install Pod::Simple from CPAN.
22+
comes with Perl >= 5.10. Lower versions should install [Pod::Simple](http://search.cpan.org/~dwheeler/Pod-Simple-3.28/lib/Pod/Simple.pod) from CPAN.
2323

2424
Installation
2525
-----------

github-markup.gemspec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ Gem::Specification.new do |s|
1616
s.test_files = s.files.grep(%r{^(test|spec|features)/})
1717
s.require_paths = %w[lib]
1818

19-
s.add_dependency "posix-spawn", "~> 0.3.8"
19+
s.add_development_dependency 'minitest', '~> 5.4.3'
20+
s.add_development_dependency 'html-pipeline', '~> 1.0'
21+
s.add_development_dependency 'sanitize', '~> 2.1.0'
22+
s.add_development_dependency 'nokogiri', '~> 1.6.1'
23+
s.add_development_dependency 'nokogiri-diff', '~> 0.2.0'
2024
end

lib/github-markup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module GitHub
22
module Markup
3-
VERSION = '1.3.0'
3+
VERSION = '1.3.1'
44
Version = VERSION
55
end
66
end

lib/github/commands/rest2html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ class GitHubHTMLTranslator(HTMLTranslator):
8989
else:
9090
self.body.append(self.starttag(node, 'pre'))
9191

92+
# always wrap two-backtick rst inline literals in <code>, not <tt>
93+
# this also avoids the generation of superfluous <span> tags
94+
def visit_literal(self, node):
95+
self.body.append(self.starttag(node, 'code', suffix=''))
96+
97+
def depart_literal(self, node):
98+
self.body.append('</code>')
99+
92100
def visit_table(self, node):
93101
classes = ' '.join(['docutils', self.settings.table_style]).strip()
94102
self.body.append(

lib/github/markup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def markup(file, pattern, opts = {}, &block)
3131
end
3232

3333
def command(command, regexp, &block)
34-
if File.exists?(file = File.dirname(__FILE__) + "/commands/#{command}")
34+
if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
3535
command = file
3636
end
3737

lib/github/markup/command_implementation.rb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
require "posix-spawn"
1+
begin
2+
require "posix-spawn"
3+
rescue LoadError
4+
require "open3"
5+
end
6+
27
require "github/markup/implementation"
38

49
module GitHub
@@ -31,15 +36,35 @@ def call_block(rendered, content)
3136
rendered
3237
end
3338
end
34-
35-
def execute(command, target)
36-
spawn = POSIX::Spawn::Child.new(*command, :input => target)
37-
if spawn.status.success?
38-
spawn.out.gsub("\r", '').force_encoding(target.encoding)
39-
else
40-
raise CommandError.new(spawn.err.strip)
39+
40+
if defined?(Posix::Spawn)
41+
def execute(command, target)
42+
spawn = POSIX::Spawn::Child.new(*command, :input => target)
43+
if spawn.status.success?
44+
sanitize(spawn.out, target.encoding)
45+
else
46+
raise CommandError.new(spawn.err.strip)
47+
end
48+
end
49+
else
50+
def execute(command, target)
51+
output = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thr|
52+
stdin.puts target
53+
stdin.close
54+
if wait_thr.value.success?
55+
stdout.readlines
56+
else
57+
raise CommandError.new(stderr.readlines.join('').strip)
58+
end
59+
end
60+
sanitize(output.join(''), target.encoding)
4161
end
4262
end
63+
64+
def sanitize(input, encoding)
65+
input.gsub("\r", '').force_encoding(encoding)
66+
end
67+
4368
end
4469
end
4570
end

test/fixtures/fail.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
echo "failure message">&2 && false

test/markup_test.rb

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,61 @@
33
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
44

55
require 'github/markup'
6-
require 'test/unit'
6+
require 'minitest/autorun'
7+
require 'html/pipeline'
8+
require 'nokogiri'
9+
require 'nokogiri/diff'
10+
11+
def normalize_html(text)
12+
text.strip!
13+
text.gsub!(/\s\s+/,' ')
14+
text.gsub!(/\p{Pi}|\p{Pf}|&amp;quot;/u,'"')
15+
text.gsub!("\u2026",'...')
16+
text
17+
end
18+
19+
def assert_html_equal(expected, actual, msg = nil)
20+
assertion = Proc.new do
21+
expected_doc = Nokogiri::HTML(expected) {|config| config.noblanks}
22+
actual_doc = Nokogiri::HTML(actual) {|config| config.noblanks}
23+
24+
expected_doc.search('//text()').each {|node| node.content = normalize_html node.content}
25+
actual_doc.search('//text()').each {|node| node.content = normalize_html node.content}
26+
27+
ignore_changes = {"+" => Regexp.union(/^\s*id=".*"\s*$/), "-" => nil}
28+
expected_doc.diff(actual_doc) do |change, node|
29+
if change != ' ' && !node.blank? then
30+
break unless node.to_html =~ ignore_changes[change]
31+
end
32+
end
33+
end
34+
assert(assertion.call, msg)
35+
end
36+
37+
class MarkupTest < Minitest::Test
38+
class MarkupFilter < HTML::Pipeline::Filter
39+
def call
40+
filename = context[:filename]
41+
GitHub::Markup.render(filename, File.read(filename)).strip.force_encoding("utf-8")
42+
end
43+
end
44+
45+
Pipeline = HTML::Pipeline.new [
46+
MarkupFilter,
47+
HTML::Pipeline::SanitizationFilter
48+
]
749

8-
class MarkupTest < Test::Unit::TestCase
950
Dir['test/markups/README.*'].each do |readme|
1051
next if readme =~ /html$/
1152
markup = readme.split('/').last.gsub(/^README\./, '')
1253

1354
define_method "test_#{markup}" do
14-
source = File.read(readme)
55+
skip "Skipping MediaWiki test because wikicloth is currently not compatible with JRuby." if markup == "mediawiki" && RUBY_PLATFORM == "java"
1556

57+
source = File.read(readme)
1658
expected_file = "#{readme}.html"
1759
expected = File.read(expected_file).rstrip
18-
actual = GitHub::Markup.render(readme, File.read(readme)).rstrip.force_encoding("utf-8")
60+
actual = Pipeline.to_html(nil, :filename => readme)
1961

2062
if source != expected
2163
assert(source != actual, "#{markup} did not render anything")
@@ -27,8 +69,8 @@ class MarkupTest < Test::Unit::TestCase
2769
f.read
2870
end
2971

30-
assert expected == actual, <<message
31-
#{File.basename expected_file}'s contents don't match command output:
72+
assert_html_equal expected, actual, <<message
73+
#{File.basename expected_file}'s contents are not html equal to output:
3274
#{diff}
3375
message
3476
end
@@ -44,7 +86,7 @@ def test_knows_what_it_can_and_cannot_render
4486
end
4587

4688
def test_raises_error_if_command_exits_non_zero
47-
GitHub::Markup.command('echo "failure message">&2 && false', /fail/)
89+
GitHub::Markup.command('test/fixtures/fail.sh', /fail/)
4890
assert GitHub::Markup.can_render?('README.fail')
4991
begin
5092
GitHub::Markup.render('README.fail', "stop swallowing errors")

test/markups/README.asciidoc.html

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1>Document Title</h1>
2-
<div class="sect1">
3-
<h2 id="first-section">First Section</h2>
4-
<div class="sectionbody">
5-
<div class="ulist">
2+
<div>
3+
<h2>First Section</h2>
4+
<div>
5+
<div>
66
<ul>
77
<li>
88
<p>One</p>
@@ -14,26 +14,25 @@ <h2 id="first-section">First Section</h2>
1414
</div>
1515
</div>
1616
</div>
17-
<div class="sect1">
18-
<h2 id="second-section">Second Section</h2>
19-
<div class="sectionbody">
20-
<div class="admonitionblock note">
17+
<div>
18+
<h2>Second Section</h2>
19+
<div>
20+
<div>
2121
<table>
2222
<tr>
23-
<td class="icon">
24-
<div class="title">Note</div>
23+
<td>
24+
<div>Note</div>
2525
</td>
26-
<td class="content">
26+
<td>
2727
Here is some source code.
2828
</td>
2929
</tr>
3030
</table>
3131
</div>
32-
<div class="listingblock">
33-
<div class="content">
32+
<div>
33+
<div>
3434
<pre lang="ruby"><code>puts "Hello, World!"</code></pre>
3535
</div>
3636
</div>
3737
</div>
38-
</div>
39-
38+
</div>

test/markups/README.creole.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
<h1>H1</h1><h2>H2</h2><p>paragraph of text that will be turned into a paragraph element. It can go over several lines with line breaks, it will be turned into a contiguous paragraph element.</p><p>You can force a linebreak in your paragraph text<br/>thusly.</p><ul><li>a list element<ul><li>sub list element</li></ul></li><li>2nd list element</li></ul><pre>pre formatted text
1+
<h1>H1</h1><h2>H2</h2><p>paragraph of text that will be turned into a paragraph element. It can go over several lines with line breaks, it will be turned into a contiguous paragraph element.</p><p>You can force a linebreak in your paragraph text<br>thusly.</p><ul>
2+
<li>a list element<ul><li>sub list element</li></ul>
3+
</li>
4+
<li>2nd list element</li>
5+
</ul><pre>pre formatted text
26

37
$ ls -la
48
total 56

test/markups/README.litcoffee.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ <h2>Literate CoffeeScript Test</h2>
66

77
<p>comment comment</p>
88

9-
<pre><code>test &quot;basic literate CoffeeScript parsing&quot;, -&gt;
9+
<pre><code>test "basic literate CoffeeScript parsing", -&gt;
1010
ok yes
1111
</code></pre>
1212

1313
<p>now with a...</p>
1414

15-
<pre><code>test &quot;broken up indentation&quot;, -&gt;
15+
<pre><code>test "broken up indentation", -&gt;
1616
</code></pre>
1717

1818
<p>... broken up ...</p>
@@ -27,7 +27,7 @@ <h2>Literate CoffeeScript Test</h2>
2727

2828
<p>Code must be separated from text by a blank line.</p>
2929

30-
<pre><code>test &quot;code blocks must be preceded by a blank line&quot;, -&gt;
30+
<pre><code>test "code blocks must be preceded by a blank line", -&gt;
3131
</code></pre>
3232

3333
<p>The next line is part of the text and will not be executed.
@@ -38,7 +38,7 @@ <h2>Literate CoffeeScript Test</h2>
3838

3939
<p>Code in <code>backticks is not parsed</code> and...</p>
4040

41-
<pre><code>test &quot;comments in indented blocks work&quot;, -&gt;
41+
<pre><code>test "comments in indented blocks work", -&gt;
4242
do -&gt;
4343
do -&gt;
4444
# Regular comment.
@@ -62,5 +62,5 @@ <h2>Literate CoffeeScript Test</h2>
6262

6363
<p>Tabs work too:</p>
6464

65-
<p>test &quot;tabbed code&quot;, -&gt;
66-
ok yes</p>
65+
<p>test "tabbed code", -&gt;
66+
ok yes</p>

test/markups/README.markdown.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<ul>
22
<li>One</li>
33
<li>Two</li>
4-
</ul>
4+
</ul>

0 commit comments

Comments
 (0)