Skip to content

Commit 60119d9

Browse files
committed
Merge remote-tracking branch 'origin/master' into implementation-name
* origin/master: (57 commits) tweaks Call out CSS issues Fix link to linguist Release 1.3.3 The command is POSIX, not Posix Release 1.3.2 Spruce up old tests Add empty `a` to support contents with sectnums Add comments to describe these calls No longer true Restore "test" as the default rake task point to other places before creating issues Extconf hack no longer necessary Don't test jdk7 Fallback on open3 if posix-spawn is unavailable. Define CommandImplementation#execute conditional on presence of Posix::Spawn Get html_equal tests running with minitest Updated deprecated .exists? in markup.rb Added the link to Pod::Simple on CPAN. Fix pod output ... Conflicts: lib/github/markup.rb test/markup_test.rb
2 parents 7a06537 + ad43ec6 commit 60119d9

29 files changed

+422
-288
lines changed

.travis.yml

+5-2
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

CONTRIBUTING.md

+12-47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# Contributing
22

3-
Want to contribute? Great!
3+
This library's only job is to decide which markup format to use and call out to an external library to convert the markup to HTML (see the [README](README.md) for more information on how markup is rendered on GitHub.com).
4+
5+
If you are having an issue with:
6+
7+
* **Syntax highlighting** - see [github/linguist](https://github.com/github/linguist/blob/master/CONTRIBUTING.md#fixing-syntax-highlighting)
8+
* **Markdown on GitHub** - contact [email protected]
9+
* **Styling issues on GitHub** - contact [email protected]
10+
11+
Anything else - [search open issues](https://github.com/github/markup/issues) or create an issue and and we'll help point you in the right direction.
12+
13+
## Submitting a Pull Request
414

515
1. Fork it.
616
2. Create a branch (`git checkout -b my_markup`)
@@ -9,57 +19,12 @@ Want to contribute? Great!
919
5. Open a [Pull Request][1]
1020
6. Enjoy a refreshing Diet Coke and wait
1121

12-
13-
There are two ways to add markups.
14-
15-
### Commands
16-
17-
If your markup is in a language other than Ruby, drop a translator
18-
script in `lib/github/commands` which accepts input on STDIN and
19-
returns HTML on STDOUT. See [rest2html][r2h] for an example.
20-
21-
Once your script is in place, edit `lib/github/markups.rb` and tell
22-
GitHub Markup about it. Again we look to [rest2html][r2hc] for
23-
guidance:
24-
25-
command(:rest2html, /re?st(.txt)?/)
26-
27-
Here we're telling GitHub Markup of the existence of a `rest2html`
28-
command which should be used for any file ending in `rest`,
29-
`rst`, `rest.txt` or `rst.txt`. Any regular expression will do.
30-
31-
Finally add your [tests](#testing).
32-
33-
### Classes
34-
35-
If your markup can be translated using a Ruby library, that's
36-
great. Check out `lib/github/markups.rb` for some
37-
examples. Let's look at Markdown:
38-
39-
markup(:markdown, /md|mkdn?|markdown/) do |content|
40-
Markdown.new(content).to_html
41-
end
42-
43-
We give the `markup` method three bits of information: the name of the
44-
file to `require`, a regular expression for extensions to match, and a
45-
block to run with unformatted markup which should return HTML.
46-
47-
If you need to monkeypatch a RubyGem or something, check out the
48-
included RDoc example.
49-
50-
Finally add your [tests](#testing).
51-
52-
### Testing
22+
## Testing
5323

5424
To run the tests:
5525

5626
$ rake
5727

58-
When adding support for a new markup library, create a `README.extension` in `test/markups` along with a `README.extension.html`. As you may imagine, the `README.extension` should be your known input and the
59-
`README.extension.html` should be the desired output.
60-
61-
Now run the tests: `rake`
62-
6328
If nothing complains, congratulations!
6429

6530
## Releasing a new version

Gemfile

+7-4
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"
6-
gem "org-ruby", "= 0.9.1.gh"
9+
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

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## 1.3.3 (2015-02-17)
2+
3+
* Address a slight typo with `POSIX` [#456](https://github.com/github/markup/pull/456)
4+
5+
[Full changelog](https://github.com/github/markup/compare/v1.3.2...v1.3.3)
6+
7+
## 1.3.2 (2015-02-17)
8+
9+
* RST: Output code instead of tt for inline literals [#370](https://github.com/github/markup/pull/370)
10+
* RST: Add IDs to headers so that `.. contents` works with `.. sectnum` [#391](https://github.com/github/markup/pull/391)
11+
12+
[Full changelog](https://github.com/github/markup/compare/v1.3.1...v1.3.2)
13+
14+
## 1.3.1 (2014-11-13)
15+
16+
* Fix name error when trying to use newer versions of RedCarpet [#387](https://github.com/github/markup/pull/387)
17+
18+
[Full changelog](https://github.com/github/markup/compare/v1.3.0...v1.3.1)
19+
120
## 1.3.0 (2014-09-11)
221

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

README.md

+10-32
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
GitHub Markup
22
=============
33

4-
We use this library on GitHub when rendering your README or any other
5-
rich text file. The generated HTML is then run through filters in the [html-pipeline](https://github.com/jch/html-pipeline) to perform things like [sanitization](#html-sanitization) and [syntax highlighting](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/syntax_highlight_filter.rb).
4+
This library is the first step of a journey that every markup file in a repository goes on before it is rendered on GitHub.com:
5+
6+
0. This library converts the raw markup to HTML. See the list of [supported markup formats](#markups) below.
7+
0. The HTML is sanitized, aggressively removing things that could harm you and your kin—such as `script` tags, inline-styles, and `class` or `id` attributes. See the [sanitization filter](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/sanitization_filter.rb) for the full whitelist.
8+
0. Syntax highlighting is performed on code blocks. See [github/linguist](https://github.com/github/linguist#syntax-highlighting) for more information about syntax highlighting.
9+
0. The HTML is passed through other filters in the [html-pipeline](https://github.com/jch/html-pipeline) that add special sauce, such as [emoji](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/emoji_filter.rb), [task lists](https://github.com/github/task_list/blob/master/lib/task_list/filter.rb), [named anchors](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/toc_filter.rb), [CDN caching for images](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/camo_filter.rb), and [autolinking](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/autolink_filter.rb).
10+
0. The resulting HTML is rendered on GitHub.com.
11+
12+
Please see our [contributing guidelines](CONTRIBUTING.md) before reporting an issue.
613

714
Markups
815
-------
@@ -19,7 +26,7 @@ you wish to run the library. You can also run `script/bootstrap` to fetch them a
1926
* [.rst](http://docutils.sourceforge.net/rst.html) -- `easy_install docutils`
2027
* [.asciidoc, .adoc, .asc](http://asciidoc.org/) -- `gem install asciidoctor` (http://asciidoctor.org)
2128
* [.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.
29+
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.
2330

2431
Installation
2532
-----------
@@ -41,32 +48,3 @@ Contributing
4148
------------
4249

4350
See [Contributing](CONTRIBUTING.md)
44-
45-
HTML sanitization
46-
-----------------
47-
48-
HTML rendered by the various markup language processors gets passed through an [HTML sanitization filter](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/sanitization_filter.rb) for security reasons. HTML elements not in the whitelist are removed. HTML attributes not in the whitelist are removed from the preserved elements.
49-
50-
The following HTML elements, organized by category, are whitelisted:
51-
52-
|Type | Elements
53-
|------|----------
54-
|Headings | `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `h7`, `h8`
55-
|Prose | `p`, `div`, `blockquote`
56-
|Formatted | `pre`
57-
| Inline | `b`, `i`, `strong`, `em`, `tt`, `code`, `ins`, `del`, `sup`, `sub`, `kbd`, `samp`, `q`, `var`
58-
| Lists | `ol`, `ul`, `li`, `dl`, `dt`, `dd`
59-
| Tables | `table`, `thead`, `tbody`, `tfoot`, `tr`, `td`, `th`
60-
| Breaks | `br`, `hr`
61-
| Ruby (East Asian) | `ruby`, `rt`, `rp`
62-
63-
The following attributes, organized by element, are whitelisted:
64-
65-
|Element | Attributes
66-
|------|----------
67-
| `a` | `href` (`http://`, `https://`, `mailto://`, `github-windows://`, and `github-mac://` URI schemes and relative paths only)
68-
| `img` | `src` (`http://` and `https://` URI schemes and relative paths only)
69-
| `div` | `itemscope`, `itemtype`
70-
| All | `abbr`, `accept`, `accept-charset`, `accesskey`, `action`, `align`, `alt`, `axis`, `border`, `cellpadding`, `cellspacing`, `char`, `charoff`, `charset`, `checked`, `cite`, `clear`, `cols`, `colspan`, `color`, `compact`, `coords`, `datetime`, `dir`, `disabled`, `enctype`, `for`, `frame`, `headers`, `height`, `hreflang`, `hspace`, `ismap`, `label`, `lang`, `longdesc`, `maxlength`, `media`, `method`, `multiple`, `name`, `nohref`, `noshade`, `nowrap`, `prompt`, `readonly`, `rel`, `rev`, `rows`, `rowspan`, `rules`, `scope`, `selected`, `shape`, `size`, `span`, `start`, `summary`, `tabindex`, `target`, `title`, `type`, `usemap`, `valign`, `value`, `vspace`, `width`, `itemprop`
71-
72-
Note that the `id` attribute is *not* whitelisted.

github-markup.gemspec

+5-1
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

+1-1
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.3'
44
Version = VERSION
55
end
66
end

lib/github/commands/foo.rst

-7
This file was deleted.

lib/github/commands/rest2html

+13-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ class GitHubHTMLTranslator(HTMLTranslator):
6666
# see also: http://bit.ly/1exfq2h (warning! sourceforge link.)
6767
def depart_document(self, node):
6868
HTMLTranslator.depart_document(self, node)
69-
self.html_body.pop(0)
70-
self.html_body.pop()
69+
self.html_body.pop(0) # pop the starting <div> off
70+
self.html_body.pop() # pop the ending </div> off
7171

7272
# technique for visiting sections, without generating additional divs
7373
# see also: http://bit.ly/NHtyRx
74+
# the a is to support ::contents with ::sectnums: http://git.io/N1yC
7475
def visit_section(self, node):
76+
id_attribute = node.attributes['ids'][0]
77+
self.body.append('<a name="%s"></a>\n' % id_attribute)
7578
self.section_level += 1
7679

7780
def depart_section(self, node):
@@ -86,6 +89,14 @@ class GitHubHTMLTranslator(HTMLTranslator):
8689
else:
8790
self.body.append(self.starttag(node, 'pre'))
8891

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+
89100
def visit_table(self, node):
90101
classes = ' '.join(['docutils', self.settings.table_style]).strip()
91102
self.body.append(

lib/github/markup.rb

+1-1
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, name, &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

+32-7
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
@@ -33,14 +38,34 @@ def call_block(rendered, content)
3338
end
3439
end
3540

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

lib/github/markup/markdown.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Markdown < Implementation
88
GitHub::Markdown.render(content)
99
},
1010
"redcarpet" => proc { |content|
11-
RedcarpetCompat.new(content).to_html
11+
Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(content)
1212
},
1313
"rdiscount" => proc { |content|
1414
RDiscount.new(content).to_html

test/fixtures/fail.sh

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

0 commit comments

Comments
 (0)