Skip to content

Commit a0a7353

Browse files
committed
accept .convert method call without options
1 parent 52760d4 commit a0a7353

4 files changed

Lines changed: 150 additions & 23 deletions

File tree

lib/markdown_it_ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ def self.convert(input, **options)
1010
options.transform_keys!(&:to_s)
1111
options.transform_values!(&:to_s)
1212

13-
__convert(input, **options)
13+
__convert(input, options)
1414
end
1515
end
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<h2>タイトル1</h2>
2+
<p>hello world</p>
3+
<h2>タイトル2</h2>
4+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
5+
<h3>タイトル2-1</h3>
6+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
7+
ジョバンニは思わずかけよって博士の前に立って、ぼくはカムパネルラの行った方を知っていますぼくはカムパネルラといっしょに歩いていたのですと云おうとしましたがもうのどがつまって何とも云えませんでした。すると博士はジョバンニが挨拶あいさつに来たとでも思ったものですか、しばらくしげしげジョバンニを見ていましたが「あなたはジョバンニさんでしたね。どうも今晩はありがとう。」と叮ていねいに云いました。ジョバンニは何も云えずにただおじぎをしました。</p>
8+
<p><a href="https://www.city.fuji.shizuoka.jp" target="_blank" rel="noopener noreferrer">リンク 1</a>
9+
<a href="htts:/www.city.fuji.shizuoka.jp" target="_blank" rel="noopener noreferrer">リンク 2</a>
10+
<a href="https://www.google.com" target="_blank" rel="noopener noreferrer">リンク 3</a>
11+
<a href="https://google.com" target="_blank" rel="noopener noreferrer">リンク 4</a>
12+
<a href="/foo/bar/hoge.pdf" target="_blank" rel="noopener noreferrer">リンク 5</a>
13+
<a href="/foo/bar/1234" target="_blank" rel="noopener noreferrer">リンク 6</a>
14+
<a href="google.com/foo/bar" target="_blank" rel="noopener noreferrer">リンク 7</a>
15+
foobar <img src="https://www.city.fuji.shizuoka.jp/page/gazou/fmervo000001dsro-att/1226-0009big.jpg" alt="画像タイトル"> baz</p>
16+
<div> HTML tag is here </div>
17+
<p>[[foo bar]]</p>
18+
<blockquote>
19+
<p>吾輩は猫である。名前はまだ無い。
20+
どこで生れたかとんと見当がつかぬ。
21+
<a href="https://www.city.fuji.shizuoka.jp" target="_blank" rel="noopener noreferrer">hoge</a>
22+
<cite>夏目漱石</cite></p>
23+
</blockquote>
24+
<h3>タイトル2-2</h3>
25+
<ul>
26+
<li>lorem ipsum 雨ニモ負ケズ 1
27+
<ul>
28+
<li>lorem ipsum 雨ニモ負ケズ 0-1</li>
29+
<li>lorem ipsum 雨ニモ負ケズ 1-2</li>
30+
</ul>
31+
</li>
32+
<li>lorem ipsum 雨ニモ負ケズ 2</li>
33+
<li>lorem ipsum 雨ニモ負ケズ 3</li>
34+
</ul>
35+
<ol>
36+
<li>lorem ipsum 雨ニモ負ケズ 1</li>
37+
<li>lorem ipsum 雨ニモ負ケズ 2</li>
38+
<li>lorem ipsum 雨ニモ負ケズ 3</li>
39+
</ol>
40+
<h4>タイトル2-2-1</h4>
41+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
42+
ジョバンニは思わずかけよって博士の前に立って、ぼくはカムパネルラの行った方を知っていますぼくはカムパネルラといっしょに歩いていたのですと云おうとしましたがもうのどがつまって何とも云えませんでした。すると博士はジョバンニが挨拶あいさつに来たとでも思ったものですか、しばらくしげしげジョバンニを見ていましたが「あなたはジョバンニさんでしたね。どうも今晩はありがとう。」と叮ていねいに云いました。ジョバンニは何も云えずにただおじぎをしました。</p>
43+
<h2>タイトル3</h2>
44+
<p>こんにちは
45+
<s>これは間違いです</s> (strike-through is not supported)</p>
46+
<table class="table">
47+
<thead>
48+
<tr>
49+
<th style="text-align:left">title</th>
50+
<th style="text-align:right">title</th>
51+
<th style="text-align:center">title</th>
52+
</tr>
53+
</thead>
54+
<tbody>
55+
<tr>
56+
<td style="text-align:left">This</td>
57+
<td style="text-align:right">This</td>
58+
<td style="text-align:center">This</td>
59+
</tr>
60+
<tr>
61+
<td style="text-align:left">column</td>
62+
<td style="text-align:right">column</td>
63+
<td style="text-align:center">column</td>
64+
</tr>
65+
<tr>
66+
<td style="text-align:left">will</td>
67+
<td style="text-align:right">will</td>
68+
<td style="text-align:center">will</td>
69+
</tr>
70+
<tr>
71+
<td style="text-align:left">be</td>
72+
<td style="text-align:right">be</td>
73+
<td style="text-align:center">be</td>
74+
</tr>
75+
<tr>
76+
<td style="text-align:left">left</td>
77+
<td style="text-align:right">right</td>
78+
<td style="text-align:center">center</td>
79+
</tr>
80+
<tr>
81+
<td style="text-align:left">ali<br/>gned</td>
82+
<td style="text-align:right">aligned</td>
83+
<td style="text-align:center">aligned</td>
84+
</tr>
85+
<tr>
86+
<td style="text-align:left">will</td>
87+
<td style="text-align:right">will</td>
88+
<td style="text-align:center"><strong>太字 bold here</strong> <a href="google.com" target="_blank" rel="noopener noreferrer">hoge</a></td>
89+
</tr>
90+
</tbody>
91+
</table>
92+
<h2>タイトル4</h2>
93+
<p>contents here</p>
94+
<h4>4-1-1</h4>
95+
<p>another sentence here</p>
96+
<h2>タイトル5</h2>
97+
<p>++some irrelevant markdown-like charactors++ 無関係な記号 1
98+
<strong>emphasis on here</strong> 強調する部分</p>
99+
<p>==another irrelevant markdown-like charactors== 無関係な記号 2</p>
100+
<h1>タイトル6-h1</h1>
101+
<h2>タイトル6-h2</h2>
102+
<h3>タイトル6-h3</h3>
103+
<h4>タイトル6-h4</h4>
104+
<h5>タイトル6-h5</h5>
105+
<h6>タイトル6-h6</h6>

