github-markup 1.4.4 → 1.4.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +5 -1
- data/Gemfile +2 -1
- data/README.md +20 -6
- data/bin/github-markup +23 -5
- data/lib/github-markup.rb +1 -1
- data/lib/github/commands/pod2html +15 -0
- data/lib/github/commands/rest2html +88 -8
- data/lib/github/markup.rb +53 -12
- data/lib/github/markup/command_implementation.rb +3 -2
- data/lib/github/markup/gem_implementation.rb +2 -2
- data/lib/github/markup/implementation.rb +5 -10
- data/lib/github/markup/markdown.rb +1 -1
- data/lib/github/markup/rdoc.rb +1 -1
- data/lib/github/markups.rb +11 -18
- data/test/markup_test.rb +23 -19
- data/test/markups/README.directives.rst +103 -0
- data/test/markups/README.directives.rst.html +74 -0
- data/test/markups/README.pod +4 -4
- data/test/markups/README.pod.html +41 -53
- data/test/markups/README.rst +3 -0
- data/test/markups/README.rst.html +4 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e03f4fced75d3a7c35f4cffd733122b04c48f10
|
4
|
+
data.tar.gz: 97ebb3c12cd2a27ad1cd89aadb87f01b2104776a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de17c773fbdac007a4bbddffc9751956ce4438ecac99e3bdad17bfec7190b3f988c800537fe98156d291dd1935893b73bf7c0f24b9caadf0ad11caac004dc9ab
|
7
|
+
data.tar.gz: 12fa22759e16ad09e1d98b72019e745635aeb82b2f61cd06896ec1f763b56b8068d6750c4d01dae6a19f52e162b7866a7f8b5bceefbf235aad6d271e795acb79
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -9,7 +9,11 @@ notifications:
|
|
9
9
|
email: false
|
10
10
|
git:
|
11
11
|
depth: 10
|
12
|
-
before_install:
|
12
|
+
before_install:
|
13
|
+
- sudo apt-get install perl
|
14
|
+
- curl -L http://cpanmin.us | perl - --sudo App::cpanminus
|
15
|
+
- sudo cpanm --installdeps --notest Pod::Simple
|
16
|
+
- sudo pip install docutils
|
13
17
|
cache:
|
14
18
|
- bundler
|
15
19
|
- pip
|
data/Gemfile
CHANGED
@@ -8,7 +8,8 @@ gem "RedCloth"
|
|
8
8
|
gem "rdoc", "~>3.6"
|
9
9
|
gem "org-ruby", "= 0.9.9"
|
10
10
|
gem "creole", "~>0.3.6"
|
11
|
-
gem "wikicloth", "=0.8.
|
11
|
+
gem "wikicloth", "=0.8.3"
|
12
12
|
gem "asciidoctor", "= 1.5.2"
|
13
13
|
gem "rake"
|
14
14
|
gem "rinku", '~> 1'
|
15
|
+
gem "github-linguist", ">= 5.0.7"
|
data/README.md
CHANGED
@@ -19,14 +19,15 @@ you wish to run the library. You can also run `script/bootstrap` to fetch them a
|
|
19
19
|
|
20
20
|
* [.markdown, .mdown, .mkdn, .md](http://daringfireball.net/projects/markdown/) -- `gem install redcarpet` (https://github.com/vmg/redcarpet)
|
21
21
|
* [.textile](http://www.textism.com/tools/textile/) -- `gem install RedCloth`
|
22
|
-
* [.rdoc](
|
22
|
+
* [.rdoc](https://rdoc.github.io/rdoc/) -- `gem install rdoc -v 3.6.1`
|
23
23
|
* [.org](http://orgmode.org/) -- `gem install org-ruby`
|
24
24
|
* [.creole](http://wikicreole.org/) -- `gem install creole`
|
25
25
|
* [.mediawiki, .wiki](http://www.mediawiki.org/wiki/Help:Formatting) -- `gem install wikicloth`
|
26
|
-
* [.rst](http://docutils.sourceforge.net/rst.html) -- `
|
26
|
+
* [.rst](http://docutils.sourceforge.net/rst.html) -- `python3 -m pip install sphinx`
|
27
27
|
* [.asciidoc, .adoc, .asc](http://asciidoc.org/) -- `gem install asciidoctor` (http://asciidoctor.org)
|
28
|
-
* [.pod](http://search.cpan.org/dist/perl/pod/perlpod.pod) -- `Pod::Simple::
|
29
|
-
comes with Perl >= 5.10. Lower versions should install
|
28
|
+
* [.pod](http://search.cpan.org/dist/perl/pod/perlpod.pod) -- `Pod::Simple::XHTML`
|
29
|
+
comes with Perl >= 5.10. Lower versions should install Pod::Simple from CPAN.
|
30
|
+
|
30
31
|
|
31
32
|
Installation
|
32
33
|
-----------
|
@@ -38,18 +39,31 @@ gem install github-markup
|
|
38
39
|
Usage
|
39
40
|
-----
|
40
41
|
|
42
|
+
Basic form:
|
43
|
+
|
41
44
|
```ruby
|
42
45
|
require 'github/markup'
|
43
|
-
|
46
|
+
|
47
|
+
GitHub::Markup.render('README.markdown', '* One\n* Two')
|
44
48
|
```
|
45
49
|
|
46
|
-
|
50
|
+
More realistic form:
|
47
51
|
|
48
52
|
```ruby
|
49
53
|
require 'github/markup'
|
54
|
+
|
50
55
|
GitHub::Markup.render(file, File.read(file))
|
51
56
|
```
|
52
57
|
|
58
|
+
And a convenience form:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
require 'github/markup'
|
62
|
+
|
63
|
+
GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, '* One\n* Two')
|
64
|
+
```
|
65
|
+
|
66
|
+
|
53
67
|
Contributing
|
54
68
|
------------
|
55
69
|
|
data/bin/github-markup
CHANGED
@@ -1,10 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + "/../lib"
|
3
|
+
$LOAD_PATH.unshift File.dirname(File.realpath(__FILE__)) + "/../lib"
|
4
4
|
require 'github/markup'
|
5
5
|
|
6
|
-
if ARGV
|
7
|
-
|
8
|
-
|
9
|
-
puts "usage: #$0 FILE"
|
6
|
+
if ARGV.size < 1
|
7
|
+
print "usage: #$0 FILE [ FILES ... ]\n"
|
8
|
+
exit 1
|
10
9
|
end
|
10
|
+
|
11
|
+
sources = []
|
12
|
+
|
13
|
+
ARGV.each { |s|
|
14
|
+
begin
|
15
|
+
file = File.open( s, "r" )
|
16
|
+
sources.push [ s, file ]
|
17
|
+
rescue Exception => e
|
18
|
+
$stderr.print "error: #{e.message}\n"
|
19
|
+
exit 1
|
20
|
+
ensure
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
sources.each { |name, file|
|
25
|
+
print GitHub::Markup.render( name, file.read )
|
26
|
+
file.close
|
27
|
+
}
|
28
|
+
|
data/lib/github-markup.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env perl
|
2
|
+
|
3
|
+
use strict;
|
4
|
+
use Pod::Simple::XHTML 3.11;
|
5
|
+
|
6
|
+
my $p = Pod::Simple::XHTML->new;
|
7
|
+
$p->html_header('');
|
8
|
+
$p->html_footer('');
|
9
|
+
$p->perldoc_url_prefix('http://metacpan.org/search?q=');
|
10
|
+
$p->strip_verbatim_indent(sub {
|
11
|
+
my $lines = shift;
|
12
|
+
(my $indent = $lines->[0]) =~ s/\S.*//;
|
13
|
+
return $indent;
|
14
|
+
});
|
15
|
+
$p->parse_from_file(shift);
|
@@ -31,9 +31,11 @@ import sys
|
|
31
31
|
import os
|
32
32
|
|
33
33
|
# This fixes docutils failing with unicode parameters to CSV-Table. The -S
|
34
|
-
# switch and the following
|
35
|
-
|
36
|
-
sys
|
34
|
+
# switch and the following 3 lines can be removed after upgrading to python 3.
|
35
|
+
if sys.version_info[0] < 3:
|
36
|
+
reload(sys)
|
37
|
+
sys.setdefaultencoding('utf-8')
|
38
|
+
|
37
39
|
import site
|
38
40
|
|
39
41
|
try:
|
@@ -43,12 +45,80 @@ except:
|
|
43
45
|
pass
|
44
46
|
|
45
47
|
import codecs
|
48
|
+
import io
|
46
49
|
|
47
50
|
from docutils import nodes
|
48
51
|
from docutils.parsers.rst import directives, roles
|
49
52
|
from docutils.parsers.rst.directives.body import CodeBlock
|
50
53
|
from docutils.core import publish_parts
|
51
54
|
from docutils.writers.html4css1 import Writer, HTMLTranslator
|
55
|
+
from docutils.parsers.rst.states import Body
|
56
|
+
from docutils import nodes
|
57
|
+
|
58
|
+
# By default, docutils provides two choices for unknown directives:
|
59
|
+
# - Show errors if the reporting level is high enough
|
60
|
+
# - Silently do not display them otherwise
|
61
|
+
# Comments are not displayed, either.
|
62
|
+
|
63
|
+
# This code monkey-patches docutils to show preformatted lines
|
64
|
+
# in both these cases.
|
65
|
+
|
66
|
+
# Recommended practice for repositories with rst files:
|
67
|
+
# - If github is the preferred viewer for the rst files (e.g. README.rst),
|
68
|
+
# then design the files to properly display for github. E.g., do not
|
69
|
+
# include unknown directives or restructuredText comments.
|
70
|
+
# - If github is NOT the preferred viewer for the rst files (e.g.
|
71
|
+
# the files are designed to be used with sphinx extensions at readthedocs)
|
72
|
+
# then include a restructuredText comment at the top of the file
|
73
|
+
# explaining that the document will display much more nicely with its
|
74
|
+
# preferred viewer, e.g. at readthedocs.
|
75
|
+
|
76
|
+
original_behavior = False # Documents original docutils behavior
|
77
|
+
github_display = True
|
78
|
+
|
79
|
+
def unknown_directive(self, type_name):
|
80
|
+
lineno = self.state_machine.abs_line_number()
|
81
|
+
indented, indent, offset, blank_finish = \
|
82
|
+
self.state_machine.get_first_known_indented(0, strip_indent=False)
|
83
|
+
text = '\n'.join(indented)
|
84
|
+
if original_behavior:
|
85
|
+
error = self.reporter.error(
|
86
|
+
'Unknown directive type "%s".' % type_name,
|
87
|
+
nodes.literal_block(text, text), line=lineno)
|
88
|
+
return [error], blank_finish
|
89
|
+
elif github_display:
|
90
|
+
cls = ['unknown_directive']
|
91
|
+
result = [nodes.literal_block(text, text, classes=cls)]
|
92
|
+
return result, blank_finish
|
93
|
+
else:
|
94
|
+
return [nodes.comment(text, text)], blank_finish
|
95
|
+
|
96
|
+
def comment(self, match):
|
97
|
+
if not match.string[match.end():].strip() \
|
98
|
+
and self.state_machine.is_next_line_blank(): # an empty comment?
|
99
|
+
return [nodes.comment()], 1 # "A tiny but practical wart."
|
100
|
+
indented, indent, offset, blank_finish = \
|
101
|
+
self.state_machine.get_first_known_indented(match.end())
|
102
|
+
while indented and not indented[-1].strip():
|
103
|
+
indented.trim_end()
|
104
|
+
if not original_behavior:
|
105
|
+
firstline = ''.join(indented[:1]).split()
|
106
|
+
if ' '.join(firstline[:2]) == 'github display':
|
107
|
+
if len(firstline) == 3 and firstline[2] in ('on', 'off'):
|
108
|
+
global github_display
|
109
|
+
github_display = firstline[2] == 'on'
|
110
|
+
if len(indented) == 1:
|
111
|
+
return [nodes.comment()], 1
|
112
|
+
text = '\n'.join(indented[1:])
|
113
|
+
cls = ['github_comment']
|
114
|
+
result = [nodes.literal_block(text, text, classes=cls)]
|
115
|
+
return result, blank_finish
|
116
|
+
text = '\n'.join(indented)
|
117
|
+
return [nodes.comment(text, text)], blank_finish
|
118
|
+
|
119
|
+
Body.comment = comment
|
120
|
+
Body.unknown_directive = unknown_directive
|
121
|
+
|
52
122
|
|
53
123
|
SETTINGS = {
|
54
124
|
'cloak_email_addresses': False,
|
@@ -56,7 +126,6 @@ SETTINGS = {
|
|
56
126
|
'raw_enabled': True,
|
57
127
|
'strip_comments': True,
|
58
128
|
'doctitle_xform': True,
|
59
|
-
'sectsubtitle_xform': True,
|
60
129
|
'initial_header_level': 2,
|
61
130
|
'report_level': 5,
|
62
131
|
'syntax_highlight': 'none',
|
@@ -105,6 +174,9 @@ class GitHubHTMLTranslator(HTMLTranslator):
|
|
105
174
|
else:
|
106
175
|
self.body.append(self.starttag(node, 'pre'))
|
107
176
|
|
177
|
+
def visit_doctest_block(self, node):
|
178
|
+
self.body.append(self.starttag(node, 'pre', lang='pycon'))
|
179
|
+
|
108
180
|
# always wrap two-backtick rst inline literals in <code>, not <tt>
|
109
181
|
# this also avoids the generation of superfluous <span> tags
|
110
182
|
def visit_literal(self, node):
|
@@ -139,9 +211,9 @@ class GitHubHTMLTranslator(HTMLTranslator):
|
|
139
211
|
|
140
212
|
# toss off `object` tag
|
141
213
|
self.body.pop()
|
142
|
-
|
214
|
+
# add on `img` with attributes
|
143
215
|
self.body.append(self.starttag(node, 'img', **atts))
|
144
|
-
|
216
|
+
HTMLTranslator.depart_image(self, node)
|
145
217
|
|
146
218
|
|
147
219
|
def kbd(name, rawtext, text, lineno, inliner, options=None, content=None):
|
@@ -162,7 +234,11 @@ def main():
|
|
162
234
|
except IOError: # given filename could not be found
|
163
235
|
return ''
|
164
236
|
except IndexError: # no filename given
|
165
|
-
|
237
|
+
if sys.version_info[0] < 3: # python 2.x
|
238
|
+
text = sys.stdin.read()
|
239
|
+
else: # python 3
|
240
|
+
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
|
241
|
+
text = input_stream.read()
|
166
242
|
|
167
243
|
writer = Writer()
|
168
244
|
writer.translator_class = GitHubHTMLTranslator
|
@@ -185,5 +261,9 @@ def main():
|
|
185
261
|
return ''
|
186
262
|
|
187
263
|
if __name__ == '__main__':
|
188
|
-
sys.
|
264
|
+
if sys.version_info[0] < 3: # python 2.x
|
265
|
+
sys.stdout.write("%s%s" % (main(), "\n"))
|
266
|
+
else: # python 3
|
267
|
+
output_stream = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
268
|
+
output_stream.write("%s%s" % (main(), "\n"))
|
189
269
|
sys.stdout.flush()
|
data/lib/github/markup.rb
CHANGED
@@ -2,16 +2,34 @@ require "github/markup/command_implementation"
|
|
2
2
|
require "github/markup/gem_implementation"
|
3
3
|
|
4
4
|
module GitHub
|
5
|
+
module Markups
|
6
|
+
# all of supported markups:
|
7
|
+
MARKUP_ASCIIDOC = :asciidoc
|
8
|
+
MARKUP_CREOLE = :creole
|
9
|
+
MARKUP_MARKDOWN = :markdown
|
10
|
+
MARKUP_MEDIAWIKI = :mediawiki
|
11
|
+
MARKUP_ORG = :org
|
12
|
+
MARKUP_POD = :pod
|
13
|
+
MARKUP_RDOC = :rdoc
|
14
|
+
MARKUP_RST = :rst
|
15
|
+
MARKUP_TEXTILE = :textile
|
16
|
+
end
|
17
|
+
|
5
18
|
module Markup
|
6
19
|
extend self
|
7
|
-
|
20
|
+
|
21
|
+
@@markups = {}
|
8
22
|
|
9
23
|
def markups
|
10
24
|
@@markups
|
11
25
|
end
|
26
|
+
|
27
|
+
def markup_impls
|
28
|
+
markups.values
|
29
|
+
end
|
12
30
|
|
13
31
|
def preload!
|
14
|
-
|
32
|
+
markup_impls.each do |markup|
|
15
33
|
markup.load
|
16
34
|
end
|
17
35
|
end
|
@@ -19,35 +37,58 @@ module GitHub
|
|
19
37
|
def render(filename, content = nil)
|
20
38
|
content ||= File.read(filename)
|
21
39
|
|
22
|
-
if impl = renderer(filename)
|
40
|
+
if impl = renderer(filename, content)
|
23
41
|
impl.render(content)
|
24
42
|
else
|
25
43
|
content
|
26
44
|
end
|
27
45
|
end
|
46
|
+
|
47
|
+
def render_s(symbol, content)
|
48
|
+
if content.nil?
|
49
|
+
raise ArgumentError, 'Can not render a nil.'
|
50
|
+
elsif markups.has_key?(symbol)
|
51
|
+
markups[symbol].render(content)
|
52
|
+
else
|
53
|
+
content
|
54
|
+
end
|
55
|
+
end
|
28
56
|
|
29
|
-
def markup(
|
30
|
-
|
57
|
+
def markup(symbol, gem_name, pattern, opts = {}, &block)
|
58
|
+
markup_impl(symbol, GemImplementation.new(pattern, gem_name, &block))
|
59
|
+
end
|
60
|
+
|
61
|
+
def markup_impl(symbol, impl)
|
62
|
+
if markups.has_key?(symbol)
|
63
|
+
raise ArgumentError, "The '#{symbol}' symbol is already defined."
|
64
|
+
end
|
65
|
+
markups[symbol] = impl
|
31
66
|
end
|
32
67
|
|
33
|
-
def command(command,
|
68
|
+
def command(symbol, command, languages, name, &block)
|
34
69
|
if File.exist?(file = File.dirname(__FILE__) + "/commands/#{command}")
|
35
70
|
command = file
|
36
71
|
end
|
37
72
|
|
38
|
-
|
73
|
+
markup_impl(symbol, CommandImplementation.new(languages, command, name, &block))
|
39
74
|
end
|
40
75
|
|
41
|
-
def can_render?(filename)
|
42
|
-
!!renderer(filename)
|
76
|
+
def can_render?(filename, content)
|
77
|
+
!!renderer(filename, content)
|
43
78
|
end
|
44
79
|
|
45
|
-
def renderer(filename)
|
46
|
-
|
47
|
-
|
80
|
+
def renderer(filename, content)
|
81
|
+
language = language(filename, content)
|
82
|
+
markup_impls.find { |impl|
|
83
|
+
impl.match?(language)
|
48
84
|
}
|
49
85
|
end
|
50
86
|
|
87
|
+
def language(filename, content)
|
88
|
+
blob = Linguist::Blob.new(filename, content)
|
89
|
+
return Linguist.detect(blob, allow_empty: true)
|
90
|
+
end
|
91
|
+
|
51
92
|
# Define markups
|
52
93
|
markups_rb = File.dirname(__FILE__) + '/markups.rb'
|
53
94
|
instance_eval File.read(markups_rb), markups_rb
|
@@ -6,6 +6,7 @@ end
|
|
6
6
|
|
7
7
|
require "github/markup/implementation"
|
8
8
|
|
9
|
+
|
9
10
|
module GitHub
|
10
11
|
module Markup
|
11
12
|
class CommandError < RuntimeError
|
@@ -14,8 +15,8 @@ module GitHub
|
|
14
15
|
class CommandImplementation < Implementation
|
15
16
|
attr_reader :command, :block, :name
|
16
17
|
|
17
|
-
def initialize(
|
18
|
-
super
|
18
|
+
def initialize(languages, command, name, &block)
|
19
|
+
super languages
|
19
20
|
@command = command.to_s
|
20
21
|
@block = block
|
21
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(languages, gem_name, &renderer)
|
9
|
+
super languages
|
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 :languages
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@
|
6
|
+
def initialize(languages)
|
7
|
+
@languages = languages
|
8
8
|
end
|
9
9
|
|
10
10
|
def load
|
@@ -15,13 +15,8 @@ module GitHub
|
|
15
15
|
raise NotImplementedError, "subclasses of GitHub::Markup::Implementation must define #render"
|
16
16
|
end
|
17
17
|
|
18
|
-
def match?(
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
def file_ext_regexp
|
24
|
-
@file_ext_regexp ||= /\.(#{regexp})\z/
|
18
|
+
def match?(language)
|
19
|
+
languages.include? language
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
data/lib/github/markup/rdoc.rb
CHANGED
data/lib/github/markups.rb
CHANGED
@@ -1,50 +1,43 @@
|
|
1
1
|
require "github/markup/markdown"
|
2
2
|
require "github/markup/rdoc"
|
3
3
|
require "shellwords"
|
4
|
+
require "linguist"
|
4
5
|
|
5
|
-
|
6
|
+
markup_impl(::GitHub::Markups::MARKUP_MARKDOWN, ::GitHub::Markup::Markdown.new)
|
6
7
|
|
7
|
-
markup(:redcloth,
|
8
|
+
markup(::GitHub::Markups::MARKUP_TEXTILE, :redcloth, [Linguist::Language["Textile"]]) do |content|
|
8
9
|
RedCloth.new(content).to_html
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
+
markup_impl(::GitHub::Markups::MARKUP_RDOC, GitHub::Markup::RDoc.new)
|
12
13
|
|
13
|
-
markup('org-ruby',
|
14
|
+
markup(::GitHub::Markups::MARKUP_ORG, 'org-ruby', [Linguist::Language["Org"]]) do |content|
|
14
15
|
Orgmode::Parser.new(content, {
|
15
16
|
:allow_include_files => false,
|
16
17
|
:skip_syntax_highlight => true
|
17
18
|
}).to_html
|
18
19
|
end
|
19
20
|
|
20
|
-
markup(:creole,
|
21
|
+
markup(::GitHub::Markups::MARKUP_CREOLE, :creole, [Linguist::Language["Creole"]]) do |content|
|
21
22
|
Creole.creolize(content)
|
22
23
|
end
|
23
24
|
|
24
|
-
markup(:wikicloth,
|
25
|
+
markup(::GitHub::Markups::MARKUP_MEDIAWIKI, :wikicloth, [Linguist::Language["MediaWiki"]]) do |content|
|
25
26
|
wikicloth = WikiCloth::WikiCloth.new(:data => content)
|
26
27
|
WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS << 'tt' unless WikiCloth::WikiBuffer::HTMLElement::ESCAPED_TAGS.include?('tt')
|
27
28
|
wikicloth.to_html(:noedit => true)
|
28
29
|
end
|
29
30
|
|
30
|
-
markup(:asciidoctor,
|
31
|
+
markup(::GitHub::Markups::MARKUP_ASCIIDOC, :asciidoctor, [Linguist::Language["AsciiDoc"]]) do |content|
|
31
32
|
Asciidoctor::Compliance.unique_id_start_index = 1
|
32
33
|
Asciidoctor.convert(content, :safe => :secure, :attributes => %w(showtitle=@ idprefix idseparator=- env=github env-github source-highlighter=html-pipeline))
|
33
34
|
end
|
34
35
|
|
35
36
|
command(
|
37
|
+
::GitHub::Markups::MARKUP_RST,
|
36
38
|
"python2 -S #{Shellwords.escape(File.dirname(__FILE__))}/commands/rest2html",
|
37
|
-
|
39
|
+
[Linguist::Language["reStructuredText"]],
|
38
40
|
"restructuredtext"
|
39
41
|
)
|
40
42
|
|
41
|
-
|
42
|
-
# so we return the favor by ripping out the good parts.
|
43
|
-
#
|
44
|
-
# Any block passed to `command` will be handed the command's STDOUT for
|
45
|
-
# post processing.
|
46
|
-
command('/usr/bin/env perl -MPod::Simple::HTML -e Pod::Simple::HTML::go', /pod/, "pod") do |rendered|
|
47
|
-
if rendered =~ /<!-- start doc -->\s*(.+)\s*<!-- end doc -->/mi
|
48
|
-
$1
|
49
|
-
end
|
50
|
-
end
|
43
|
+
command(::GitHub::Markups::MARKUP_POD, :pod2html, [Linguist::Language["Pod"]], "pod")
|
data/test/markup_test.rb
CHANGED
@@ -75,33 +75,37 @@ class MarkupTest < Minitest::Test
|
|
75
75
|
message
|
76
76
|
end
|
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', '<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')
|
86
86
|
end
|
87
87
|
|
88
88
|
def test_each_render_has_a_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
|
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
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_rendering_by_symbol
|
101
|
+
assert_equal '<p><code>test</code></p>', GitHub::Markup.render_s(GitHub::Markups::MARKUP_MARKDOWN, '`test`').strip
|
98
102
|
end
|
99
103
|
|
100
104
|
def test_raises_error_if_command_exits_non_zero
|
101
|
-
GitHub::Markup.command('test/fixtures/fail.sh',
|
102
|
-
assert GitHub::Markup.can_render?('README.
|
105
|
+
GitHub::Markup.command(:doesntmatter, 'test/fixtures/fail.sh', [Linguist::Language['Java']], 'fail')
|
106
|
+
assert GitHub::Markup.can_render?('README.java', 'stop swallowing errors')
|
103
107
|
begin
|
104
|
-
GitHub::Markup.render('README.
|
108
|
+
GitHub::Markup.render('README.java', "stop swallowing errors")
|
105
109
|
rescue GitHub::Markup::CommandError => e
|
106
110
|
assert_equal "failure message", e.message
|
107
111
|
else
|
@@ -0,0 +1,103 @@
|
|
1
|
+
==================================================
|
2
|
+
restructuredText (rst) directives and comments
|
3
|
+
==================================================
|
4
|
+
|
5
|
+
Introduction
|
6
|
+
=================
|
7
|
+
|
8
|
+
An rst directive starts with two periods, and has a keyword
|
9
|
+
followed by two colons, like this::
|
10
|
+
|
11
|
+
.. MyDirective::
|
12
|
+
|
13
|
+
The rst parser is quite flexible and configurable. Directives
|
14
|
+
may be added for specialized operations. Sphinx is a system
|
15
|
+
that was designed for writing documentation, and, for example,
|
16
|
+
readthedocs.org uses sphinx.
|
17
|
+
|
18
|
+
Display of rst files at github needs to cover two distinct
|
19
|
+
use-cases:
|
20
|
+
|
21
|
+
- The github display is the primary method for displaying
|
22
|
+
the file (e.g. for README.rst files)
|
23
|
+
|
24
|
+
- The github display is incidental to the primary method
|
25
|
+
for displaying the file (e.g. for readthedocs documentation)
|
26
|
+
|
27
|
+
Currently, github handles the first case fine, but could
|
28
|
+
confuse viewers for the second case, because sometimes
|
29
|
+
content is missing from the github display.
|
30
|
+
|
31
|
+
It would seem that one possibility for distinguishing these
|
32
|
+
two cases is to add a github directive to control the display.
|
33
|
+
|
34
|
+
Unfortunately, this would place a burden on every other rst
|
35
|
+
parser to ignore the github directive (some of them will error
|
36
|
+
on unknown directives).
|
37
|
+
|
38
|
+
Instead, we can assign semantic content to specific comments.
|
39
|
+
|
40
|
+
This is a fairly ugly hack, but it has the benefit of not
|
41
|
+
requiring any document changes that would create problems with
|
42
|
+
any conformant parser.
|
43
|
+
|
44
|
+
|
45
|
+
The proposed special comment is::
|
46
|
+
|
47
|
+
.. github display [on | off]
|
48
|
+
|
49
|
+
|
50
|
+
If you pass this the "on" value, then all unknown directives
|
51
|
+
will be displayed as literal code blocks. If you pass this
|
52
|
+
the "off" value, then unknown directives will not be displayed.
|
53
|
+
|
54
|
+
In addition to controlling the display of literal code blocks,
|
55
|
+
this also allows you to show comments specifically for github.
|
56
|
+
|
57
|
+
For example, somebody could place this at the top of their file::
|
58
|
+
|
59
|
+
.. github display
|
60
|
+
|
61
|
+
This file was designed to be viewed at readthedocs. Some
|
62
|
+
content will not display properly when viewing using the
|
63
|
+
github browser.
|
64
|
+
|
65
|
+
Tests
|
66
|
+
==========
|
67
|
+
|
68
|
+
By default, unknown directives should be displayed.
|
69
|
+
|
70
|
+
.. UnknownDirective:: This is an unknown directive
|
71
|
+
|
72
|
+
it has a lot of stuff underneath it
|
73
|
+
|
74
|
+
But we can turn this off, and the next directive should
|
75
|
+
not be displayed.
|
76
|
+
|
77
|
+
.. github display off
|
78
|
+
|
79
|
+
.. UnknownDirective:: This is an unknown directive
|
80
|
+
|
81
|
+
it has a lot of stuff underneath it
|
82
|
+
|
83
|
+
Or we can turn it back on...
|
84
|
+
|
85
|
+
.. github display on
|
86
|
+
|
87
|
+
.. UnknownDirective:: This is an unknown directive (3)
|
88
|
+
|
89
|
+
it has a lot of stuff underneath it
|
90
|
+
|
91
|
+
Here is a comment that should display at github
|
92
|
+
|
93
|
+
.. github display
|
94
|
+
|
95
|
+
YOU SHOULD SEE THIS!
|
96
|
+
|
97
|
+
And here is a comment that should not display at github
|
98
|
+
|
99
|
+
.. foobar
|
100
|
+
|
101
|
+
YOU SHOULD NOT SEE THIS!
|
102
|
+
|
103
|
+
This concludes the tests.
|
@@ -0,0 +1,74 @@
|
|
1
|
+
<h1>restructuredText (rst) directives and comments</h1>
|
2
|
+
<a name="introduction"></a>
|
3
|
+
<h2>Introduction</h2>
|
4
|
+
<p>An rst directive starts with two periods, and has a keyword
|
5
|
+
followed by two colons, like this:</p>
|
6
|
+
<pre>
|
7
|
+
.. MyDirective::
|
8
|
+
</pre>
|
9
|
+
<p>The rst parser is quite flexible and configurable. Directives
|
10
|
+
may be added for specialized operations. Sphinx is a system
|
11
|
+
that was designed for writing documentation, and, for example,
|
12
|
+
readthedocs.org uses sphinx.</p>
|
13
|
+
<p>Display of rst files at github needs to cover two distinct
|
14
|
+
use-cases:</p>
|
15
|
+
<ul>
|
16
|
+
<li>The github display is the primary method for displaying
|
17
|
+
the file (e.g. for README.rst files)</li>
|
18
|
+
<li>The github display is incidental to the primary method
|
19
|
+
for displaying the file (e.g. for readthedocs documentation)</li>
|
20
|
+
</ul>
|
21
|
+
<p>Currently, github handles the first case fine, but could
|
22
|
+
confuse viewers for the second case, because sometimes
|
23
|
+
content is missing from the github display.</p>
|
24
|
+
<p>It would seem that one possibility for distinguishing these
|
25
|
+
two cases is to add a github directive to control the display.</p>
|
26
|
+
<p>Unfortunately, this would place a burden on every other rst
|
27
|
+
parser to ignore the github directive (some of them will error
|
28
|
+
on unknown directives).</p>
|
29
|
+
<p>Instead, we can assign semantic content to specific comments.</p>
|
30
|
+
<p>This is a fairly ugly hack, but it has the benefit of not
|
31
|
+
requiring any document changes that would create problems with
|
32
|
+
any conformant parser.</p>
|
33
|
+
<p>The proposed special comment is:</p>
|
34
|
+
<pre>
|
35
|
+
.. github display [on | off]
|
36
|
+
</pre>
|
37
|
+
<p>If you pass this the "on" value, then all unknown directives
|
38
|
+
will be displayed as literal code blocks. If you pass this
|
39
|
+
the "off" value, then unknown directives will not be displayed.</p>
|
40
|
+
<p>In addition to controlling the display of literal code blocks,
|
41
|
+
this also allows you to show comments specifically for github.</p>
|
42
|
+
<p>For example, somebody could place this at the top of their file:</p>
|
43
|
+
<pre>
|
44
|
+
.. github display
|
45
|
+
|
46
|
+
This file was designed to be viewed at readthedocs. Some
|
47
|
+
content will not display properly when viewing using the
|
48
|
+
github browser.
|
49
|
+
</pre>
|
50
|
+
<a name="tests"></a>
|
51
|
+
<h2>Tests</h2>
|
52
|
+
<p>By default, unknown directives should be displayed.</p>
|
53
|
+
<pre>
|
54
|
+
.. UnknownDirective:: This is an unknown directive
|
55
|
+
|
56
|
+
it has a lot of stuff underneath it
|
57
|
+
|
58
|
+
</pre>
|
59
|
+
<p>But we can turn this off, and the next directive should
|
60
|
+
not be displayed.</p>
|
61
|
+
<p>Or we can turn it back on...</p>
|
62
|
+
<pre>
|
63
|
+
.. UnknownDirective:: This is an unknown directive (3)
|
64
|
+
|
65
|
+
it has a lot of stuff underneath it
|
66
|
+
|
67
|
+
</pre>
|
68
|
+
<p>Here is a comment that should display at github</p>
|
69
|
+
<pre>
|
70
|
+
|
71
|
+
YOU SHOULD SEE THIS!
|
72
|
+
</pre>
|
73
|
+
<p>And here is a comment that should not display at github</p>
|
74
|
+
<p>This concludes the tests.</p>
|
data/test/markups/README.pod
CHANGED
@@ -12,7 +12,7 @@ Primary goals are:
|
|
12
12
|
|
13
13
|
=over 4
|
14
14
|
|
15
|
-
=item* Create a working compiler that understands the majority of the
|
15
|
+
=item * Create a working compiler that understands the majority of the
|
16
16
|
MATLAB/Octave programming language.
|
17
17
|
|
18
18
|
=back
|
@@ -23,14 +23,14 @@ This project is broken into three primary components:
|
|
23
23
|
|
24
24
|
=over 4
|
25
25
|
|
26
|
-
=item* The first is the parser, located in the C<src/parser/> directory. The
|
26
|
+
=item * The first is the parser, located in the C<src/parser/> directory. The
|
27
27
|
parser proper is composed of three source files, F<grammar.pg> which is a
|
28
28
|
Perl6Grammar file, and F<actions.pm> which is the associated actions file
|
29
29
|
written in NQP, and F<grammar-oper.pm> which is the operator precidence parser.
|
30
30
|
In addition, several helper functions used by the parser are located in
|
31
31
|
C<src/internals>.
|
32
32
|
|
33
|
-
=item* The second component is the library of builtin functions in the
|
33
|
+
=item * The second component is the library of builtin functions in the
|
34
34
|
C<src/builtins/> directory. These functions are, currently, written primarily in
|
35
35
|
PIR. Function names prefixed with an underscore are "private" functions for use
|
36
36
|
with the parser. Other functions should have names which are the same as names
|
@@ -38,7 +38,7 @@ for regular MATLAB or Octave functions, since they will be available to the
|
|
38
38
|
HLL. These are also separated into different namespaces depending on visibility
|
39
39
|
and utility.
|
40
40
|
|
41
|
-
=item* A number of library functions are written in M, or mostly M with some
|
41
|
+
=item * A number of library functions are written in M, or mostly M with some
|
42
42
|
inline PIR code in C<toolbox/>.
|
43
43
|
|
44
44
|
=back
|
@@ -1,84 +1,72 @@
|
|
1
|
-
<
|
1
|
+
<h1>Matrixy</h1>
|
2
2
|
|
3
|
-
<
|
3
|
+
<h2>INTRODUCTION</h2>
|
4
4
|
|
5
|
-
<
|
5
|
+
<p>This is a port of the MATLAB/Octave programming language to Parrot. See the ROADMAP file for more information on the status of this project, and what else needs to be done.</p>
|
6
6
|
|
7
|
-
<
|
8
|
-
See the ROADMAP file for more information on the status of this project,
|
9
|
-
and what else needs to be done.</p>
|
10
|
-
|
11
|
-
<h2><a href="#___top" title="click to go to top of document" name="ABOUT">ABOUT</a></h2>
|
7
|
+
<h2>ABOUT</h2>
|
12
8
|
|
13
9
|
<p>Primary goals are:</p>
|
14
10
|
|
15
|
-
<
|
16
|
-
|
17
|
-
|
11
|
+
<ul>
|
12
|
+
|
13
|
+
<li><p>Create a working compiler that understands the majority of the MATLAB/Octave programming language.</p>
|
18
14
|
|
19
|
-
|
15
|
+
</li>
|
16
|
+
</ul>
|
17
|
+
|
18
|
+
<h2>IMPLEMENTATION</h2>
|
20
19
|
|
21
20
|
<p>This project is broken into three primary components:</p>
|
22
21
|
|
23
|
-
<
|
24
|
-
|
25
|
-
located in the <code>src/parser/</code> directory.
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Function names prefixed with an underscore are "private" functions for use with the parser.
|
38
|
-
Other functions should have names which are the same as names for regular MATLAB or Octave functions,
|
39
|
-
since they will be available to the HLL.
|
40
|
-
These are also separated into different namespaces depending on visibility and utility.</p>
|
41
|
-
|
42
|
-
<p>=item* A number of library functions are written in M,
|
43
|
-
or mostly M with some inline PIR code in <code>toolbox/</code>.</p>
|
44
|
-
</blockquote>
|
45
|
-
|
46
|
-
<h2><a href="#___top" title="click to go to top of document" name="DEPENDENCIES">DEPENDENCIES</a></h2>
|
22
|
+
<ul>
|
23
|
+
|
24
|
+
<li><p>The first is the parser, located in the <code>src/parser/</code> directory. The parser proper is composed of three source files, <i>grammar.pg</i> which is a Perl6Grammar file, and <i>actions.pm</i> which is the associated actions file written in NQP, and <i>grammar-oper.pm</i> which is the operator precidence parser. In addition, several helper functions used by the parser are located in <code>src/internals</code>.</p>
|
25
|
+
|
26
|
+
</li>
|
27
|
+
<li><p>The second component is the library of builtin functions in the <code>src/builtins/</code> directory. These functions are, currently, written primarily in PIR. Function names prefixed with an underscore are "private" functions for use with the parser. Other functions should have names which are the same as names for regular MATLAB or Octave functions, since they will be available to the HLL. These are also separated into different namespaces depending on visibility and utility.</p>
|
28
|
+
|
29
|
+
</li>
|
30
|
+
<li><p>A number of library functions are written in M, or mostly M with some inline PIR code in <code>toolbox/</code>.</p>
|
31
|
+
|
32
|
+
</li>
|
33
|
+
</ul>
|
34
|
+
|
35
|
+
<h2>DEPENDENCIES</h2>
|
47
36
|
|
48
37
|
<p>Matrixy depends on these dependencies:</p>
|
49
38
|
|
50
|
-
<h3
|
39
|
+
<h3>Parrot</h3>
|
51
40
|
|
52
|
-
<p>To get a proper version of Parrot to build Matrixy,
|
53
|
-
you will need to check out and build Parrot from source:</p>
|
41
|
+
<p>To get a proper version of Parrot to build Matrixy, you will need to check out and build Parrot from source:</p>
|
54
42
|
|
55
|
-
<pre>
|
56
|
-
|
57
|
-
|
58
|
-
|
43
|
+
<pre><code>svn co http://svn.parrot.org/parrot/trunk parrot
|
44
|
+
cd parrot
|
45
|
+
perl Configure.pl
|
46
|
+
make && make test && make install-dev</code></pre>
|
59
47
|
|
60
|
-
<h3
|
48
|
+
<h3>Parrot-Linear-Algebra</h3>
|
61
49
|
|
62
50
|
<p>The linear algebra package for Parrot is available separately and provides functionality required by Matrixy. This includes matrix data types and matrix manipulation libraries</p>
|
63
51
|
|
64
|
-
<h2
|
52
|
+
<h2>BUILDING</h2>
|
65
53
|
|
66
54
|
<p>Once all dependencies are in place, you can build Matrixy using this sequence of commands:</p>
|
67
55
|
|
68
|
-
<pre>
|
69
|
-
|
56
|
+
<pre><code>perl Configure.pl
|
57
|
+
nmake test</code></pre>
|
70
58
|
|
71
|
-
<h2
|
59
|
+
<h2>TODO</h2>
|
72
60
|
|
73
|
-
<pre
|
74
|
-
|
75
|
-
|
61
|
+
<pre><code>* Parser
|
62
|
+
* Standard Builtins
|
63
|
+
* Test against Octave Test Suite.</code></pre>
|
76
64
|
|
77
|
-
<h2
|
65
|
+
<h2>BUGS</h2>
|
78
66
|
|
79
67
|
<p>Lots!</p>
|
80
68
|
|
81
|
-
<h2
|
69
|
+
<h2>CONTACT</h2>
|
82
70
|
|
83
71
|
<p>If you need to contact the Matrixy team, go to the project home page at:</p>
|
84
72
|
|
data/test/markups/README.rst
CHANGED
@@ -44,6 +44,9 @@ The UTF-8 quote character in this table used to cause python to go boom. Now doc
|
|
44
44
|
>>> some_function()
|
45
45
|
'result'
|
46
46
|
|
47
|
+
>>> some_function()
|
48
|
+
'result'
|
49
|
+
|
47
50
|
============== ==========================================================
|
48
51
|
Travis http://travis-ci.org/tony/pullv
|
49
52
|
Docs http://pullv.rtfd.org
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.6
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- bin/github-markup
|
115
115
|
- github-markup.gemspec
|
116
116
|
- lib/github-markup.rb
|
117
|
+
- lib/github/commands/pod2html
|
117
118
|
- lib/github/commands/rest2html
|
118
119
|
- lib/github/markup.rb
|
119
120
|
- lib/github/markup/command_implementation.rb
|
@@ -130,6 +131,8 @@ files:
|
|
130
131
|
- test/markups/README.asciidoc.html
|
131
132
|
- test/markups/README.creole
|
132
133
|
- test/markups/README.creole.html
|
134
|
+
- test/markups/README.directives.rst
|
135
|
+
- test/markups/README.directives.rst.html
|
133
136
|
- test/markups/README.litcoffee
|
134
137
|
- test/markups/README.litcoffee.html
|
135
138
|
- test/markups/README.markdown
|
@@ -187,6 +190,8 @@ test_files:
|
|
187
190
|
- test/markups/README.asciidoc.html
|
188
191
|
- test/markups/README.creole
|
189
192
|
- test/markups/README.creole.html
|
193
|
+
- test/markups/README.directives.rst
|
194
|
+
- test/markups/README.directives.rst.html
|
190
195
|
- test/markups/README.litcoffee
|
191
196
|
- test/markups/README.litcoffee.html
|
192
197
|
- test/markups/README.markdown
|