gfm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +15 -0
  2. data/bin/gfm +3 -0
  3. data/lib/gfm.rb +45 -0
  4. metadata +75 -0
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzU4ZjE2MTY0YmI5N2I0ZmM1ZjNlNTQ3ODBlNWQ0N2MxNGUyMTRmYQ==
5
+ data.tar.gz: !binary |-
6
+ Yjc1MDNiNzdiNGEzMmE5MDlmZTAzZmQyMjljMDhkMThjMDU2ZTZjMw==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MTVjYmU5Y2RhZmYwNTJhOWYyMmRiOWRmZjQzMThmY2I5ZDE1NzRiN2E3ODI2
10
+ Nzg3MGZlZTRkNmI0NWM0OGNlODk3OTQ4ZjAxNmUzMDcxMzMwMmY2ZTRiYzkz
11
+ NmU4N2YxZGVkNzI0YmM2ZmU5MTcyZWZkOTdjZmM1ZmYzZTljMjk=
12
+ data.tar.gz: !binary |-
13
+ YTBmMGI5NWYwMGI3YzM5NTQyOWQ4YTE0NzZmYTJjZmI5ODUzNzVhOGY2YTNm
14
+ MTIzMTAzN2RhYzc0NGZlNDdmZGZmZDE2NjJiYmJjY2Q2NDAyYzljMTA2Nzc0
15
+ NDA4Njg4YTk2OWJhYTlkY2Q3MzI1NmZkYWQyZjAxZjg0NGVkYTU=
data/bin/gfm ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gfm'
@@ -0,0 +1,45 @@
1
+ input_file = ARGV[0]
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)
16
+ require 'html/pipeline'
17
+ require 'httpclient'
18
+ require 'linguist'
19
+
20
+ pipeline = HTML::Pipeline.new [
21
+ HTML::Pipeline::MarkdownFilter,
22
+ HTML::Pipeline::TableOfContentsFilter,
23
+ HTML::Pipeline::SanitizationFilter,
24
+ HTML::Pipeline::ImageMaxWidthFilter,
25
+ HTML::Pipeline::HttpsFilter,
26
+ HTML::Pipeline::MentionFilter,
27
+ HTML::Pipeline::SyntaxHighlightFilter
28
+ ]
29
+
30
+ stylesheet_tags = HTTPClient.new.get("https://github.com").body.split("\n").select do |line|
31
+ line=~/https:.*github.*\.css/
32
+ end.join
33
+
34
+ output_file_name = ARGV[1].present? ? (ARGV[1].end_with?('.html') ? ARGV[1] : ARGV[1] + '.html') : nil
35
+ output_file = File.open(output_file_name || ARGV[0].gsub('md', 'html'), 'w')
36
+
37
+ html_opening_tags = "<html><head><title>#{ARGV[0]}</title>"
38
+ body_tags = "</head><body><div id='readme' style='width:914px;margin:20px auto'><article class='markdown-body'>"
39
+ body_content = pipeline.call(File.new(ARGV[0]).readlines.join)[:output].to_s
40
+ html_closing_tags = '</article></div></body></html>'
41
+
42
+ output_file.write(html_opening_tags + stylesheet_tags + body_tags + body_content + html_closing_tags)
43
+ else
44
+ puts "Invalid markdown file #{ARGV[0]}"
45
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gfm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Rose
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: html-pipeline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: github-linguist
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Generates an HTML file from a GitHub Flavored Markdown File. Useful for
42
+ previewing README files.
43
+ email: ekimsc1094@sympatico.ca
44
+ executables:
45
+ - gfm
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - lib/gfm.rb
50
+ - bin/gfm
51
+ homepage: https://github.com/msrose/gfm
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.7
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: GitHub Flavoured Markdown Previewer
75
+ test_files: []