md2review 1.2.0 → 1.3.0

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: e89900431129c85303b2e0b6a88148e46aeaf0c8
4
- data.tar.gz: a42c3ebdae24c58d1d94c316d2f7183a67211fc2
3
+ metadata.gz: a57ec7a51d60f3ee878b3744a749f25aa3d5567a
4
+ data.tar.gz: 860a29d7751752ba1715da6b10b7e8e9f3a9c0f5
5
5
  SHA512:
6
- metadata.gz: cfef0533c707cddc1ba28ccd5367f6977dd03b14ca9cf6475527e4b79b77985fb5aeb00f5d6668b092cbdd9420bc44f9595dbf41962dfc5ad037c16b28bfe8a7
7
- data.tar.gz: 1b8f74362eb313400d83a6ed906ad73a0c429301adf2d6cda2b5c086c785248f9cbd4b93f94a992409f14da4bedbb735cdac91aa8b13eeca2171f928dcbd6192
6
+ metadata.gz: 15bb56747f0611da2a5d34e6f59a163d3029a19cfb477df6936af6f9a7639298d0ee87edf8b0765b829f6fbe1c78267faf2442a5c8a2098106c61fd97dd1f052
7
+ data.tar.gz: 6f6f179e177c34a40cf0d000033ace1cf1bc04d28c9f158e3e63073bd5e38f7baa0d35d748225fc4a80a400c7b97af275a2cb840e3f36cba037585b0ced0a5e8
data/bin/md2review CHANGED
@@ -17,17 +17,20 @@ require 'redcarpet'
17
17
  require 'redcarpet/render/review'
18
18
 
19
19
  render_extensions = {}
20
+ render_extensions[:link_in_footnote] = false
20
21
  parse_extensions = {}
21
22
  parse_extensions[:tables] = true
22
23
  parse_extensions[:strikethrough] = true
23
24
  parse_extensions[:fenced_code_blocks] = true
24
-
25
+ parse_extensions[:footnotes] = true
25
26
 
26
27
  renderer = Redcarpet::Render::ReVIEW
27
28
 
28
29
  ARGV.delete_if do |arg|
29
30
  if arg =~ /^--render-header-offset\s*=\s*([012])$/
30
31
  render_extensions[:header_offset] = $1.to_i
32
+ elsif arg =~ /^--render-disable-image-caption$/
33
+ render_extensions[:disable_image_caption] = true
31
34
  elsif arg =~ /^--render-([\w-]+)$/
32
35
  arg = $1.gsub('-', '_')
33
36
  render_extensions[arg.to_sym] = true
@@ -1,3 +1,3 @@
1
1
  module MD2ReVIEW
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'digest/md5'
2
+
1
3
  module Redcarpet
2
4
  module Render
3
5
  class ReVIEW < Base
@@ -7,9 +9,12 @@ module Redcarpet
7
9
  @table_num = 0
8
10
  @table_id_prefix = "tbl"
9
11
  @header_offset = 0
12
+ @link_in_footnote = render_extensions[:link_in_footnote]
13
+ @image_caption = !render_extensions[:disable_image_caption]
10
14
  if render_extensions[:header_offset]
11
15
  @header_offset = render_extensions[:header_offset]
12
16
  end
17
+ @links = {}
13
18
  end
14
19
 
15
20
  def normal_text(text)
@@ -69,6 +74,12 @@ module Redcarpet
69
74
  "\n=== #{title}\n"
70
75
  when 4
71
76
  "\n==== #{title}\n"
77
+ when 5
78
+ "\n===== #{title}\n"
79
+ when 6
80
+ "\n====== #{title}\n"
81
+ else
82
+ raise "too long header"
72
83
  end
73
84
  end
74
85
 
@@ -95,7 +106,11 @@ module Redcarpet
95
106
 
96
107
  def image(link, title, alt_text)
97
108
  filename = File.basename(link,".*")
98
- "//image[#{filename}][#{alt_text}]{\n//}\n"
109
+ if @image_caption
110
+ "//image[#{filename}][#{alt_text}]{\n//}\n"
111
+ else
112
+ "//indepimage[#{filename}]\n"
113
+ end
99
114
  end
100
115
 
101
116
  def autolink(link, link_type)
