markdown2html 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c58ccbbf29dbe8b0c286da5989b8a4a1fe0cc3a0
4
- data.tar.gz: a2b449be63e38c82297e23564fa99977757dd7cf
3
+ metadata.gz: 2d86e3ec1e255b2db0b3def7be33646bd8f6b4d1
4
+ data.tar.gz: 57ca287284b5d5e7e2bb9d4a05fdaf090b264b2d
5
5
  SHA512:
6
- metadata.gz: 040de566967f41ede08ccd795a6677d78d46c5896859300b6410ff00242ee3eb69766eb31c4d889f6ac62ac277dc0c1308a700efc94959d613d6ffe5af259066
7
- data.tar.gz: e8a21f79b2583845a893aa054c4b8251cda8b6fa356ff749fce26b7906cdce38e99dd872251d4dee6ffba49a655f2a5419a6209bdefd9c7ab4abd1a9b1153f90
6
+ metadata.gz: b9d4ad9ae30094affd2563cba10d060becd48c18cfd03511eb2c6a7027b14346307bc7ee1545007064f12e4a2b1a688fe443a5904ecd7ed577bdf58eefa51c80
7
+ data.tar.gz: 56700beb424e4ebfa20d82fef081cd3faa97d7915814e7891b89fd8465251c75f202364f22d4f436aeb402582e82dd86e2b8fdd7a50c5fd23f3a0d60f448bd69
data/README.md CHANGED
@@ -1,25 +1,30 @@
1
- #Markdown2Html
1
+ # Markdown2Html
2
2
 
3
- ##Overview
3
+ ## Overview
4
4
 
5
- Convert local markdown files or wikis from git repositories to html.
5
+ Convert local markdown files or entire GitHub wikis to html.
6
6
 
7
- ##Installation
7
+ ## Installation
8
8
 
9
9
  ```bash
10
- $ gem install markdown2html
10
+ gem install markdown2html
11
11
  ```
12
12
 
13
- ##Usage
13
+ ## Usage
14
14
 
15
- Local conversion:
15
+ ### Local conversion
16
16
 
17
17
  ```bash
18
+ markdown2html file.md
18
19
  markdown2html file1.md file2.md ...
19
20
  ```
20
21
 
21
- Download and convert a GitHub wiki:
22
+ The html file will be created in the same directory with a similar name and the `.html` extension.
23
+
24
+ ### GitHub wiki
22
25
 
23
26
  ```bash
24
27
  markdown2html plataformatec/devise
25
28
  ```
29
+
30
+ This command clones the wiki in the current directory and then it converts each md file on it to html.
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/**/test*.rb']
7
+ end
8
+
9
+ task :default => [:test]
@@ -1,14 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'html/pipeline'
4
3
  require 'markdown2html'
5
4
 
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
5
  # detect mode
13
6
  if ARGV.length == 0
14
7
  # help mode
@@ -21,14 +14,13 @@ elsif ARGV.any? {|f| f =~ /\.md$/}
21
14
  ARGV.each do |file|
22
15
  next unless file =~ /\.md$/
23
16
  puts "Converting #{file}..."
24
- Markdown2Html::Processor.convert_file(file, :output_directory => output_directory)
17
+ Markdown2Html::Processor.convert_file(file)
25
18
  end
26
19
  else
27
20
  # github mode
28
21
  repository = ARGV[0]
29
22
  wiki_repository = "#{repository}.wiki"
30
23
  directory = wiki_repository.split('/')[1]
31
- output_directory ||= "#{directory}_html"
32
24
 
33
25
  unless Dir.exists?(directory)
34
26
  clone_command = "git clone git://github.com/#{wiki_repository}.git"
@@ -36,14 +28,8 @@ else
36
28
  fail unless system(clone_command)
37
29
  end
38
30
 
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
31
  Dir.glob("#{directory}/**/*.md").each do |file|
46
32
  puts "Converting #{file}..."
47
- Markdown2Html::Processor.convert_file(file, :output_directory => output_directory, :repository => repository)
33
+ Markdown2Html::Processor.convert_file(file, :repository => repository)
48
34
  end
49
35
  end
@@ -1,15 +1,15 @@
1
1
  require 'markdown2html/link_filter'
2
+ require 'html/pipeline'
2
3
 
3
4
  module Markdown2Html
4
5
  class Processor
5
6
  def self.convert_file(source_filename, options={})
6
7
  return unless source_filename =~ /\.md$/
7
8
 
8
- output_directory = options.fetch(:output_directory, nil)
9
9
  repository = options.fetch(:repository, nil)
10
10
 
11
11
  File.open(source_filename, 'r') do |source_file|
12
- File.open(target_filename(source_filename, output_directory), 'w') do |target_file|
12
+ File.open(target_filename(source_filename), 'w') do |target_file|
13
13
  md_filter = HTML::Pipeline::MarkdownFilter.new(source_file.read)
14
14
  link_filter = Markdown2Html::LinkFilter.new(md_filter.call, repository)
15
15
  target_file.write(link_filter.call)
@@ -19,17 +19,8 @@ module Markdown2Html
19
19
 
20
20
  private
21
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
22
+ def self.target_filename(source_filename)
23
+ source_filename.gsub(/md$/, 'html').downcase
33
24
  end
34
25
  end
35
26
  end
