md2pukiwiki 0.0.1

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: a3f6772be1c5d36b6fa2233dc5da1b9ed849899a
4
+ data.tar.gz: 5476c351b4d8ce08c4c178cd9dec4e3f75dc3523
5
+ SHA512:
6
+ metadata.gz: 059407a05b13c57648a2741d78a7e7ace80fdff2796d37605354356d3534cffb0c5666bf628b5f55f5db10b4bc3a4cce41279b70081b62662239e967748d7eeb
7
+ data.tar.gz: 39372cff963b948c171867635fe126549c416ccd717becaf19622ba3737efc6e6831732511ccf2f8390c587cc9aa405c435ff9984901b8683380f730124f04b7
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in md2pukiwiki.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 dtan4
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,61 @@
1
+ # md2pukiwiki
2
+ [![Build Status](https://travis-ci.org/dtan4/md2pukiwiki.svg?branch=master)](https://travis-ci.org/dtan4/md2pukiwiki)
3
+ [![Coverage Status](https://coveralls.io/repos/dtan4/md2pukiwiki/badge.png)](https://coveralls.io/r/dtan4/md2pukiwiki)
4
+ [![Code Climate](https://codeclimate.com/github/dtan4/md2pukiwiki.png)](https://codeclimate.com/github/dtan4/md2pukiwiki)
5
+
6
+ Convert Markdown to Pukiwiki-notation
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'md2pukiwiki'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install md2pukiwiki
21
+
22
+ ## Usage
23
+
24
+ $ md2pukiwiki <filename>
25
+
26
+ Conversion result will be written to the standard output.
27
+
28
+ ## Example
29
+
30
+ ```
31
+ $ cat sample.md
32
+ # header
33
+ * list1
34
+ * l**is**t2
35
+ * list2.1
36
+
37
+ ## subheader
38
+ 1. nlist1
39
+ 2. nl*is*t2
40
+ 1. nlist2.1
41
+
42
+ $ md2pukiwiki sample.md > sample.txt
43
+ $ cat sample.txt
44
+ *header
45
+ - list1
46
+ - l''is''t2
47
+ -- list2.1
48
+
49
+ **subheader
50
+ + nlist1
51
+ + nl'''is'''t2
52
+ ++ nlist2.1
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it ( https://github.com/dtan4/md2pukiwiki/fork )
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/bin/md2pukiwiki ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "md2pukiwiki"
4
+ require "pathname"
5
+
6
+ USAGE = "usage: md2pukiwiki <file>"
7
+
8
+ if ARGV.length < 1
9
+ $stderr.puts USAGE
10
+ exit 1
11
+ end
12
+
13
+ filename = ARGV.shift
14
+
15
+ unless File.exist?(filename)
16
+ $stderr.puts "file not found!: #{filename}"
17
+ exit 1
18
+ end
19
+
20
+ puts Md2pukiwiki.convert(open(filename).read)
@@ -0,0 +1,75 @@
1
+ require "md2pukiwiki/version"
2
+
3
+ module Md2pukiwiki
4
+ def self.convert(text)
5
+ text.lines.map do |line|
6
+ new_line = line.chomp
7
+
8
+ new_line = convert_header(new_line)
9
+ new_line = convert_list(new_line)
10
+ new_line = convert_numbered_list(new_line)
11
+
12
+ new_line = convert_bold_text(new_line)
13
+ new_line = convert_italic_text(new_line)
14
+ new_line = convert_strikethrough_text(new_line)
15
+
16
+ new_line = convert_image(new_line)
17
+ new_line = convert_link(new_line)
18
+
19
+ new_line
20
+ end.join("\n")
21
+ end
22
+
23
+ private
24
+
25
+ # "# header" => "*header"
26
+ def self.convert_header(line)
27
+ if /\A(?<sharps>#+) (?<header>.+)\z/ =~ line
28
+ "#{'*' * sharps.length}#{header}"
29
+ else
30
+ line
31
+ end
32
+ end
33
+
34
+ # "* list" => "- list"
35
+ def self.convert_list(line)
36
+ if /\A(?<spaces>\s*)\* (?<list>.+)\z/ =~ line
37
+ "#{'-' * (spaces.length / 4 + 1)} #{list}"
38
+ else
39
+ line
40
+ end
41
+ end
42
+
43
+ # "1. list" => "+ list"
44
+ def self.convert_numbered_list(line)
45
+ if /\A(?<spaces>\s*)\d+\. (?<list>.+)\z/ =~ line
46
+ "#{'+' * (spaces.length / 4 + 1)} #{list}"
47
+ else
48
+ line
49
+ end
50
+ end
51
+
52
+ # "**bold**" => "''bold''"
53
+ def self.convert_bold_text(line)
54
+ line.gsub(/(?:\*{2}|_{2})(?<bold>.+?)(?:\*{2}|_{2})/, "''\\k<bold>''")
55
+ end
56
+
57
+ # "*italic*" => "'''italic'''"
58
+ def self.convert_italic_text(line)
59
+ line.gsub(/(?:\*{1}|_{1})(?<italic>.+?)(?:\*{1}|_{1})/, "'''\\k<italic>'''")
60
+ end
61
+
62
+ def self.convert_strikethrough_text(line)
63
+ line.gsub(/~{2}(?<strikethrough>.+?)~{2}/, '%%\k<strikethrough>%%')
64
+ end
65
+
66
+ # "![text](image)" => "#ref(image,text)"
67
+ def self.convert_image(line)
68
+ line.gsub(/!\[(?<text>.+?)\]\((?<image>.+?)\)/, '#ref(\k<image>,\k<text>)')
69
+ end
70
+
71
+ # "[text](link)" => "[[text:link]]"
72
+ def self.convert_link(line)
73
+ line.gsub(/\[(?<text>.+?)\]\((?<link>.+?)\)/, '[[\k<text>:\k<link>]]')
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module Md2pukiwiki
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'md2pukiwiki/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "md2pukiwiki"
8
+ spec.version = Md2pukiwiki::VERSION
9
+ spec.authors = ["dtan4"]
10
+ spec.email = ["dtanshi45@gmail.com"]
11
+ spec.summary = %q{Convert Markdown to Pukiwiki-notation}
12
+ spec.description = %q{Text converter from Markdown to Pukiwiki-notation}
13
+ spec.homepage = "https://github.com/dtan4/md2pukiwiki"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+ spec.add_development_dependency "coveralls"
26
+ end
@@ -0,0 +1,91 @@
1
+ require 'spec_helper'
2
+
3
+ describe Md2pukiwiki do
4
+ describe "#convert" do
5
+ it "should convert header" do
6
+ expect(Md2pukiwiki.convert("# header")).to eq "*header"
7
+ end
8
+
9
+ it "should convert sub-header" do
10
+ expect(Md2pukiwiki.convert("## header")).to eq "**header"
11
+ end
12
+
13
+ it "should convert list" do
14
+ expect(Md2pukiwiki.convert("* list")).to eq "- list"
15
+ end
16
+
17
+ it "should convert nested list" do
18
+ expect(Md2pukiwiki.convert(" * list")).to eq "-- list"
19
+ end
20
+
21
+ it "should convert numbered list" do
22
+ expect(Md2pukiwiki.convert("1. list")).to eq "+ list"
23
+ end
24
+
25
+ it "should convert nested numbered list" do
26
+ expect(Md2pukiwiki.convert(" 1. list")).to eq "++ list"
27
+ end
28
+
29
+ it "should convert bold text" do
30
+ expect(Md2pukiwiki.convert("**bold**")).to eq "''bold''"
31
+ end
32
+
33
+ it "should convert underscore-notation bold text" do
34
+ expect(Md2pukiwiki.convert("__bold__")).to eq "''bold''"
35
+ end
36
+
37
+ it "should convert italic text" do
38
+ expect(Md2pukiwiki.convert("*italic*")).to eq "'''italic'''"
39
+ end
40
+
41
+ it "should convert underscore-notation italic text" do
42
+ expect(Md2pukiwiki.convert("_italic_")).to eq "'''italic'''"
43
+ end
44
+
45
+ it "should convert strikethrough text" do
46
+ expect(Md2pukiwiki.convert("~~strikethrough~~")).to eq "%%strikethrough%%"
47
+ end
48
+
49
+ it "should convert link" do
50
+ expect(Md2pukiwiki.convert("[link](http://link.com)")).to eq "[[link:http://link.com]]"
51
+ end
52
+
53
+ it "should convert image" do
54
+ converted = Md2pukiwiki.convert("![image](http://link.com/image.jpg)")
55
+ expect(converted).to eq "#ref(http://link.com/image.jpg,image)"
56
+ end
57
+
58
+ it "should convert image link" do
59
+ converted = Md2pukiwiki.convert("[![ImageLink](http://link.com/image.jpg)](http://link.com/)")
60
+ expect(converted).to eq "[[#ref(http://link.com/image.jpg,ImageLink):http://link.com/]]"
61
+ end
62
+
63
+ it "should convert multi-line text" do
64
+ markdown = <<-EOS.strip
65
+ # header
66
+ * list1
67
+ * l**is**t2
68
+ * list2.1
69
+
70
+ ## subheader
71
+ 1. nlist1
72
+ 2. nl*is*t2
73
+ 1. nlist2.1
74
+ EOS
75
+
76
+ pukiwiki = <<-EOS.strip
77
+ *header
78
+ - list1
79
+ - l''is''t2
80
+ -- list2.1
81
+
82
+ **subheader
83
+ + nlist1
84
+ + nl'''is'''t2
85
+ ++ nlist2.1
86
+ EOS
87
+
88
+ expect(Md2pukiwiki.convert(markdown)).to eq pukiwiki
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,5 @@
1
+ require "coveralls"
2
+ Coveralls.wear!
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
5
+ require 'md2pukiwiki'
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: md2pukiwiki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - dtan4
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Text converter from Markdown to Pukiwiki-notation
84
+ email:
85
+ - dtanshi45@gmail.com
86
+ executables:
87
+ - md2pukiwiki
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - Guardfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/md2pukiwiki
100
+ - lib/md2pukiwiki.rb
101
+ - lib/md2pukiwiki/version.rb
102
+ - md2pukiwiki.gemspec
103
+ - spec/md2pukiwiki_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: https://github.com/dtan4/md2pukiwiki
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Convert Markdown to Pukiwiki-notation
129
+ test_files:
130
+ - spec/md2pukiwiki_spec.rb
131
+ - spec/spec_helper.rb
132
+ has_rdoc: