gfm 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/gfm +11 -0
- data/lib/gfm.rb +26 -36
- data/lib/gfm/converter.rb +44 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTE3NDBjOGQyYTU0MWE3NjI1YTdmMTA4MWYzZjQ5YmY3YTJlMTUyNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTJkMzBmMTRlZmVlMWIyNjBkNzcyMGIxMTNlYjExMDA2NWUwNTQyYQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTNmNTY5OWNhMGUyZWQzOGFiZWI1ZGY5MGE3NWJmNzM2ZTE1OTc0ZTgxZGIx
|
10
|
+
Yzk1ZjI3MjQ4NTk4NzQzY2ExYzFkNjE4OGNmNTIzMzVjMzhmZjc0MjRkOWYw
|
11
|
+
ZGYzNWU1ZjBkODgzOTU0MGFkYzZkYjMzOTIzNTE5ZWUyMDc5ZGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTg3NDBkNjgyNTBjNmQ5MjAzNWYzMTE2ZDBlZjhhNTY0NzI3MzZjZDZhMzgx
|
14
|
+
YTFiZGVjZWYyZTE3NWIwMGI3OGVlYWFiZGE0MzJiNDAyZjRlNjkzYTMzN2Yz
|
15
|
+
ZDFjZjdjMjU1Yjc4ZTczZmNiNjg4NTU0NGQ2NzBlZTgwNzc5ODg=
|
data/bin/gfm
CHANGED
@@ -1,3 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'gfm'
|
4
|
+
require 'gfm/converter'
|
5
|
+
|
6
|
+
input_file, output_file = ARGV
|
7
|
+
|
8
|
+
if input_file.nil? || ARGV.include?('--help') || ARGV.include?('-h')
|
9
|
+
puts GFM::HELP_TEXT
|
10
|
+
elsif input_file.end_with?(".md") && File.exists?(input_file)
|
11
|
+
GFM::Converter.new(input_file).write_output_file(output_file)
|
12
|
+
else
|
13
|
+
puts "Invalid markdown file #{input_file}"
|
14
|
+
end
|
data/lib/gfm.rb
CHANGED
@@ -1,45 +1,35 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
if input_file.nil? || ARGV.include?('--help') || ARGV.include?('-h')
|
4
|
-
puts <<HELP
|
5
|
-
Usage:
|
6
|
-
gfm input_file.md [output_file] [--help, -h]
|
7
|
-
|
8
|
-
input_file.md The markdown file to be parsed with GitHub Flavored Markdown.
|
9
|
-
|
10
|
-
output_file Name of the output file to be generated. If no name is given,
|
11
|
-
input_file.html is used.
|
12
|
-
|
13
|
-
--help, -h Display this help message.
|
14
|
-
HELP
|
15
|
-
elsif input_file.end_with?(".md") && File.exists?(input_file)
|
1
|
+
module GFM
|
16
2
|
require 'html/pipeline'
|
17
3
|
require 'httpclient'
|
18
4
|
require 'linguist'
|
19
5
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
HTML::Pipeline::SanitizationFilter,
|
24
|
-
HTML::Pipeline::ImageMaxWidthFilter,
|
25
|
-
HTML::Pipeline::HttpsFilter,
|
26
|
-
HTML::Pipeline::MentionFilter,
|
27
|
-
HTML::Pipeline::SyntaxHighlightFilter
|
28
|
-
]
|
6
|
+
HELP_TEXT = <<HELP
|
7
|
+
Usage:
|
8
|
+
gfm INPUT_FILE.md [OUTPUT_FILE] [--help, -h]
|
29
9
|
|
30
|
-
|
31
|
-
line=~/https:.*github.*\.css/
|
32
|
-
end.join
|
10
|
+
INPUT_FILE.md The markdown file to be parsed with GitHub Flavored Markdown.
|
33
11
|
|
34
|
-
|
35
|
-
|
12
|
+
OUTPUT_FILE Name of the output file to be generated. If no name is given,
|
13
|
+
INPUT_FILE.html is used.
|
36
14
|
|
37
|
-
|
38
|
-
|
39
|
-
body_content = pipeline.call(File.new(ARGV[0]).readlines.join)[:output].to_s
|
40
|
-
html_closing_tags = '</article></div></body></html>'
|
15
|
+
--help, -h Display this help message.
|
16
|
+
HELP
|
41
17
|
|
42
|
-
|
43
|
-
|
44
|
-
|
18
|
+
def self.pipeline
|
19
|
+
HTML::Pipeline.new [
|
20
|
+
HTML::Pipeline::MarkdownFilter,
|
21
|
+
HTML::Pipeline::TableOfContentsFilter,
|
22
|
+
HTML::Pipeline::SanitizationFilter,
|
23
|
+
HTML::Pipeline::ImageMaxWidthFilter,
|
24
|
+
HTML::Pipeline::HttpsFilter,
|
25
|
+
HTML::Pipeline::MentionFilter,
|
26
|
+
HTML::Pipeline::SyntaxHighlightFilter
|
27
|
+
]
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.stylesheet_tags
|
31
|
+
HTTPClient.new.get("https://github.com").body.split("\n").select do |line|
|
32
|
+
line=~/https:.*github.*\.css/
|
33
|
+
end.join
|
34
|
+
end
|
45
35
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module GFM
|
2
|
+
class Converter
|
3
|
+
def initialize(input_file_name)
|
4
|
+
@input_file_name = input_file_name
|
5
|
+
end
|
6
|
+
|
7
|
+
def write_output_file(filename = nil)
|
8
|
+
File.open(sanitized_output_file_name(filename), 'w').write(html_content)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def sanitized_output_file_name(filename = nil)
|
14
|
+
if filename.present?
|
15
|
+
filename.end_with?('.html') ? filename : filename + '.html'
|
16
|
+
else
|
17
|
+
@input_file_name.gsub('md', 'html')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def html_content
|
23
|
+
%Q{
|
24
|
+
<html>
|
25
|
+
<head>
|
26
|
+
<title>#{@input_file_name}</title>
|
27
|
+
#{GFM.stylesheet_tags}
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div id='readme' style='width:914px;margin:20px auto'>
|
31
|
+
<article class='markdown-body'>
|
32
|
+
#{parse_markdown}
|
33
|
+
</article>
|
34
|
+
</div>
|
35
|
+
</body>
|
36
|
+
</html>
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def parse_markdown
|
41
|
+
GFM.pipeline.call(File.new(@input_file_name).read)[:output].to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gfm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Rose
|
@@ -47,6 +47,7 @@ extensions: []
|
|
47
47
|
extra_rdoc_files: []
|
48
48
|
files:
|
49
49
|
- lib/gfm.rb
|
50
|
+
- lib/gfm/converter.rb
|
50
51
|
- bin/gfm
|
51
52
|
homepage: https://github.com/msrose/gfm
|
52
53
|
licenses:
|