spec/fixtures/dummy_output.html renamed to spec/fixtures/dummy_output_with_options.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ <h6>タイトル2-2-1</h6>
4343
<h4>タイトル3</h4>
4444
<p>こんにちは
4545
<s>これは間違いです</s> (strike-through is not supported)</p>
46-
<div class="table-class">
47-
<table>
46+
<table class="table-class">
4847
<thead>
4948
<tr>
5049
<th style="text-align:left">title</th>
@@ -90,7 +89,6 @@ <h4>タイトル3</h4>
9089
</tr>
9190
</tbody>
9291
</table>
93-
</div>
9492
<h4>タイトル4</h4>
9593
<p>contents here</p>
9694
<h6>4-1-1</h6>

spec/markdown_it_ruby_spec.rb

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,55 @@
66
end
77

88
describe 'MarkdownIt.convert' do
9-
subject { described_class.convert(input, **options) }
10-
11-
let(:input) { "## title 1\nsome random markdown" }
12-
let(:options) {
13-
{
14-
internal_domain_name: 'https://example.com',
15-
heading_level_offset: 2,
16-
table_class_name: 'table-class',
9+
let(:input) { "# title 1\nsome random markdown" }
10+
11+
context 'with options' do
12+
subject { described_class.convert(input, **options) }
13+
14+
let(:options) {
15+
{
16+
internal_domain_name: 'https://example.com',
17+
heading_level_offset: 2,
18+
table_class_name: 'table-class',
19+
}
1720
}
18-
}
1921

20-
it 'returns a string' do
21-
expect(subject).to be_a(String)
22-
end
22+
it 'returns a string' do
23+
expect(subject).to be_a(String)
24+
end
25+
26+
it 'converts markdown to html' do
27+
expect(subject).to match(%r{\A<h3>title 1</h3>\n<p>some random markdown</p>\n\z})
28+
end
29+
30+
context 'with fixtures' do
31+
let(:input) { File.read('spec/fixtures/dummy_input.md') }
32+
let(:expected_output) { File.read('spec/fixtures/dummy_output_with_options.html') }
2333

24-
it 'converts markdown to html' do
25-
expect(subject).to match(%r{\A<h4>title 1</h4>\n<p>some random markdown</p>\n\z})
34+
it 'converts markdown content to html' do
35+
expect(subject).to eq(expected_output)
36+
end
37+
end
2638
end
2739

28-
context 'with fixtures' do
29-
let(:input) { File.read('spec/fixtures/dummy_input.md') }
30-
let(:expected_output) { File.read('spec/fixtures/dummy_output.html') }
40+
context 'without options' do
41+
subject { described_class.convert(input) }
42+
43+
it 'returns a string' do
44+
expect(subject).to be_a(String)
45+
end
46+
47+
it 'converts markdown to html' do
48+
expect(subject).to match(%r{\A<h1>title 1</h1>\n<p>some random markdown</p>\n\z})
49+
end
50+
51+
context 'with fixtures' do
52+
let(:input) { File.read('spec/fixtures/dummy_input.md') }
53+
let(:expected_output) { File.read('spec/fixtures/dummy_output_default.html') }
3154

32-
it 'converts markdown content to html' do
33-
expect(subject).to eq(expected_output)
55+
it 'converts markdown content to html' do
56+
expect(subject).to eq(expected_output)
57+
end
3458
end
3559
end
3660
end

0 commit comments

Comments
 (0)