md2hiki 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/md2hiki +46 -0
- data/lib/md2hiki.rb +5 -0
- data/lib/md2hiki/version.rb +3 -0
- data/lib/redcarpet/render/hiki.rb +135 -0
- data/md2hiki.gemspec +25 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 takahashim
|
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,29 @@
|
|
1
|
+
# Md2hiki
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'md2hiki'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install md2hiki
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/md2hiki
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Usage: redcarpet [--parse-<extension>...] [--render-<extension>...] [--smarty] [<file>...]
|
3
|
+
# Convert one or more Markdown files to Hiki and write to standard output. With
|
4
|
+
# no <file> or when <file> is '-', read Markdown source text from standard input.
|
5
|
+
# With <extension>s, perform additional Markdown processing before writing output.
|
6
|
+
if ARGV.include?('--help')
|
7
|
+
File.read(__FILE__).split("\n").grep(/^# /).each do |line|
|
8
|
+
puts line[2..-1]
|
9
|
+
end
|
10
|
+
exit 0
|
11
|
+
end
|
12
|
+
|
13
|
+
root = File.expand_path('../../', __FILE__)
|
14
|
+
$:.unshift File.expand_path('lib', root)
|
15
|
+
|
16
|
+
require 'redcarpet'
|
17
|
+
require 'redcarpet/render/hiki'
|
18
|
+
|
19
|
+
render_extensions = {}
|
20
|
+
parse_extensions = {}
|
21
|
+
parse_extensions[:tables] = true
|
22
|
+
parse_extensions[:strikethrough] = true
|
23
|
+
parse_extensions[:fenced_code_blocks] = true
|
24
|
+
|
25
|
+
|
26
|
+
renderer = Redcarpet::Render::Hiki
|
27
|
+
|
28
|
+
ARGV.delete_if do |arg|
|
29
|
+
if arg =~ /^--render-header-offset\s*=\s*([012])$/
|
30
|
+
render_extensions[:header_offset] = $1.to_i
|
31
|
+
elsif arg =~ /^--render-([\w-]+)$/
|
32
|
+
arg = $1.gsub('-', '_')
|
33
|
+
render_extensions[arg.to_sym] = true
|
34
|
+
elsif arg =~ /^--parse-([\w-]+)$/
|
35
|
+
arg = $1.gsub('-', '_')
|
36
|
+
parse_extensions[arg.to_sym] = true
|
37
|
+
else
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
render = renderer.new(render_extensions)
|
43
|
+
md = Redcarpet::Markdown.new(render, parse_extensions)
|
44
|
+
md_doc = ARGF.read
|
45
|
+
hiki_doc = md.render(md_doc)
|
46
|
+
STDOUT.write hiki_doc
|
data/lib/md2hiki.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
module Redcarpet
|
2
|
+
module Render
|
3
|
+
class Hiki < Base
|
4
|
+
|
5
|
+
def initialize(render_extensions)
|
6
|
+
super()
|
7
|
+
@header_offset = 0
|
8
|
+
if render_extensions[:header_offset]
|
9
|
+
@header_offset = render_extensions[:header_offset]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def normal_text(text)
|
14
|
+
text
|
15
|
+
end
|
16
|
+
|
17
|
+
def escape_inline(text)
|
18
|
+
## text.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/</, "<")
|
19
|
+
text
|
20
|
+
end
|
21
|
+
|
22
|
+
def block_code(code, language)
|
23
|
+
code_text = normal_text(code).chomp
|
24
|
+
code_text.gsub!(/^/,' ')
|
25
|
+
"\n#{code_text}\n\n"
|
26
|
+
end
|
27
|
+
|
28
|
+
def block_quote(quote)
|
29
|
+
quote_text = normal_text(quote).chomp
|
30
|
+
quote_text.gsub!(/^/,'""')
|
31
|
+
"\n#{quote_text}\n\n"
|
32
|
+
end
|
33
|
+
|
34
|
+
def block_html(raw_html)
|
35
|
+
html_text = raw_html.chomp
|
36
|
+
warning = "XXX: BLOCK_HTML: YOU SHOULD REWRITE IT"
|
37
|
+
"\n#{warning}\n#{html_text}\n\n"
|
38
|
+
end
|
39
|
+
|
40
|
+
def hrule
|
41
|
+
"\n//hr\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
def codespan(code)
|
45
|
+
"``#{escape_inline(code)}``"
|
46
|
+
end
|
47
|
+
|
48
|
+
def header(title, level)
|
49
|
+
l = level - @header_offset
|
50
|
+
case l
|
51
|
+
when 1
|
52
|
+
"\n! #{title}\n"
|
53
|
+
when 2
|
54
|
+
"\n!! #{title}\n"
|
55
|
+
when 3
|
56
|
+
"\n!!!! #{title}\n"
|
57
|
+
when 4
|
58
|
+
"\n!!!! #{title}\n"
|
59
|
+
when 5
|
60
|
+
"\n!!!!! #{title}\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def table(header, body)
|
65
|
+
header_text = ""
|
66
|
+
if header
|
67
|
+
header_text = header
|
68
|
+
end
|
69
|
+
body.chomp!
|
70
|
+
"#{header_text}\n\n#{body}\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
def table_row(content)
|
74
|
+
content+"\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
def table_cell(content, alignment)
|
78
|
+
"||#{content}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def image(link, title, alt_text)
|
82
|
+
filename = File.basename(link,".*")
|
83
|
+
text = alt_text || title
|
84
|
+
"[[#{text}|#{link}]]"
|
85
|
+
end
|
86
|
+
|
87
|
+
def autolink(link, link_type)
|
88
|
+
"[[#{escape_inline(link)}]]"
|
89
|
+
end
|
90
|
+
|
91
|
+
def link(link, title, content)
|
92
|
+
"[[#{escape_inline(content)}|#{escape_inline(link)}]]"
|
93
|
+
end
|
94
|
+
|
95
|
+
def double_emphasis(text)
|
96
|
+
"''#{escape_inline(text)}''"
|
97
|
+
end
|
98
|
+
|
99
|
+
def emphasis(text)
|
100
|
+
"'#{escape_inline(text)}'"
|
101
|
+
end
|
102
|
+
|
103
|
+
def strikethrough(text)
|
104
|
+
"==#{escape_inline(text)}=="
|
105
|
+
end
|
106
|
+
|
107
|
+
def linebreak
|
108
|
+
"\n\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
def paragraph(text)
|
112
|
+
"\n\n#{text}\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
def list(content, list_type)
|
116
|
+
case list_type
|
117
|
+
when :ordered
|
118
|
+
"\n"
|
119
|
+
when :unordered
|
120
|
+
"\n"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def list_item(content, list_type)
|
125
|
+
case list_type
|
126
|
+
when :ordered
|
127
|
+
"# #{content.strip}\n"
|
128
|
+
when :unordered
|
129
|
+
"* #{content.strip}\n"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/md2hiki.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'md2hiki/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "md2hiki"
|
8
|
+
spec.version = Md2hiki::VERSION
|
9
|
+
spec.authors = ["takahashim"]
|
10
|
+
spec.email = ["maki@rubycolor.org"]
|
11
|
+
spec.description = %q{md2hiki is a Markdown to Hiki converter using redcarpet}
|
12
|
+
spec.summary = %q{Markdown -> Hiki converter}
|
13
|
+
spec.homepage = "https://github.com/takahashim/md2hiki"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency 'redcarpet', '>2.0.0'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: md2hiki
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- takahashim
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redcarpet
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '>'
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '>'
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.3'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.3'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: md2hiki is a Markdown to Hiki converter using redcarpet
|
63
|
+
email:
|
64
|
+
- maki@rubycolor.org
|
65
|
+
executables:
|
66
|
+
- md2hiki
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- bin/md2hiki
|
76
|
+
- lib/md2hiki.rb
|
77
|
+
- lib/md2hiki/version.rb
|
78
|
+
- lib/redcarpet/render/hiki.rb
|
79
|
+
- md2hiki.gemspec
|
80
|
+
homepage: https://github.com/takahashim/md2hiki
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.25
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Markdown -> Hiki converter
|
105
|
+
test_files: []
|