@@ -4,12 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = 'markdown2html'
7
- gem.version = '0.1.0'
7
+ gem.version = '0.1.2'
8
8
  gem.authors = ['Alf Cora']
9
9
  gem.email = ['alfius@protonmail.com']
10
10
  gem.description = %q{Convert markdown files and wikis to html.}
11
11
  gem.summary = %q{Convert local markdown files or wikis from git repositories to html.}
12
12
  gem.homepage = 'https://github.com/alfonsocora/markdown2html'
13
+ gem.license = 'MIT'
13
14
 
14
15
  gem.files = `git ls-files`.split($/)
15
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -18,5 +19,6 @@ Gem::Specification.new do |gem|
18
19
 
19
20
  gem.add_runtime_dependency 'html-pipeline', '~> 2.2', '>= 2.2.2'
20
21
  gem.add_runtime_dependency 'github-markdown', '~> 0.6', '>= 0.6.9'
21
- gem.add_development_dependency 'rspec', '~> 2.12', '>= 2.12.0'
22
+ gem.add_development_dependency 'minitest', '~> 5.8', '>= 5.8.3'
23
+ gem.add_development_dependency 'rake', '~> 10.4', '>= 10.4.2'
22
24
  end
@@ -0,0 +1,18 @@
1
+ require 'test_helper'
2
+
3
+ class TestMarkdown2Html < Minitest::Test
4
+ def test_fixes_links_to_implicit_pages
5
+ source = '[[Another-Local-Page]]'
6
+ assert_equal '<a href="another-local-page.html">Another-Local-Page</a>', Markdown2Html::LinkFilter.new(source, nil).call
7
+ end
8
+
9
+ def test_fixes_explicit_links
10
+ source = '<a href="https://github.com/user/repo/wiki/Another-Local-Page">Another-Local-Page</a>'
11
+ assert_equal '<a href="another-local-page.html">Another-Local-Page</a>', Markdown2Html::LinkFilter.new(source, 'user/repo').call
12
+ end
13
+
14
+ def test_leaves_links_to_github_pages_untouched
15
+ source = '<a href="https://github.com/user/repo/wiki/_pages">Pages</a>'
16
+ assert_equal source, Markdown2Html::LinkFilter.new(source, 'user/repo').call
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+ require 'tempfile'
3
+
4
+ class TestProcessor < Minitest::Test
5
+ def test_ignores_non_md_files
6
+ assert_nil Markdown2Html::Processor.convert_file('file.txt')
7
+ end
8
+
9
+ def test_converts_to_html_and_sets_the_correct_filename
10
+ source = Tempfile.new(['source', '.md'])
11
+ source.write('# The Source')
12
+ source.close
13
+
14
+ Markdown2Html::Processor.convert_file(source.path)
15
+
16
+ File.open(source.path.gsub(/md$/, 'html').downcase, 'r') do |target|
17
+ assert_equal '<h1>The Source</h1>', target.readline
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'markdown2html'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown2html
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alf Cora
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-01 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: html-pipeline
@@ -51,25 +51,45 @@ dependencies:
51
51
  - !ruby/object:Gem::Version
52
52
  version: 0.6.9
53
53
  - !ruby/object:Gem::Dependency
54
- name: rspec
54
+ name: minitest
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - "~>"
58
58
  - !ruby/object:Gem::Version
59
- version: '2.12'
59
+ version: '5.8'
60
60
  - - ">="
61
61
  - !ruby/object:Gem::Version
62
- version: 2.12.0
62
+ version: 5.8.3
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '2.12'
69
+ version: '5.8'
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
- version: 2.12.0
72
+ version: 5.8.3
73
+ - !ruby/object:Gem::Dependency
74
+ name: rake
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '10.4'
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 10.4.2
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.4'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 10.4.2
73
93
  description: Convert markdown files and wikis to html.
74
94
  email:
75
95
  - alfius@protonmail.com
@@ -80,7 +100,6 @@ extra_rdoc_files: []
80
100
  files:
81
101
  - ".gitignore"
82
102
  - Gemfile
83
- - LICENSE.txt
84
103
  - README.md
85
104
  - Rakefile
86
105
  - bin/markdown2html
@@ -89,10 +108,12 @@ files:
89
108
  - lib/markdown2html/processor.rb
90
109
  - license.txt
91
110
  - markdown2html.gemspec
92
- - spec/lib/markdown2html/link_filter_spec.rb
93
- - spec/spec_helper.rb
111
+ - test/lib/markdown2html/test_link_filter.rb
112
+ - test/lib/markdown2html/test_processor.rb
113
+ - test/test_helper.rb
94
114
  homepage: https://github.com/alfonsocora/markdown2html
95
- licenses: []
115
+ licenses:
116
+ - MIT
96
117
  metadata: {}
97
118
  post_install_message:
98
119
  rdoc_options: []
@@ -115,5 +136,6 @@ signing_key:
115
136
  specification_version: 4
116
137
  summary: Convert local markdown files or wikis from git repositories to html.
117
138
  test_files:
118
- - spec/lib/markdown2html/link_filter_spec.rb
119
- - spec/spec_helper.rb
139
+ - test/lib/markdown2html/test_link_filter.rb
140
+ - test/lib/markdown2html/test_processor.rb
141
+ - test/test_helper.rb
@@ -1,22 +0,0 @@
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.
@@ -1,18 +0,0 @@
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
@@ -1,9 +0,0 @@
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