markdown2html 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c58ccbbf29dbe8b0c286da5989b8a4a1fe0cc3a0
4
+ data.tar.gz: a2b449be63e38c82297e23564fa99977757dd7cf
5
+ SHA512:
6
+ metadata.gz: 040de566967f41ede08ccd795a6677d78d46c5896859300b6410ff00242ee3eb69766eb31c4d889f6ac62ac277dc0c1308a700efc94959d613d6ffe5af259066
7
+ data.tar.gz: e8a21f79b2583845a893aa054c4b8251cda8b6fa356ff749fce26b7906cdce38e99dd872251d4dee6ffba49a655f2a5419a6209bdefd9c7ab4abd1a9b1153f90
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in markdown2html.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alfonso Cora
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ #Markdown2Html
2
+
3
+ ##Overview
4
+
5
+ Convert local markdown files or wikis from git repositories to html.
6
+
7
+ ##Installation
8
+
9
+ ```bash
10
+ $ gem install markdown2html
11
+ ```
12
+
13
+ ##Usage
14
+
15
+ Local conversion:
16
+
17
+ ```bash
18
+ markdown2html file1.md file2.md ...
19
+ ```
20
+
21
+ Download and convert a GitHub wiki:
22
+
23
+ ```bash
24
+ markdown2html plataformatec/devise
25
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/markdown2html ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'html/pipeline'
4
+ require 'markdown2html'
5
+
6
+ # get the output directory parameter
7
+ output_directory = nil
8
+ if o_index = ARGV.index('-o')
9
+ output_directory = ARGV[o_index + 1]
10
+ end
11
+
12
+ # detect mode
13
+ if ARGV.length == 0
14
+ # help mode
15
+ puts 'Usage:'
16
+ puts ' markdown2html file.md'
17
+ puts ' markdown2html file1.md file2.md ...'
18
+ puts ' markdown2html plataformatec/devise'
19
+ elsif ARGV.any? {|f| f =~ /\.md$/}
20
+ # file mode
21
+ ARGV.each do |file|
22
+ next unless file =~ /\.md$/
23
+ puts "Converting #{file}..."
24
+ Markdown2Html::Processor.convert_file(file, :output_directory => output_directory)
25
+ end
26
+ else
27
+ # github mode
28
+ repository = ARGV[0]
29
+ wiki_repository = "#{repository}.wiki"
30
+ directory = wiki_repository.split('/')[1]
31
+ output_directory ||= "#{directory}_html"
32
+
33
+ unless Dir.exists?(directory)
34
+ clone_command = "git clone git://github.com/#{wiki_repository}.git"
35
+ puts "> #{clone_command}"
36
+ fail unless system(clone_command)
37
+ end
38
+
39
+ unless Dir.exists?(output_directory)
40
+ mkdir_command = "mkdir #{output_directory}"
41
+ puts "> #{mkdir_command}"
42
+ fail unless system(mkdir_command)
43
+ end
44
+
45
+ Dir.glob("#{directory}/**/*.md").each do |file|
46
+ puts "Converting #{file}..."
47
+ Markdown2Html::Processor.convert_file(file, :output_directory => output_directory, :repository => repository)
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ module Markdown2Html
2
+ class LinkFilter
3
+ def initialize(source, repository)
4
+ @source = source
5
+ @repository = repository
6
+ end
7
+
8
+ def call
9
+ @result = @source.gsub(/\[\[.*\]\]/) do |page_name|
10
+ page_name.gsub!(/[\[\]]/, '')
11
+ link = page_name_to_path(page_name)
12
+ "<a href=\"#{link}\">#{page_name}</a>"
13
+ end
14
+
15
+ if @repository
16
+ @result.gsub!(/"(https:\/\/github.com\/#{@repository}\/wiki\/)(.*)"/) do |explicit_link|
17
+ url, path = $1, $2
18
+
19
+ next explicit_link if path =~ /^_pages/
20
+
21
+ explicit_link.gsub!(url, '')
22
+ explicit_link.gsub!(path, page_name_to_path(path))
23
+ end
24
+ end
25
+
26
+ @result
27
+ end
28
+
29
+ def page_name_to_path(page_name)
30
+ "#{page_name.downcase.gsub(/\s/,'-').gsub(':', '%3A')}.html"
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ require 'markdown2html/link_filter'
2
+
3
+ module Markdown2Html
4
+ class Processor
5
+ def self.convert_file(source_filename, options={})
6
+ return unless source_filename =~ /\.md$/
7
+
8
+ output_directory = options.fetch(:output_directory, nil)
9
+ repository = options.fetch(:repository, nil)
10
+
11
+ File.open(source_filename, 'r') do |source_file|
12
+ File.open(target_filename(source_filename, output_directory), 'w') do |target_file|
13
+ md_filter = HTML::Pipeline::MarkdownFilter.new(source_file.read)
14
+ link_filter = Markdown2Html::LinkFilter.new(md_filter.call, repository)
15
+ target_file.write(link_filter.call)
16
+ end
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def self.target_filename(source_filename, output_directory=nil)
23
+ # sanitize final slash
24
+ if output_directory && !(output_directory =~ /\/$/)
25
+ output_directory += '/'
26
+ end
27
+
28
+ if output_directory
29
+ output_directory + source_filename.gsub(/^.*\//, '')
30
+ else
31
+ source_filename
32
+ end.gsub(/md$/, 'html').downcase
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require 'markdown2html/processor'
data/license.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Alfonso Cora
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'markdown2html'
7
+ gem.version = '0.1.0'
8
+ gem.authors = ['Alf Cora']
9
+ gem.email = ['alfius@protonmail.com']
10
+ gem.description = %q{Convert markdown files and wikis to html.}
11
+ gem.summary = %q{Convert local markdown files or wikis from git repositories to html.}
12
+ gem.homepage = 'https://github.com/alfonsocora/markdown2html'
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ['lib']
18
+
19
+ gem.add_runtime_dependency 'html-pipeline', '~> 2.2', '>= 2.2.2'
20
+ gem.add_runtime_dependency 'github-markdown', '~> 0.6', '>= 0.6.9'
21
+ gem.add_development_dependency 'rspec', '~> 2.12', '>= 2.12.0'
22
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Markdown2Html::LinkFilter do
4
+ it 'should fix links to implicit pages' do
5
+ source = '[[Another-Local-Page]]'
6
+ Markdown2Html::LinkFilter.new(source, nil).call.should == '<a href="another-local-page.html">Another-Local-Page</a>'
7
+ end
8
+
9
+ it 'should fix explicit links' do
10
+ source = '<a href="https://github.com/user/repo/wiki/Another-Local-Page">Another-Local-Page</a>'
11
+ Markdown2Html::LinkFilter.new(source, 'user/repo').call.should == '<a href="another-local-page.html">Another-Local-Page</a>'
12
+ end
13
+
14
+ it 'should leave links to github pages untouched' do
15
+ source = '<a href="https://github.com/user/repo/wiki/_pages">Pages</a>'
16
+ Markdown2Html::LinkFilter.new(source, 'user/repo').call.should == source
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ require 'markdown2html'
4
+
5
+ Dir[File.expand_path("support/*", File.dirname(__FILE__))].each {|f| require f}
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :rspec
9
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markdown2html
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alf Cora
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-01 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: '2.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.2.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.2.2
33
+ - !ruby/object:Gem::Dependency
34
+ name: github-markdown
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.6'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.6.9
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.6'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.6.9
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.12'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 2.12.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.12'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 2.12.0
73
+ description: Convert markdown files and wikis to html.
74
+ email:
75
+ - alfius@protonmail.com
76
+ executables:
77
+ - markdown2html
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/markdown2html
87
+ - lib/markdown2html.rb
88
+ - lib/markdown2html/link_filter.rb
89
+ - lib/markdown2html/processor.rb
90
+ - license.txt
91
+ - markdown2html.gemspec
92
+ - spec/lib/markdown2html/link_filter_spec.rb
93
+ - spec/spec_helper.rb
94
+ homepage: https://github.com/alfonsocora/markdown2html
95
+ licenses: []
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Convert local markdown files or wikis from git repositories to html.
117
+ test_files:
118
+ - spec/lib/markdown2html/link_filter_spec.rb
119
+ - spec/spec_helper.rb