@@ -103,7 +118,13 @@ module Redcarpet
103
118
  end
104
119
 
105
120
  def link(link, title, content)
106
- "@<href>{#{escape_href(link)},#{escape_inline(content)}}"
121
+ if @link_in_footnote
122
+ key = Digest::MD5.hexdigest(link)
123
+ @links[key] ||= link
124
+ footnotes(content) + footnote_ref(key)
125
+ else
126
+ "@<href>{#{escape_href(link)},#{escape_inline(content)}}"
127
+ end
107
128
  end
108
129
 
109
130
  def double_emphasis(text)
@@ -149,6 +170,9 @@ module Redcarpet
149
170
  end
150
171
 
151
172
  def list_item(content, list_type)
173
+ content.gsub!(%r<\n//(image|indepimage)\[([^\]]*?)\][^\{]*({\n//})?\n>){
174
+ "@<icon>{"+$2+"}\n"
175
+ }
152
176
  case list_type
153
177
  when :ordered
154
178
  item = content.gsub(/\n(\s+[^0-9])/){$1}.gsub(/\n(\s+[0-9]+[^.])/){$1}.strip
@@ -176,14 +200,18 @@ module Redcarpet
176
200
  def footnote_ref(number)
177
201
  "@<fn>{#{number}}"
178
202
  end
203
+
179
204
  def footnotes(text)
180
205
  "#{text}"
181
206
  end
182
207
 
183
208
  def footnote_def(text,number)
184
- "\n//footnote[#{number}][#{escape_inline(text).strip}]\n"
209
+ "\n//footnote[#{number}][#{text.strip}]\n"
185
210
  end
186
211
 
212
+ def postprocess(text)
213
+ text + @links.map { |key, link| footnote_def(link, key) }.join
214
+ end
187
215
  end
188
216
  end
189
217
  end
data/md2review.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["takahashimm@gmail.com"]
11
11
  gem.description = %q{a converter from Markdown to Re:VIEW. It uses redcarpet.}
12
12
  gem.summary = %q{a converter from Markdown to Re:VIEW}
13
- gem.homepage = ""
13
+ gem.homepage = 'https://github.com/takahashim/md2review'
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -18,4 +18,5 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
  gem.add_dependency('redcarpet', '>2.0.0')
20
20
  gem.add_development_dependency "rake"
21
+ gem.add_development_dependency "test-unit"
21
22
  end
data/test/review_test.rb CHANGED
@@ -16,8 +16,9 @@ class ReVIEWTest < Test::Unit::TestCase
16
16
  @markdown = Redcarpet::Markdown.new(Redcarpet::Render::ReVIEW.new({}))
17
17
  end
18
18
 
19
- def render_with(flags, text)
20
- Redcarpet::Markdown.new(Redcarpet::Render::ReVIEW, flags).render(text)
19
+ def render_with(flags, text, render_flags = {})
20
+ renderer = Redcarpet::Render::ReVIEW.new(render_flags)
21
+ Redcarpet::Markdown.new(renderer, flags).render(text)
21
22
  end
22
23
 
23
24
  def test_that_simple_one_liner_goes_to_review
@@ -35,11 +36,31 @@ class ReVIEWTest < Test::Unit::TestCase
35
36
  assert_equal "\n\n@<href>{http://exmaple.com/foo\\,bar,example}\n\n", @markdown.render("[example](http://exmaple.com/foo,bar)")
36
37
  end
37
38
 
