md2review 1.8.0 → 1.9.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/md2review/version.rb +1 -1
- data/lib/redcarpet/render/review.rb +30 -3
- data/test/review_test.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1044d852345e611794a38f4bc2cd8053f668c8a
|
4
|
+
data.tar.gz: 9f0343040dcb3e15a05ac4830b13a5eb828cf946
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a14a611b1e9349247fa8a66ac4e0357022754c0b879245a74caad1b8251571aebfdf8c253bd294f8f22536ef1710440ba135cb5f558d99e727add5ebc8dafb53
|
7
|
+
data.tar.gz: 1d2db2f93a8a6b47fc00d0c1006613b6d627d4732dea754635682cf222bd677b243d47b5d6ba63056af85fadcefadab3e312070c2d044d3bbc408781967ee904
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/takahashim/md2review)
|
4
4
|
|
5
|
-
md2review is a
|
5
|
+
md2review is a CLI tool to convert from Markdown into Re:VIEW (http://reviewml.org/ ).
|
6
6
|
This command uses Redcarpet gem to parse markdown.
|
7
7
|
|
8
8
|
## Installation
|
data/lib/md2review/version.rb
CHANGED
@@ -19,6 +19,21 @@ module Redcarpet
|
|
19
19
|
@support_table_caption = render_extensions[:table_caption]
|
20
20
|
@table_caption = nil
|
21
21
|
@math = render_extensions[:math]
|
22
|
+
@math_buf = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def preprocess(text)
|
26
|
+
counter = -1
|
27
|
+
if @math
|
28
|
+
while %r|\$\$(.+?)\$\$| =~ text
|
29
|
+
text.sub!(%r|\$\$(.+?)\$\$|) do
|
30
|
+
counter += 1
|
31
|
+
@math_buf[counter] = $1
|
32
|
+
"〓MATH:#{counter}:〓"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
text
|
22
37
|
end
|
23
38
|
|
24
39
|
def normal_text(text)
|
@@ -26,7 +41,19 @@ module Redcarpet
|
|
26
41
|
end
|
27
42
|
|
28
43
|
def escape_inline(text)
|
29
|
-
|
44
|
+
## } -> \}
|
45
|
+
## \} -> \\\}
|
46
|
+
## .} -> .\}
|
47
|
+
text.gsub(/(.)?}/) do
|
48
|
+
if $1 == '\\'
|
49
|
+
replaced = '\\\\\\}'
|
50
|
+
elsif $1
|
51
|
+
replaced = $1 + '\\}'
|
52
|
+
else
|
53
|
+
replaced = '\\}'
|
54
|
+
end
|
55
|
+
replaced
|
56
|
+
end
|
30
57
|
end
|
31
58
|
|
32
59
|
def escape_href(text)
|
@@ -249,8 +276,8 @@ module Redcarpet
|
|
249
276
|
def postprocess(text)
|
250
277
|
text = text.gsub(%r|^[ \t]+(//image\[[^\]]+\]\[[^\]]+\]{$\n^//})|, '\1')
|
251
278
|
if @math
|
252
|
-
while %r
|
253
|
-
text.sub!(%r
|
279
|
+
while %r|〓MATH:(\d+):〓| =~ text
|
280
|
+
text.sub!(%r|〓MATH:(\d+):〓|){ "@<m>{" + escape_inline(@math_buf[$1.to_i]) + "}" }
|
254
281
|
end
|
255
282
|
end
|
256
283
|
text + @links.map { |key, link| footnote_def(link, key) }.join
|
data/test/review_test.rb
CHANGED
@@ -179,6 +179,29 @@ EOB
|
|
179
179
|
assert_equal %Q[\n\nその結果、@<m>{y=ax^2+bx+c}の式が得られます。\n\n], rd
|
180
180
|
end
|
181
181
|
|
182
|
+
def test_multi_math
|
183
|
+
rd = render_with({}, "その結果、$$y=a_2x^2+b_2x+c_2$$の式が得られます。$$a_2$$は2次の係数、$$b_2$$は1次の係数、$$c_2$$は定数です。",{:math => true})
|
184
|
+
assert_equal %Q[\n\nその結果、@<m>{y=a_2x^2+b_2x+c_2}の式が得られます。@<m>{a_2}は2次の係数、@<m>{b_2}は1次の係数、@<m>{c_2}は定数です。\n\n], rd
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_math2
|
188
|
+
rd = render_with({}, <<-'EOB',{:math => true})
|
189
|
+
$$X = \{ {x_1}, \cdots ,{x_n} \}$$、$$m$$、$${\mu _X}$$、$$\sigma _X^2$$、$$\{ {\hat x_1}, \cdots ,{\hat x_n} \}$$
|
190
|
+
|
191
|
+
$$\mathbf{W} = ({w_1}, \cdots ,{w_n})$$、$$\sqrt {w_1^2 + \cdots + w_n^2} $$、$$\left| {w_1^{}} \right| + \left| {w_2^{}} \right| + \cdots + \left| {w_n^{}} \right|$$。
|
192
|
+
EOB
|
193
|
+
assert_equal <<-'EOB', rd
|
194
|
+
|
195
|
+
|
196
|
+
@<m>{X = \{ {x_1\}, \cdots ,{x_n\} \\\}}、@<m>{m}、@<m>{{\mu _X\}}、@<m>{\sigma _X^2}、@<m>{\{ {\hat x_1\}, \cdots ,{\hat x_n\} \\\}}
|
197
|
+
|
198
|
+
|
199
|
+
|
200
|
+
@<m>{\mathbf{W\} = ({w_1\}, \cdots ,{w_n\})}、@<m>{\sqrt {w_1^2 + \cdots + w_n^2\} }、@<m>{\left| {w_1^{\}\} \right| + \left| {w_2^{\}\} \right| + \cdots + \left| {w_n^{\}\} \right|}。
|
201
|
+
|
202
|
+
EOB
|
203
|
+
end
|
204
|
+
|
182
205
|
def test_no_math
|
183
206
|
rd = render_with({}, "その結果、$$y=ax^2+bx+c$$の式が得られます。",{:math => false})
|
184
207
|
assert_equal %Q[\n\nその結果、$$y=ax^2+bx+c$$の式が得られます。\n\n], rd
|
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.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takahashim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|