md2review 1.0.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.
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,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 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,32 @@
1
+ # md2review
2
+
3
+ md2review is a converter from Markdown into ReVIEW.
4
+ This command uses Redcarpet gem to parse markdown.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'md2review'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install md2review
19
+
20
+ ## Usage
21
+
22
+ You can use the commmand md2review as:
23
+
24
+ $ md2review your-document.md > your-document.re
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/md2review ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+ # Usage: redcarpet [--parse-<extension>...] [--render-<extension>...] [--smarty] [<file>...]
3
+ # Convert one or more Markdown files to ReVIEW 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/review'
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::ReVIEW
27
+
28
+ ARGV.delete_if do |arg|
29
+ if arg =~ /^--render-([\w-]+)$/
30
+ arg = $1.gsub('-', '_')
31
+ render_extensions[arg.to_sym] = true
32
+ elsif arg =~ /^--parse-([\w-]+)$/
33
+ arg = $1.gsub('-', '_')
34
+ parse_extensions[arg.to_sym] = true
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ render = renderer.new(render_extensions)
41
+ md = Redcarpet::Markdown.new(render, parse_extensions)
42
+ md_doc = ARGF.read
43
+ review_doc = md.render(md_doc)
44
+ STDOUT.write review_doc
@@ -0,0 +1,3 @@
1
+ module MD2ReVIEW
2
+ VERSION = "1.0.0"
3
+ end
data/lib/md2review.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "redcarpet-review/version"
2
+
3
+ module Redcarpet
4
+ module Review
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,135 @@
1
+ module Redcarpet
2
+ module Render
3
+ class ReVIEW < Base
4
+
5
+ def initialize(render_extensions)
6
+ super()
7
+ @table_num = 0
8
+ @table_id_prefix = "tbl"
9
+ end
10
+
11
+ def normal_text(text)
12
+ text
13
+ end
14
+
15
+ def block_code(code, language)
16
+ code_text = normal_text(code).chomp
17
+ lang = ""
18
+ if language
19
+ lang = "#\@# lang: #{language}\n"
20
+ end
21
+ "\n#{lang}//emlist{\n#{code_text}\n//}\n"
22
+ end
23
+
24
+ def block_quote(quote)
25
+ quote_text = normal_text(quote).chomp
26
+ quote_text.gsub!(/\A\n\n/,'')
27
+ "\n//quote{\n#{quote_text}\n//}\n"
28
+ end
29
+
30
+ def block_html(raw_html)
31
+ html_text = raw_html.chomp
32
+ warning = "XXX: BLOCK_HTML: YOU SHOULD REWRITE IT"
33
+ "\n//emlist{\n#{warning}\n#{html_text}\n//}\n"
34
+ end
35
+
36
+ def hrule
37
+ "\n//hr\n"
38
+ end
39
+
40
+ def codespan(code)
41
+ "@<tt>{#{normal_text(code)}}"
42
+ end
43
+
44
+ def header(title, level)
45
+ case level
46
+ when 1
47
+ "\n= #{title}\n"
48
+ when 2
49
+ "\n== #{title}\n"
50
+ when 3
51
+ "\n=== #{title}\n"
52
+ when 4
53
+ "\n==== #{title}\n"
54
+ end
55
+ end
56
+
57
+ def table(header, body)
58
+ @sep = nil
59
+ header_text = ""
60
+ if header
61
+ header_text = "#{header}-----------------\n"
62
+ end
63
+ "//table[#{table_id()}][]{\n#{header_text}#{body}\n//}\n"
64
+ end
65
+
66
+ def table_row(content)
67
+ @sep = nil
68
+ content+"\n"
69
+ end
70
+
71
+ def table_cell(content, alignment)
72
+ sep = @sep
73
+ @sep = "\t"
74
+ "#{sep}#{content}"
75
+ end
76
+
77
+ def image(link, title, alt_text)
78
+ filename = File.basename(link,".*")
79
+ "//image[#{filename}][#{alt_text}]{\n//}"
80
+ end
81
+
82
+ def autolink(link, link_type)
83
+ "@<href>{#{link}}"
84
+ end
85
+
86
+ def link(link, title, content)
87
+ "@<href>{#{link},#{content}}"
88
+ end
89
+
90
+ def double_emphasis(text)
91
+ "@<strong>{#{text}}"
92
+ end
93
+
94
+ def emphasis(text)
95
+ "@<b>{#{text}}"
96
+ end
97
+
98
+ def strikethrough(text)
99
+ "@<del>{#{text}}"
100
+ end
101
+
102
+ def linebreak
103
+ "@<br>{}\n"
104
+ end
105
+
106
+ def paragraph(text)
107
+ "\n\n#{text}\n"
108
+ end
109
+
110
+ def list(content, list_type)
111
+ case list_type
112
+ when :ordered
113
+ "\n#{content}\n"
114
+ when :unordered
115
+ "\n#{content}\n"
116
+ end
117
+ end
118
+
119
+ def list_item(content, list_type)
120
+ case list_type
121
+ when :ordered
122
+ " 1. #{content.strip}\n"
123
+ when :unordered
124
+ " * #{content.strip}\n"
125
+ end
126
+ end
127
+
128
+ def table_id()
129
+ @table_num += 1
130
+ "#{@table_id_prefix}#{@table_num}"
131
+ end
132
+
133
+ end
134
+ end
135
+ end
data/md2review.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'md2review/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "md2review"
8
+ gem.version = MD2ReVIEW::VERSION
9
+ gem.authors = ["takahashim"]
10
+ gem.email = ["takahashimm@gmail.com"]
11
+ gem.description = %q{a converter MD -> ReVIEW}
12
+ gem.summary = %q{a converter MD -> ReVIEW}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('redcarpet', '>2.0.0')
20
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: md2review
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - takahashim
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-23 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
+ description: a converter MD -> ReVIEW
31
+ email:
32
+ - takahashimm@gmail.com
33
+ executables:
34
+ - md2review
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - bin/md2review
44
+ - lib/md2review.rb
45
+ - lib/md2review/version.rb
46
+ - lib/redcarpet/render/review.rb
47
+ - md2review.gemspec
48
+ homepage: ''
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.24
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: a converter MD -> ReVIEW
72
+ test_files: []