39
+ def test_href_in_footnote
40
+ text = %Q[aaa [foo](http://example.jp/foo), [bar](http://example.jp/bar), [foo2](http://example.jp/foo)]
41
+ rd = Redcarpet::Markdown.new(Redcarpet::Render::ReVIEW.new({:link_in_footnote => true})).render(text)
42
+ assert_equal %Q|\n\naaa foo@<fn>{3ccd7167b80081c737b749ad1c27dcdc}, bar@<fn>{9dcab303478e38d32d83ae19daaea9f6}, foo2@<fn>{3ccd7167b80081c737b749ad1c27dcdc}\n\n\n//footnote[3ccd7167b80081c737b749ad1c27dcdc][http://example.jp/foo]\n\n//footnote[9dcab303478e38d32d83ae19daaea9f6][http://example.jp/bar]\n|, rd
43
+ end
44
+
38
45
  def test_header
39
46
  assert_respond_to @markdown, :render
40
47
  assert_equal "\n= AAA\n\n\nBBB\n\n\n== ccc\n\n\nddd\n\n", @markdown.render("#AAA\nBBB\n\n##ccc\n\nddd\n")
41
48
  end
42
49
 
50
+ def test_header56
51
+ assert_respond_to @markdown, :render
52
+ assert_equal "\n===== AAA\n\n\nBBB\n\n\n====== ccc\n\n\nddd\n\n", @markdown.render("#####AAA\nBBB\n\n######ccc\n\nddd\n")
53
+ end
54
+
55
+ def test_image
56
+ assert_equal "\n\n//image[image][test]{\n//}\n\n\n", @markdown.render("![test](path/to/image.jpg)\n")
57
+ end
58
+
59
+ def test_indepimage
60
+ rev = render_with({}, "![test](path/to/image.jpg)\n",{:disable_image_caption => true})
61
+ assert_equal "\n\n//indepimage[image]\n\n\n", rev
62
+ end
63
+
43
64
  def test_nested_ulist
44
65
  assert_equal " * aaa\n ** bbb\n * ccc\n", @markdown.render("- aaa\n - bbb\n- ccc\n")
45
66
  end
@@ -53,6 +74,14 @@ class ReVIEWTest < Test::Unit::TestCase
53
74
  assert_equal " 1. aaa\n 1. bbb\n 1. ccc\n", @markdown.render("1. aaa\n 2. bbb\n3. ccc\n")
54
75
  end
55
76
 
77
+ def test_olist_image
78
+ assert_equal " 1. aaa@<icon>{foo}\n 1. bbb\n 1. ccc\n", @markdown.render("1. aaa\n ![test](foo.jpg)\n2. bbb\n3. ccc\n")
79
+ end
80
+
81
+ def test_olist_image2
82
+ assert_equal " 1. aaa@<br>{}@<icon>{foo}\n 1. bbb\n 1. ccc\n", @markdown.render("1. aaa \n ![test](foo.jpg)\n2. bbb\n3. ccc\n")
83
+ end
84
+
56
85
  def test_code_fence_with_caption
57
86
  rd = render_with({:fenced_code_blocks => true}, %Q[~~~ {caption="test"}\ndef foo\n p "test"\nend\n~~~\n])
58
87
  assert_equal %Q[\n//emlist[test]{\ndef foo\n p "test"\nend\n//}\n], rd
@@ -74,7 +103,7 @@ class ReVIEWTest < Test::Unit::TestCase
74
103
  end
75
104
 
76
105
  def test_footnote
77
- rd = render_with({:footnotes=>true}, "これは脚注付き[^1]の段落です。\n\n\n[^1]: そして、これが脚注です。\n")
78
- assert_equal %Q|\n\nこれは脚注付き@<fn>{1}の段落です。\n\n\n//footnote[1][そして、これが脚注です。]\n|, rd
106
+ rd = render_with({:footnotes=>true}, "これは*脚注*付き[^1]の段落です。\n\n\n[^1]: そして、これが脚注です。\n")
107
+ assert_equal %Q|\n\nこれは@<b>{脚注}付き@<fn>{1}の段落です。\n\n\n//footnote[1][そして、これが脚注です。]\n|, rd
79
108
  end
80
109
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md2review
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - takahashim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redcarpet
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
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'
41
55
  description: a converter from Markdown to Re:VIEW. It uses redcarpet.
42
56
  email:
43
57
  - takahashimm@gmail.com
@@ -58,7 +72,7 @@ files:
58
72
  - lib/redcarpet/render/review.rb
59
73
  - md2review.gemspec
60
74
  - test/review_test.rb
61
- homepage: ''
75
+ homepage: https://github.com/takahashim/md2review
62
76
  licenses: []
63
77
  metadata: {}
64
78
  post_install_message:
@@ -77,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
91
  version: '0'
78
92
  requirements: []
79
93
  rubyforge_project:
80
- rubygems_version: 2.2.2
94
+ rubygems_version: 2.4.5
81
95
  signing_key:
82
96
  specification_version: 4
83
97
  summary: a converter from Markdown to Re:VIEW