kramdown-man 0.1.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -3
- data/.yardopts +1 -1
- data/ChangeLog.md +55 -0
- data/Gemfile +6 -3
- data/README.md +152 -54
- data/bin/kramdown-man +3 -12
- data/lib/kramdown/man/cli.rb +202 -0
- data/lib/kramdown/{converter/man.rb → man/converter.rb} +318 -87
- data/lib/kramdown/man/task.rb +1 -1
- data/lib/kramdown/man/version.rb +1 -1
- data/lib/kramdown/man.rb +26 -3
- data/man/kramdown-man.1 +191 -110
- data/man/kramdown-man.1.md +90 -32
- data/spec/cli_spec.rb +218 -0
- data/spec/converter_spec.rb +969 -0
- data/spec/{document_spec.rb → integration_spec.rb} +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +7 -5
- data/spec/converter/man_spec.rb +0 -579
@@ -11,7 +11,7 @@ describe Kramdown::Document, :integration do
|
|
11
11
|
|
12
12
|
describe "#to_man" do
|
13
13
|
it "must return the same output as Kramdown::Converter::Man" do
|
14
|
-
output, warnings = Kramdown::Converter
|
14
|
+
output, warnings = Kramdown::Man::Converter.convert(subject.root)
|
15
15
|
|
16
16
|
expect(subject.to_man).to be == output
|
17
17
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kramdown-man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kramdown
|
@@ -61,14 +61,16 @@ files:
|
|
61
61
|
- bin/kramdown-man
|
62
62
|
- gemspec.yml
|
63
63
|
- kramdown-man.gemspec
|
64
|
-
- lib/kramdown/converter/man.rb
|
65
64
|
- lib/kramdown/man.rb
|
65
|
+
- lib/kramdown/man/cli.rb
|
66
|
+
- lib/kramdown/man/converter.rb
|
66
67
|
- lib/kramdown/man/task.rb
|
67
68
|
- lib/kramdown/man/version.rb
|
68
69
|
- man/kramdown-man.1
|
69
70
|
- man/kramdown-man.1.md
|
70
|
-
- spec/
|
71
|
-
- spec/
|
71
|
+
- spec/cli_spec.rb
|
72
|
+
- spec/converter_spec.rb
|
73
|
+
- spec/integration_spec.rb
|
72
74
|
- spec/man_spec.rb
|
73
75
|
- spec/spec_helper.rb
|
74
76
|
homepage: https://github.com/postmodern/kramdown-man#readme
|
data/spec/converter/man_spec.rb
DELETED
@@ -1,579 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
# HACK: load our version of kramdown/converter/man.rb and not kramdown's
|
4
|
-
require_relative '../../lib/kramdown/converter/man'
|
5
|
-
|
6
|
-
describe Kramdown::Converter::Man do
|
7
|
-
let(:markdown) { File.read('man/kramdown-man.1.md') }
|
8
|
-
let(:doc) { Kramdown::Document.new(markdown) }
|
9
|
-
let(:root) { doc.root }
|
10
|
-
|
11
|
-
subject { described_class.send(:new,root,{}) }
|
12
|
-
|
13
|
-
describe "#convert" do
|
14
|
-
let(:doc) do
|
15
|
-
Kramdown::Document.new(%{
|
16
|
-
# Header
|
17
|
-
|
18
|
-
Hello world.
|
19
|
-
}.strip)
|
20
|
-
end
|
21
|
-
let(:root) { doc.root }
|
22
|
-
|
23
|
-
it "should add the header" do
|
24
|
-
expect(subject.convert(root)).to eq([
|
25
|
-
described_class::HEADER,
|
26
|
-
".TH Header",
|
27
|
-
".LP",
|
28
|
-
".PP",
|
29
|
-
'Hello world\.'
|
30
|
-
].join("\n"))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#convert_root" do
|
35
|
-
let(:doc) do
|
36
|
-
Kramdown::Document.new(%{
|
37
|
-
# Header
|
38
|
-
|
39
|
-
Hello world.
|
40
|
-
}.strip)
|
41
|
-
end
|
42
|
-
|
43
|
-
let(:root) { doc.root }
|
44
|
-
|
45
|
-
it "should convert every element" do
|
46
|
-
expect(subject.convert_root(root)).to eq([
|
47
|
-
".TH Header",
|
48
|
-
".LP",
|
49
|
-
".PP",
|
50
|
-
'Hello world\.'
|
51
|
-
].join("\n"))
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "#convert_element" do
|
56
|
-
let(:doc) { Kramdown::Document.new(" puts 'hello'") }
|
57
|
-
let(:el) { doc.root.children[0] }
|
58
|
-
|
59
|
-
it "should convert the element based on it's type" do
|
60
|
-
expect(subject.convert_element(el)).to eq(subject.convert_codeblock(el))
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "#convert_blank" do
|
65
|
-
let(:doc) { Kramdown::Document.new("foo\n\nbar") }
|
66
|
-
let(:blank) { doc.root.children[0].children[1] }
|
67
|
-
|
68
|
-
it "should convert blank elements to '.LP'" do
|
69
|
-
expect(subject.convert_blank(blank)).to eq('.LP')
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "#convert_text" do
|
74
|
-
let(:content) { 'Foo bar' }
|
75
|
-
let(:doc) { Kramdown::Document.new(content) }
|
76
|
-
let(:text) { doc.root.children[0].children[0] }
|
77
|
-
|
78
|
-
it "should convert text elements" do
|
79
|
-
expect(subject.convert_text(text)).to eq(content)
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when the text has two-space indentation" do
|
83
|
-
let(:content) { "Foo\n bar\n baz" }
|
84
|
-
|
85
|
-
it "should strip leading whitespace from each line" do
|
86
|
-
expect(subject.convert_text(text)).to eq(content.gsub("\n ","\n"))
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
context "when the text has tab indentation" do
|
91
|
-
let(:content) { "Foo\n\tbar\n\tbaz" }
|
92
|
-
|
93
|
-
it "should strip leading whitespace from each line" do
|
94
|
-
expect(subject.convert_text(text)).to eq(content.gsub("\n\t","\n"))
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "#convert_typographic_sym" do
|
100
|
-
context "ndash" do
|
101
|
-
let(:doc) { Kramdown::Document.new("-- foo") }
|
102
|
-
let(:sym) { doc.root.children[0].children[0] }
|
103
|
-
|
104
|
-
it "should convert ndash symbols back into '\-\-'" do
|
105
|
-
expect(subject.convert_typographic_sym(sym)).to eq("\\-\\-")
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
context "mdash" do
|
110
|
-
let(:doc) { Kramdown::Document.new("--- foo") }
|
111
|
-
let(:sym) { doc.root.children[0].children[0] }
|
112
|
-
|
113
|
-
it "should convert mdash symbols into '\[em]'" do
|
114
|
-
expect(subject.convert_typographic_sym(sym)).to eq('\[em]')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
context "hellip" do
|
119
|
-
let(:doc) { Kramdown::Document.new("... foo") }
|
120
|
-
let(:sym) { doc.root.children[0].children[0] }
|
121
|
-
|
122
|
-
it "should convert mdash symbols into '\\.\\.\\.'" do
|
123
|
-
expect(subject.convert_typographic_sym(sym)).to eq('\.\.\.')
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "laquo" do
|
128
|
-
let(:doc) { Kramdown::Document.new("<< foo") }
|
129
|
-
let(:sym) { doc.root.children[0].children[0] }
|
130
|
-
|
131
|
-
it "should convert mdash symbols into '\[Fo]'" do
|
132
|
-
expect(subject.convert_typographic_sym(sym)).to eq('\[Fo]')
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
context "raquo" do
|
137
|
-
let(:doc) { Kramdown::Document.new("foo >> bar") }
|
138
|
-
let(:sym) { doc.root.children[0].children[1] }
|
139
|
-
|
140
|
-
it "should convert mdash symbols into '\[Fc]'" do
|
141
|
-
expect(subject.convert_typographic_sym(sym)).to eq('\[Fc]')
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
context "laquo_space" do
|
146
|
-
let(:doc) { Kramdown::Document.new(" << foo") }
|
147
|
-
let(:sym) { doc.root.children[0].children[0] }
|
148
|
-
|
149
|
-
it "should convert mdash symbols into '\[Fo]'" do
|
150
|
-
expect(subject.convert_typographic_sym(sym)).to eq('\[Fo]')
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "raquo_space" do
|
155
|
-
let(:doc) { Kramdown::Document.new("foo >> bar") }
|
156
|
-
let(:sym) { doc.root.children[0].children[1] }
|
157
|
-
|
158
|
-
it "should convert mdash symbols into '\[Fc]'" do
|
159
|
-
expect(subject.convert_typographic_sym(sym)).to eq('\[Fc]')
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
describe "#convert_smart_quote" do
|
165
|
-
context "lsquo" do
|
166
|
-
let(:doc) { Kramdown::Document.new("'hello world'") }
|
167
|
-
let(:quote) { doc.root.children[0].children.first }
|
168
|
-
|
169
|
-
it "should convert lsquo quotes into '\[oq]'" do
|
170
|
-
expect(subject.convert_smart_quote(quote)).to eq('\[oq]')
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
context "rsquo" do
|
175
|
-
let(:doc) { Kramdown::Document.new("'hello world'") }
|
176
|
-
let(:quote) { doc.root.children[0].children.last }
|
177
|
-
|
178
|
-
it "should convert rsquo quotes into '\[cq]'" do
|
179
|
-
expect(subject.convert_smart_quote(quote)).to eq('\[cq]')
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
context "ldquo" do
|
184
|
-
let(:doc) { Kramdown::Document.new('"hello world"') }
|
185
|
-
let(:quote) { doc.root.children[0].children.first }
|
186
|
-
|
187
|
-
it "should convert lsquo quotes into '\[lq]'" do
|
188
|
-
expect(subject.convert_smart_quote(quote)).to eq('\[lq]')
|
189
|
-
end
|
190
|
-
end
|
191
|
-
|
192
|
-
context "rdquo" do
|
193
|
-
let(:doc) { Kramdown::Document.new('"hello world"') }
|
194
|
-
let(:quote) { doc.root.children[0].children.last }
|
195
|
-
|
196
|
-
it "should convert lsquo quotes into '\[rq]'" do
|
197
|
-
expect(subject.convert_smart_quote(quote)).to eq('\[rq]')
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
describe "#convert_header" do
|
203
|
-
context "when level is 1" do
|
204
|
-
let(:doc) { Kramdown::Document.new("# Header") }
|
205
|
-
let(:header) { doc.root.children[0] }
|
206
|
-
|
207
|
-
it "should convert level 1 headers into '.TH text'" do
|
208
|
-
expect(subject.convert_header(header)).to eq(".TH Header")
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
context "when level is 2" do
|
213
|
-
let(:doc) { Kramdown::Document.new("## Header") }
|
214
|
-
let(:header) { doc.root.children[0] }
|
215
|
-
|
216
|
-
it "should convert level 2 headers into '.SH text'" do
|
217
|
-
expect(subject.convert_header(header)).to eq(".SH Header")
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
context "when level is 3" do
|
222
|
-
let(:doc) { Kramdown::Document.new("### Header") }
|
223
|
-
let(:header) { doc.root.children[0] }
|
224
|
-
|
225
|
-
it "should convert level 2 headers into '.SS text'" do
|
226
|
-
expect(subject.convert_header(header)).to eq(".SS Header")
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
context "when level is 4 or greater" do
|
231
|
-
let(:doc) { Kramdown::Document.new("#### Header") }
|
232
|
-
let(:header) { doc.root.children[0] }
|
233
|
-
|
234
|
-
it "should convert level 2 headers into '.SS text'" do
|
235
|
-
expect(subject.convert_header(header)).to eq(".SS Header")
|
236
|
-
end
|
237
|
-
end
|
238
|
-
end
|
239
|
-
|
240
|
-
describe "#convert_hr" do
|
241
|
-
let(:doc) { Kramdown::Document.new('------------------------------------') }
|
242
|
-
let(:hr) { doc.root.children[0] }
|
243
|
-
|
244
|
-
it "should convert hr elements into '.ti 0\\n\\\\l'\\\\n(.lu\\''" do
|
245
|
-
expect(subject.convert_hr(hr)).to eq(".ti 0\n\\l'\\n(.lu'")
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
describe "#convert_ul" do
|
250
|
-
let(:text1) { 'foo' }
|
251
|
-
let(:text2) { 'bar' }
|
252
|
-
let(:doc) { Kramdown::Document.new("* #{text1}\n* #{text2}") }
|
253
|
-
let(:ul) { doc.root.children[0] }
|
254
|
-
|
255
|
-
it "should convert ul elements into '.RS\\n...\\n.RE'" do
|
256
|
-
expect(subject.convert_ul(ul)).to eq([
|
257
|
-
".RS",
|
258
|
-
".IP \\(bu 2",
|
259
|
-
text1,
|
260
|
-
".IP \\(bu 2",
|
261
|
-
text2,
|
262
|
-
".RE"
|
263
|
-
].join("\n"))
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
describe "#convert_ul_li" do
|
268
|
-
let(:text) { 'hello world' }
|
269
|
-
let(:doc) { Kramdown::Document.new("* #{text}") }
|
270
|
-
let(:li) { doc.root.children[0].children[0] }
|
271
|
-
|
272
|
-
it "should convert the first p element to '.IP \\\\(bu 2\\n...'" do
|
273
|
-
expect(subject.convert_ul_li(li)).to eq(".IP \\(bu 2\n#{text}")
|
274
|
-
end
|
275
|
-
|
276
|
-
context "with multiple multiple paragraphs" do
|
277
|
-
let(:text1) { 'hello' }
|
278
|
-
let(:text2) { 'world' }
|
279
|
-
let(:doc) { Kramdown::Document.new("* #{text1}\n\n #{text2}") }
|
280
|
-
|
281
|
-
it "should convert the other p elements to '.IP \\\\( 2\\n...'" do
|
282
|
-
expect(subject.convert_ul_li(li)).to eq([
|
283
|
-
".IP \\(bu 2",
|
284
|
-
text1,
|
285
|
-
".IP \\( 2",
|
286
|
-
text2
|
287
|
-
].join("\n"))
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
describe "#convert_ol" do
|
293
|
-
let(:text1) { 'foo' }
|
294
|
-
let(:text2) { 'bar' }
|
295
|
-
let(:doc) { Kramdown::Document.new("1. #{text1}\n2. #{text2}") }
|
296
|
-
let(:ol) { doc.root.children[0] }
|
297
|
-
|
298
|
-
it "should convert ol elements into '.RS\\n...\\n.RE'" do
|
299
|
-
expect(subject.convert_ol(ol)).to eq([
|
300
|
-
".nr step1 0 1",
|
301
|
-
".RS",
|
302
|
-
".IP \\n+[step1]",
|
303
|
-
text1,
|
304
|
-
".IP \\n+[step1]",
|
305
|
-
text2,
|
306
|
-
".RE"
|
307
|
-
].join("\n"))
|
308
|
-
end
|
309
|
-
end
|
310
|
-
|
311
|
-
describe "#convert_ol_li" do
|
312
|
-
let(:text) { 'hello world' }
|
313
|
-
let(:doc) { Kramdown::Document.new("1. #{text}") }
|
314
|
-
let(:li) { doc.root.children[0].children[0] }
|
315
|
-
|
316
|
-
it "should convert the first p element to '.IP \\\\n+[step0]\\n...'" do
|
317
|
-
expect(subject.convert_ol_li(li)).to eq(".IP \\n+[step0]\n#{text}")
|
318
|
-
end
|
319
|
-
|
320
|
-
context "with multiple multiple paragraphs" do
|
321
|
-
let(:text1) { 'hello' }
|
322
|
-
let(:text2) { 'world' }
|
323
|
-
let(:doc) { Kramdown::Document.new("1. #{text1}\n\n #{text2}") }
|
324
|
-
|
325
|
-
it "should convert the other p elements to '.IP \\\\n\\n...'" do
|
326
|
-
expect(subject.convert_ol_li(li)).to eq([
|
327
|
-
".IP \\n+[step0]",
|
328
|
-
text1,
|
329
|
-
".IP \\n",
|
330
|
-
text2
|
331
|
-
].join("\n"))
|
332
|
-
end
|
333
|
-
end
|
334
|
-
end
|
335
|
-
|
336
|
-
describe "#convert_abbreviation" do
|
337
|
-
let(:acronym) { 'HTML' }
|
338
|
-
let(:definition) { 'Hyper Text Markup Language' }
|
339
|
-
let(:doc) { Kramdown::Document.new("This is an #{acronym} example.\n\n*[#{acronym}]: #{definition}") }
|
340
|
-
let(:abbreviation) { doc.root.children[0].children[1] }
|
341
|
-
|
342
|
-
it "should convert abbreviation elements into their text" do
|
343
|
-
expect(subject.convert_abbreviation(abbreviation)).to eq(acronym)
|
344
|
-
end
|
345
|
-
end
|
346
|
-
|
347
|
-
describe "#convert_blockquote" do
|
348
|
-
let(:text) { "Some quote." }
|
349
|
-
let(:escaped_text) { 'Some quote\.' }
|
350
|
-
let(:doc) { Kramdown::Document.new("> #{text}") }
|
351
|
-
let(:blockquote) { doc.root.children[0] }
|
352
|
-
|
353
|
-
it "should convert blockquote elements into '.PP\\n.RS\\ntext...\\n.RE'" do
|
354
|
-
expect(subject.convert_blockquote(blockquote)).to eq(".PP\n.RS\n#{escaped_text}\n.RE")
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
describe "#convert_codeblock" do
|
359
|
-
let(:code) { "puts 'hello world'" }
|
360
|
-
let(:escaped_code) { 'puts \(aqhello world\(aq' }
|
361
|
-
let(:doc) { Kramdown::Document.new(" #{code}\n") }
|
362
|
-
let(:codeblock) { doc.root.children[0] }
|
363
|
-
|
364
|
-
it "should convert codeblock elements into '.nf\\ntext...\\n.fi'" do
|
365
|
-
expect(subject.convert_codeblock(codeblock)).to eq(".nf\n#{escaped_code}\n.fi")
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
describe "#convert_comment" do
|
370
|
-
let(:text) { "Copyright (c) 2013" }
|
371
|
-
let(:doc) { Kramdown::Document.new("{::comment}\n#{text}\n{:/comment}") }
|
372
|
-
let(:comment) { doc.root.children[0] }
|
373
|
-
|
374
|
-
it "should convert comment elements into '.\\\" text...'" do
|
375
|
-
expect(subject.convert_comment(comment)).to eq(".\\\" #{text}")
|
376
|
-
end
|
377
|
-
end
|
378
|
-
|
379
|
-
describe "#convert_p" do
|
380
|
-
let(:text) { "Hello world." }
|
381
|
-
let(:escaped_text) { 'Hello world\.' }
|
382
|
-
let(:doc) { Kramdown::Document.new(text) }
|
383
|
-
let(:p) { doc.root.children[0] }
|
384
|
-
|
385
|
-
it "should convert p elements into '.PP\\ntext'" do
|
386
|
-
expect(subject.convert_p(p)).to eq(".PP\n#{escaped_text}")
|
387
|
-
end
|
388
|
-
|
389
|
-
context "when the paragraph starts with a codespan element" do
|
390
|
-
let(:option) { '--foo' }
|
391
|
-
let(:text) { 'Foo bar baz' }
|
392
|
-
let(:doc) { Kramdown::Document.new("`#{option}`\n\t#{text}") }
|
393
|
-
|
394
|
-
it "should convert p elements into '.TP\\n\\fB--option\\fR\\ntext...'" do
|
395
|
-
expect(subject.convert_p(p)).to eq(".TP\n\\fB#{option}\\fR\n#{text}")
|
396
|
-
end
|
397
|
-
|
398
|
-
context "when there is only one codespan element" do
|
399
|
-
let(:code) { 'code' }
|
400
|
-
let(:doc) { Kramdown::Document.new("`#{code}`") }
|
401
|
-
|
402
|
-
it "should convert p elements into '.PP\\n\\fB...\\fR'" do
|
403
|
-
expect(subject.convert_p(p)).to eq(".PP\n\\fB#{code}\\fR")
|
404
|
-
end
|
405
|
-
end
|
406
|
-
|
407
|
-
context "when there are more than one codespan element" do
|
408
|
-
let(:flag) { '-f' }
|
409
|
-
let(:option) { '--foo' }
|
410
|
-
let(:text) { 'Foo bar baz' }
|
411
|
-
let(:doc) { Kramdown::Document.new("`#{flag}`, `#{option}`\n\t#{text}") }
|
412
|
-
|
413
|
-
it "should convert p elements into '.TP\\n\\fB-o\\fR, \\fB--option\\fR\\ntext...'" do
|
414
|
-
expect(subject.convert_p(p)).to eq(".TP\n\\fB#{flag}\\fR, \\fB#{option}\\fR\n#{text}")
|
415
|
-
end
|
416
|
-
|
417
|
-
context "when there is no newline" do
|
418
|
-
let(:doc) { Kramdown::Document.new("`#{flag}` `#{option}`") }
|
419
|
-
|
420
|
-
it "should convert the p element into a '.PP\\n...'" do
|
421
|
-
expect(subject.convert_p(p)).to eq(".PP\n\\fB#{flag}\\fR \\fB#{option}\\fR")
|
422
|
-
end
|
423
|
-
end
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
context "when the paragraph starts with a em element" do
|
428
|
-
let(:option) { '--foo' }
|
429
|
-
let(:escaped_option) { "\\-\\-foo" }
|
430
|
-
let(:text) { 'Foo bar baz' }
|
431
|
-
|
432
|
-
let(:doc) do
|
433
|
-
Kramdown::Document.new("*#{option}*\n\t#{text}")
|
434
|
-
end
|
435
|
-
|
436
|
-
it "should convert p elements into '.TP\\n\\fI--option\\fP\\ntext...'" do
|
437
|
-
expect(subject.convert_p(p)).to eq(".TP\n\\fI#{escaped_option}\\fP\n#{text}")
|
438
|
-
end
|
439
|
-
|
440
|
-
context "when there is only one em element" do
|
441
|
-
let(:text) { 'foo' }
|
442
|
-
let(:doc) { Kramdown::Document.new("*#{text}*") }
|
443
|
-
|
444
|
-
it "should convert p elements into '.PP\\n\\fI...\\fP'" do
|
445
|
-
expect(subject.convert_p(p)).to eq(".PP\n\\fI#{text}\\fP")
|
446
|
-
end
|
447
|
-
end
|
448
|
-
|
449
|
-
context "when there are more than one em element" do
|
450
|
-
let(:flag) { '-f' }
|
451
|
-
let(:escaped_flag) { "\\-f" }
|
452
|
-
let(:text) { 'Foo bar baz' }
|
453
|
-
|
454
|
-
let(:doc) do
|
455
|
-
Kramdown::Document.new("*#{flag}*, *#{option}*\n\t#{text}")
|
456
|
-
end
|
457
|
-
|
458
|
-
it "should convert p elements into '.TP\\n\\fI-o\\fP, \\fI\\-\\-option\\fP\\ntext...'" do
|
459
|
-
expect(subject.convert_p(p)).to eq(".TP\n\\fI#{escaped_flag}\\fP, \\fI#{escaped_option}\\fP\n#{text}")
|
460
|
-
end
|
461
|
-
|
462
|
-
context "when there is no newline" do
|
463
|
-
let(:doc) { Kramdown::Document.new("*#{flag}* *#{option}*") }
|
464
|
-
|
465
|
-
it "should convert the p element into a '.PP\\n...'" do
|
466
|
-
expect(subject.convert_p(p)).to eq(".PP\n\\fI#{escaped_flag}\\fP \\fI#{escaped_option}\\fP")
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|
471
|
-
end
|
472
|
-
|
473
|
-
describe "#convert_em" do
|
474
|
-
let(:text) { "hello world" }
|
475
|
-
let(:doc) { Kramdown::Document.new("*#{text}*") }
|
476
|
-
let(:em) { doc.root.children[0].children[0] }
|
477
|
-
|
478
|
-
it "should convert em elements into '\\fItext\\fP'" do
|
479
|
-
expect(subject.convert_em(em)).to eq("\\fI#{text}\\fP")
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
describe "#convert_strong" do
|
484
|
-
let(:text) { "hello world" }
|
485
|
-
let(:doc) { Kramdown::Document.new("**#{text}**") }
|
486
|
-
let(:strong) { doc.root.children[0].children[0] }
|
487
|
-
|
488
|
-
it "should convert strong elements into '\\fBtext\\fP'" do
|
489
|
-
expect(subject.convert_strong(strong)).to eq("\\fB#{text}\\fP")
|
490
|
-
end
|
491
|
-
end
|
492
|
-
|
493
|
-
describe "#convert_codespan" do
|
494
|
-
let(:code) { "puts 'hello world'" }
|
495
|
-
let(:doc) { Kramdown::Document.new("`#{code}`") }
|
496
|
-
let(:codespan) { doc.root.children[0].children[0] }
|
497
|
-
|
498
|
-
it "should convert codespan elements into '\\fBcode\\fR'" do
|
499
|
-
expect(subject.convert_codespan(codespan)).to eq("\\fB#{code}\\fR")
|
500
|
-
end
|
501
|
-
end
|
502
|
-
|
503
|
-
describe "#convert_a" do
|
504
|
-
let(:text) { 'example' }
|
505
|
-
let(:href) { 'http://example.com/' }
|
506
|
-
let(:escaped_href) { 'http:\[sl]\[sl]example\.com\[sl]' }
|
507
|
-
let(:doc) { Kramdown::Document.new("[#{text}](#{href})") }
|
508
|
-
let(:link) { doc.root.children[0].children[0] }
|
509
|
-
|
510
|
-
it "should convert a link elements into 'text\\n.UR href\\n.UE'" do
|
511
|
-
expect(subject.convert_a(link)).to eq("#{text}\n.UR #{escaped_href}\n.UE")
|
512
|
-
end
|
513
|
-
|
514
|
-
context "when the href begins with mailto:" do
|
515
|
-
let(:text) { 'Bob' }
|
516
|
-
let(:email) { 'bob@example.com' }
|
517
|
-
let(:escaped_email) { 'bob\[at]example\.com' }
|
518
|
-
let(:doc) { Kramdown::Document.new("[#{text}](mailto:#{email})") }
|
519
|
-
|
520
|
-
it "should convert the link elements into '.MT email\\n.ME'" do
|
521
|
-
expect(subject.convert_a(link)).to eq("#{text}\n.MT #{escaped_email}\n.ME")
|
522
|
-
end
|
523
|
-
|
524
|
-
context "when link is <email>" do
|
525
|
-
let(:doc) { Kramdown::Document.new("<#{email}>") }
|
526
|
-
|
527
|
-
it "should convert the link elements into '.MT email\\n.ME'" do
|
528
|
-
expect(subject.convert_a(link)).to eq("\n.MT #{escaped_email}\n.ME")
|
529
|
-
end
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
context "when the href begins with man:" do
|
534
|
-
let(:man) { 'bash' }
|
535
|
-
let(:doc) { Kramdown::Document.new("[#{man}](man:#{man})") }
|
536
|
-
|
537
|
-
it "should convert the link elements into '.BR man'" do
|
538
|
-
expect(subject.convert_a(link)).to eq("\n.BR #{man}")
|
539
|
-
end
|
540
|
-
|
541
|
-
context "and when the path is of the form 'page(section)'" do
|
542
|
-
let(:section) { '1' }
|
543
|
-
let(:doc) { Kramdown::Document.new("[#{man}](man:#{man}(#{section}))") }
|
544
|
-
|
545
|
-
it "should convert the link elements into '.BR page (section)'" do
|
546
|
-
expect(subject.convert_a(link)).to eq("\n.BR #{man} (#{section})")
|
547
|
-
end
|
548
|
-
end
|
549
|
-
|
550
|
-
context "and when the path is of the form 'page.section'" do
|
551
|
-
let(:section) { '1' }
|
552
|
-
let(:doc) { Kramdown::Document.new("[#{man}](man:#{man}.#{section})") }
|
553
|
-
|
554
|
-
it "should convert the link elements into '.BR page (section)'" do
|
555
|
-
expect(subject.convert_a(link)).to eq("\n.BR #{man} (#{section})")
|
556
|
-
end
|
557
|
-
end
|
558
|
-
|
559
|
-
context "when the path ends with a file extension" do
|
560
|
-
let(:file) { 'shard.yml' }
|
561
|
-
let(:doc) { Kramdown::Document.new("[#{man}](man:#{file})") }
|
562
|
-
|
563
|
-
it "should convert the link elements into '.BR file'" do
|
564
|
-
expect(subject.convert_a(link)).to eq("\n.BR #{file.gsub('.','\\.')}")
|
565
|
-
end
|
566
|
-
end
|
567
|
-
end
|
568
|
-
end
|
569
|
-
|
570
|
-
describe "#escape" do
|
571
|
-
let(:text) { "hello\nworld" }
|
572
|
-
|
573
|
-
described_class::GLYPHS.each do |char,glyph|
|
574
|
-
it "should convert #{char.dump} into #{glyph.dump}" do
|
575
|
-
expect(subject.escape("#{text} #{char}")).to eq("#{text} #{glyph}")
|
576
|
-
end
|
577
|
-
end
|
578
|
-
end
|
579
|
-
end
|