Skip to content

Commit 58c9814

Browse files
committed
Merge branch 'pchaigno-rmarkdown' into release-1.3.0
* pchaigno-rmarkdown: Case-insensitive on just markdown Perform case-insensitive test for file extensions Escape the filepath to rest2html so paths containing spaces will be passed to CommandImplementation#execute correctly. Update README.md Tables are cooler Organize the README's whitelisted elements a bit better Render RMarkdown (.rmd) as Markdown Force encoding of posix_spawn output Force encoding of posix_spawn output Fix a spelling mistake rst2html: Extend the field_name_limit to 50
2 parents bc1a936 + d41a9e1 commit 58c9814

File tree

10 files changed

+75
-23
lines changed

10 files changed

+75
-23
lines changed

README.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ GitHub Markup
22
=============
33

44
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 [santization](#html-sanitization) and [syntax highlighting](https://github.com/jch/html-pipeline/blob/master/lib/html/pipeline/syntax_highlight_filter.rb).
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).
66

77
Markups
88
-------
@@ -37,32 +37,36 @@ Or, more realistically:
3737
require 'github/markup'
3838
GitHub::Markup.render(file, File.read(file))
3939

40+
Contributing
41+
------------
42+
43+
See [Contributing](CONTRIBUTING.md)
44+
4045
HTML sanitization
4146
-----------------
4247

4348
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.
4449

4550
The following HTML elements, organized by category, are whitelisted:
4651

47-
* Headings: h1, h2, h3, h4, h5, h6, h7, h8
48-
* Prose: p, div, blockquote
49-
* Preformatted: pre
50-
* Inline: b, i, strong, em, tt, code, ins, del, sup, sub, kbd, samp, q, var
51-
* Lists: ol, ul, li, dl, dt, dd
52-
* Tables: table, thead, tbody, tfoot, tr, td, th
53-
* Breaks: br, hr
54-
* Ruby (East Asian): ruby, rt, rp
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`
5562

5663
The following attributes, organized by element, are whitelisted:
5764

58-
* a: href (http://, https://, mailto://, github-windows:// and github-mac:// URI schemes and relative paths only)
59-
* img: src (http:// and https:// URI schemes and relative paths only)
60-
* div: itemscope, itemtype
61-
* 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
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`
6271

63-
Note that the id attribute is *not* whitelisted.
64-
65-
Contributing
66-
------------
67-
68-
See [Contributing](CONTRIBUTING.md)
72+
Note that the `id` attribute is *not* whitelisted.

lib/github/commands/rest2html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ SETTINGS = {
5757
'initial_header_level': 2,
5858
'report_level': 5,
5959
'syntax_highlight' : 'none',
60-
'math_output' : 'latex'
60+
'math_output' : 'latex',
61+
'field_name_limit': 50,
6162
}
6263

6364
class GitHubHTMLTranslator(HTMLTranslator):

lib/github/markup/command_implementation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def call_block(rendered, content)
3535
def execute(command, target)
3636
spawn = POSIX::Spawn::Child.new(*command, :input => target)
3737
if spawn.status.success?
38-
spawn.out.gsub("\r", '')
38+
spawn.out.gsub("\r", '').force_encoding(target.encoding)
3939
else
4040
raise CommandError.new(spawn.err.strip)
4141
end

lib/github/markup/markdown.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Markdown < Implementation
2525
}
2626

2727
def initialize
28-
super(/md|mkdn?|mdwn|mdown|markdown|litcoffee/)
28+
super(/md|rmd|mkdn?|mdwn|mdown|markdown|litcoffee/i)
2929
end
3030

3131
def load

lib/github/markups.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "github/markup/markdown"
2+
require "shellwords"
23

34
markups << GitHub::Markup::Markdown.new
45

@@ -29,7 +30,7 @@
2930
Asciidoctor.render(content, :safe => :secure, :attributes => %w(showtitle idprefix idseparator=- env=github env-github source-highlighter=html-pipeline))
3031
end
3132

32-
command("python2 -S #{File.dirname(__FILE__)}/commands/rest2html", /re?st(\.txt)?/)
33+
command("python2 -S #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html", /re?st(\.txt)?/)
3334

3435
# pod2html is nice enough to generate a full-on HTML document for us,
3536
# so we return the favor by ripping out the good parts.

test/markup_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# encoding: UTF-8
2+
13
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
24

35
require 'github/markup'
@@ -35,6 +37,8 @@ class MarkupTest < Test::Unit::TestCase
3537
def test_knows_what_it_can_and_cannot_render
3638
assert_equal false, GitHub::Markup.can_render?('README.html')
3739
assert_equal true, GitHub::Markup.can_render?('README.markdown')
40+
assert_equal true, GitHub::Markup.can_render?('README.rmd')
41+
assert_equal true, GitHub::Markup.can_render?('README.Rmd')
3842
assert_equal false, GitHub::Markup.can_render?('README.cmd')
3943
assert_equal true, GitHub::Markup.can_render?('README.litcoffee')
4044
end
@@ -50,4 +54,9 @@ def test_raises_error_if_command_exits_non_zero
5054
fail "an exception was expected but was not raised"
5155
end
5256
end
57+
58+
def test_preserve_markup
59+
content = "Noël"
60+
assert_equal content.encoding.name, GitHub::Markup.render('Foo.rst', content).encoding.name
61+
end
5362
end

test/markups/README.rmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Title
2+
* One
3+
* Two

test/markups/README.rmd.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Title</h1>
2+
3+
<ul>
4+
<li>One</li>
5+
<li>Two</li>
6+
</ul>

test/markups/README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ Source https://github.com/tony/pullv
4646

4747
.. image:: https://scan.coverity.com/projects/621/badge.svg
4848
:alt: Coverity Scan Build Status
49+
50+
Field list
51+
----------
52+
53+
:123456789 123456789 123456789 123456789 123456789 1: Uh-oh! This name is too long!
54+
:123456789 123456789 123456789 123456789 1234567890: this is a long name,
55+
but no problem!
56+
:123456789 12345: this is not so long, but long enough for the default!
57+
:123456789 1234: this should work even with the default :)

test/markups/README.rst.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ <h2 class="subtitle" id="subtitle">Subtitle</h2>
55
<p class="topic-title first">Table of Contents</p>
66
<ul class="simple">
77
<li><a class="reference internal" href="#header-2" id="id1">Header 2</a></li>
8+
<li><a class="reference internal" href="#field-list" id="id2">Field list</a></li>
89
</ul>
910
</div>
1011
<h2><a class="toc-backref" href="#id1">Header 2</a></h2>
@@ -40,3 +41,21 @@ <h2><a class="toc-backref" href="#id1">Header 2</a></h2>
4041
<a class="reference external image-reference" href="https://scan.coverity.com/projects/621"><img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/621/badge.svg">
4142
</a>
4243
<img alt="Coverity Scan Build Status" src="https://scan.coverity.com/projects/621/badge.svg">
44+
<h2><a class="toc-backref" href="#id2">Field list</a></h2>
45+
<table class="docutils field-list" frame="void" rules="none">
46+
<col class="field-name" />
47+
<col class="field-body" />
48+
<tbody valign="top">
49+
<tr class="field"><th class="field-name" colspan="2">123456789 123456789 123456789 123456789 123456789 1:</th></tr>
50+
<tr class="field"><td>&nbsp;</td><td class="field-body">Uh-oh! This name is too long!</td>
51+
</tr>
52+
<tr class="field"><th class="field-name">123456789 123456789 123456789 123456789 1234567890:</th><td class="field-body">this is a long name,
53+
but no problem!</td>
54+
</tr>
55+
<tr class="field"><th class="field-name">123456789 12345:</th><td class="field-body">this is not so long, but long enough for the default!</td>
56+
</tr>
57+
<tr class="field"><th class="field-name">123456789 1234:</th><td class="field-body">this should work even with the default :)</td>
58+
</tr>
59+
</tbody>
60+
</table>
61+

0 commit comments

Comments
 (0)