kramdown-man 0.1.3

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.
@@ -0,0 +1,70 @@
1
+ require 'kramdown'
2
+ require 'kramdown/converter/man'
3
+
4
+ require 'rake/tasklib'
5
+
6
+ module Kramdown
7
+ module Man
8
+ #
9
+ # Defines a `man` rake task that generates man-pages within the `man/`
10
+ # directory from `.md` files.
11
+ #
12
+ class Task < Rake::TaskLib
13
+
14
+ # Markdown file glob pattern
15
+ FILES = 'man/{**/}*.{markdown,mkd,md}'
16
+
17
+ # Additional options
18
+ #
19
+ # @return [Hash]
20
+ attr_reader :options
21
+
22
+ #
23
+ # Initializes the tasks.
24
+ #
25
+ # @param [Hash] options
26
+ # Additional options.
27
+ #
28
+ def initialize(options={})
29
+ @options = options
30
+ @markdown = FileList[FILES]
31
+ @man_pages = @markdown.pathmap('%X')
32
+
33
+ define
34
+ end
35
+
36
+ protected
37
+
38
+ #
39
+ # Defines the `man` tasks.
40
+ #
41
+ def define
42
+ desc 'Build UNIX manual pages from Markdown files in man/'
43
+ task 'man' => @man_pages
44
+
45
+ @markdown.zip(@man_pages).each do |markdown,man_page|
46
+ file(man_page => markdown) do
47
+ render(markdown,man_page)
48
+ end
49
+ end
50
+ end
51
+
52
+ #
53
+ # Renders a man_page from a markdown file.
54
+ #
55
+ # @param [String] markdown
56
+ # The path to the input markdown file.
57
+ #
58
+ # @param [String] man_page
59
+ # The path to the output man_page file.
60
+ #
61
+ def render(markdown,man_page)
62
+ doc = Kramdown::Document.new(File.read(markdown),@options)
63
+
64
+ File.open(man_page,'w') do |output|
65
+ output.write doc.to_man
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,6 @@
1
+ module Kramdown
2
+ module Man
3
+ # kramdown-man version
4
+ VERSION = "0.1.3"
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ require 'kramdown'
2
+
3
+ require 'kramdown/converter/man'
4
+ require 'kramdown/man/version'
@@ -0,0 +1,176 @@
1
+ .\" Generated by kramdown-man 0.1.0
2
+ .\" https://github.com/postmodern/kramdown-roff#readme
3
+ .TH kramdown-man.1 "April 2013" kramdown-man "User Manuals"
4
+ .LP
5
+ .SH DESCRIPTION
6
+ .LP
7
+ .PP
8
+ A Kramdown
9
+ .UR http://kramdown.rubyforge.org/
10
+ .UE convert for converting Markdown files into man pages.
11
+ .LP
12
+ .SH EXAMPLE
13
+ .LP
14
+ .nf
15
+ require 'kramdown'
16
+ require 'kramdown/man'
17
+
18
+ doc = Kramdown::Document.new(File.read('man/kramdown\-man.1.md'))
19
+ File.write('man/kramdown\-man.1',doc.to_man)
20
+ system 'man', 'man/kramdown\-man.1'
21
+ .fi
22
+ .LP
23
+ .SH SYNTAX
24
+ .LP
25
+ .SS FORMATTING
26
+ .LP
27
+ .nf
28
+ `code`
29
+ .fi
30
+ .LP
31
+ .PP
32
+ \fB\fCcode\fR
33
+ .LP
34
+ .nf
35
+ *emphasis*
36
+ .fi
37
+ .LP
38
+ .PP
39
+ \fIemphasis\fP
40
+ .LP
41
+ .nf
42
+ **strong**
43
+ .fi
44
+ .LP
45
+ .PP
46
+ \fBstrong\fP
47
+ .LP
48
+ .SS PARAGRAPHS
49
+ .LP
50
+ .nf
51
+ Normal paragraph.
52
+ .fi
53
+ .LP
54
+ .PP
55
+ Normal paragraph.
56
+ .LP
57
+ .nf
58
+ `\-\-tagged`
59
+ Text here.
60
+ .fi
61
+ .LP
62
+ .TP
63
+ \fB\fC--tagged\fR
64
+ Text here.
65
+ .LP
66
+ .SS LINKS
67
+ .LP
68
+ .nf
69
+ [website](http://example.com/)
70
+ .fi
71
+ .LP
72
+ .PP
73
+ website
74
+ .UR http://example.com/
75
+ .UE
76
+ .LP
77
+ .nf
78
+ [bash](man:bash(1))
79
+ .fi
80
+ .LP
81
+ .PP
82
+ .BR bash (1)
83
+ .LP
84
+ .nf
85
+ Email <bob@example.com>
86
+ .fi
87
+ .LP
88
+ .PP
89
+ Email
90
+ .MT bob@example.com
91
+ .ME
92
+ .LP
93
+ .SS LISTS
94
+ .LP
95
+ .nf
96
+ * one
97
+ * two
98
+ * three
99
+
100
+ extra paragraph
101
+ .fi
102
+ .LP
103
+ .RS
104
+ .IP \(bu 2
105
+ one
106
+ .IP \(bu 2
107
+ two
108
+ .IP \(bu 2
109
+ three
110
+ .IP \( 2
111
+ extra paragraph
112
+ .RE
113
+ .LP
114
+ .nr step1 0 1
115
+ .RS
116
+ .IP \n+[step1]
117
+ one
118
+ .IP \n+[step1]
119
+ two
120
+ .IP \n+[step1]
121
+ three
122
+ .IP \n
123
+ extra paragraph
124
+ .RE
125
+ .LP
126
+ .SS HORIZONTAL RULE
127
+ .LP
128
+ .nf
129
+ \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
130
+ .fi
131
+ .LP
132
+ .ti 0
133
+ \l'\n(.lu'
134
+ .LP
135
+ .SS BLOCKQUOTES
136
+ .LP
137
+ .nf
138
+ > Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
139
+ >
140
+ > \-\-Antoine de Saint\-Exupéry
141
+ .fi
142
+ .LP
143
+ .PP
144
+ .RS
145
+ Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
146
+ .LP
147
+ --Antoine de Saint\-Exupéry
148
+ .RE
149
+ .LP
150
+ .SS CODE BLOCKS
151
+ .LP
152
+ .nf
153
+ #include <stdio.h>
154
+
155
+ int main()
156
+ {
157
+ printf("hello world\\n");
158
+ return 0;
159
+ }
160
+
161
+ #include <stdio.h>
162
+
163
+ int main()
164
+ {
165
+ printf("hello world\\n");
166
+ return 0;
167
+ }
168
+ .fi
169
+ .LP
170
+ .SH AUTHOR
171
+ .LP
172
+ .PP
173
+ Postmodern
174
+ .MT postmodern.mod3@gmail.com
175
+ .ME
176
+ .LP
@@ -0,0 +1,123 @@
1
+ # kramdown-man.1 "April 2013" kramdown-man "User Manuals"
2
+
3
+ ## DESCRIPTION
4
+
5
+ A [Kramdown][kramdown] convert for converting Markdown files into man pages.
6
+
7
+ ## EXAMPLE
8
+
9
+ require 'kramdown'
10
+ require 'kramdown/man'
11
+
12
+ doc = Kramdown::Document.new(File.read('man/kramdown-man.1.md'))
13
+ File.write('man/kramdown-man.1',doc.to_man)
14
+ system 'man', 'man/kramdown-man.1'
15
+
16
+ ## SYNTAX
17
+
18
+ ### FORMATTING
19
+
20
+ `code`
21
+
22
+ `code`
23
+
24
+ *emphasis*
25
+
26
+ *emphasis*
27
+
28
+ **strong**
29
+
30
+ **strong**
31
+
32
+ ### PARAGRAPHS
33
+
34
+ Normal paragraph.
35
+
36
+ Normal paragraph.
37
+
38
+ `--tagged`
39
+ Text here.
40
+
41
+ `--tagged`
42
+ Text here.
43
+
44
+ ### LINKS
45
+
46
+ [website](http://example.com/)
47
+
48
+ [website](http://example.com/)
49
+
50
+ [bash](man:bash(1))
51
+
52
+ [bash](man:bash(1))
53
+
54
+ Email <bob@example.com>
55
+
56
+ Email <bob@example.com>
57
+
58
+ ### LISTS
59
+
60
+ * one
61
+ * two
62
+ * three
63
+
64
+ extra paragraph
65
+
66
+
67
+ * one
68
+ * two
69
+ * three
70
+
71
+ extra paragraph
72
+
73
+ 1. one
74
+ 2. two
75
+ 3. three
76
+
77
+ extra paragraph
78
+
79
+ 1. one
80
+ 2. two
81
+ 3. three
82
+
83
+ extra paragraph
84
+
85
+ ### HORIZONTAL RULE
86
+
87
+ -------------------------------------------------------------------------------
88
+
89
+ -------------------------------------------------------------------------------
90
+
91
+ ### BLOCKQUOTES
92
+
93
+ > Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
94
+ >
95
+ > --Antoine de Saint-Exupéry
96
+
97
+ > Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
98
+ >
99
+ > --Antoine de Saint-Exupéry
100
+
101
+ ### CODE BLOCKS
102
+
103
+ #include <stdio.h>
104
+
105
+ int main()
106
+ {
107
+ printf("hello world\n");
108
+ return 0;
109
+ }
110
+
111
+ #include <stdio.h>
112
+
113
+ int main()
114
+ {
115
+ printf("hello world\n");
116
+ return 0;
117
+ }
118
+
119
+ ## AUTHOR
120
+
121
+ Postmodern <postmodern.mod3@gmail.com>
122
+
123
+ [kramdown]: http://kramdown.rubyforge.org/
@@ -0,0 +1,479 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'kramdown/converter/man'
4
+
5
+ describe Kramdown::Converter::Man do
6
+ let(:markdown) { File.read('man/kramdown-man.1.md') }
7
+ let(:doc) { Kramdown::Document.new(markdown) }
8
+ let(:root) { doc.root }
9
+
10
+ subject { described_class.send(:new,root,{}) }
11
+
12
+ describe "#convert" do
13
+ let(:doc) do
14
+ Kramdown::Document.new(%{
15
+ # Header
16
+
17
+ Hello world.
18
+ }.strip)
19
+ end
20
+ let(:root) { doc.root }
21
+
22
+ it "should add the header" do
23
+ subject.convert(root).should == [
24
+ described_class::HEADER,
25
+ ".TH Header",
26
+ ".LP",
27
+ ".PP",
28
+ "Hello world."
29
+ ].join("\n")
30
+ end
31
+ end
32
+
33
+ describe "#convert_root" do
34
+ let(:doc) do
35
+ Kramdown::Document.new(%{
36
+ # Header
37
+
38
+ Hello world.
39
+ }.strip)
40
+ end
41
+
42
+ let(:root) { doc.root }
43
+
44
+ it "should convert every element" do
45
+ subject.convert_root(root).should == [
46
+ ".TH Header",
47
+ ".LP",
48
+ ".PP",
49
+ "Hello world."
50
+ ].join("\n")
51
+ end
52
+ end
53
+
54
+ describe "#convert_element" do
55
+ let(:doc) { Kramdown::Document.new(" puts 'hello'") }
56
+ let(:el) { doc.root.children[0] }
57
+
58
+ it "should convert the element based on it's type" do
59
+ subject.convert_element(el).should == subject.convert_codeblock(el)
60
+ end
61
+ end
62
+
63
+ describe "#convert_blank" do
64
+ let(:doc) { Kramdown::Document.new("foo\n\nbar") }
65
+ let(:blank) { doc.root.children[0].children[1] }
66
+
67
+ it "should convert blank elements to '.LP'" do
68
+ subject.convert_blank(blank).should == '.LP'
69
+ end
70
+ end
71
+
72
+ describe "#convert_text" do
73
+ let(:content) { 'Foo bar' }
74
+ let(:doc) { Kramdown::Document.new(content) }
75
+ let(:text) { doc.root.children[0].children[0] }
76
+
77
+ it "should convert text elements" do
78
+ subject.convert_text(text).should == content
79
+ end
80
+ end
81
+
82
+ describe "#convert_typographic_sym" do
83
+ context "ndash" do
84
+ let(:doc) { Kramdown::Document.new("-- foo") }
85
+ let(:sym) { doc.root.children[0].children[0] }
86
+
87
+ it "should convert ndash symbols back into '--'" do
88
+ subject.convert_typographic_sym(sym).should == '--'
89
+ end
90
+ end
91
+
92
+ context "mdash" do
93
+ let(:doc) { Kramdown::Document.new("--- foo") }
94
+ let(:sym) { doc.root.children[0].children[0] }
95
+
96
+ it "should convert mdash symbols into '—'" do
97
+ subject.convert_typographic_sym(sym).should == '—'
98
+ end
99
+ end
100
+
101
+ context "hellip" do
102
+ let(:doc) { Kramdown::Document.new("... foo") }
103
+ let(:sym) { doc.root.children[0].children[0] }
104
+
105
+ it "should convert mdash symbols into '…'" do
106
+ subject.convert_typographic_sym(sym).should == '…'
107
+ end
108
+ end
109
+
110
+ context "laquo" do
111
+ let(:doc) { Kramdown::Document.new("<< foo") }
112
+ let(:sym) { doc.root.children[0].children[0] }
113
+
114
+ it "should convert mdash symbols into '«'" do
115
+ subject.convert_typographic_sym(sym).should == '«'
116
+ end
117
+ end
118
+
119
+ context "raquo" do
120
+ let(:doc) { Kramdown::Document.new("foo >> bar") }
121
+ let(:sym) { doc.root.children[0].children[1] }
122
+
123
+ it "should convert mdash symbols into '»'" do
124
+ subject.convert_typographic_sym(sym).should == '»'
125
+ end
126
+ end
127
+
128
+ context "laquo_space" do
129
+ let(:doc) { Kramdown::Document.new(" << foo") }
130
+ let(:sym) { doc.root.children[0].children[0] }
131
+
132
+ it "should convert mdash symbols into '«'" do
133
+ subject.convert_typographic_sym(sym).should == '«'
134
+ end
135
+ end
136
+
137
+ context "raquo_space" do
138
+ let(:doc) { Kramdown::Document.new("foo >> bar") }
139
+ let(:sym) { doc.root.children[0].children[1] }
140
+
141
+ it "should convert mdash symbols into '»'" do
142
+ subject.convert_typographic_sym(sym).should == '»'
143
+ end
144
+ end
145
+ end
146
+
147
+ describe "#convert_smart_quote" do
148
+ context "lsquo" do
149
+ let(:doc) { Kramdown::Document.new("'hello world'") }
150
+ let(:quote) { doc.root.children[0].children.first }
151
+
152
+ it "should convert lsquo quotes into '‘'" do
153
+ subject.convert_smart_quote(quote).should == '‘'
154
+ end
155
+ end
156
+
157
+ context "rsquo" do
158
+ let(:doc) { Kramdown::Document.new("'hello world'") }
159
+ let(:quote) { doc.root.children[0].children.last }
160
+
161
+ it "should convert rsquo quotes into '’'" do
162
+ subject.convert_smart_quote(quote).should == '’'
163
+ end
164
+ end
165
+
166
+ context "ldquo" do
167
+ let(:doc) { Kramdown::Document.new('"hello world"') }
168
+ let(:quote) { doc.root.children[0].children.first }
169
+
170
+ it "should convert lsquo quotes into '“'" do
171
+ subject.convert_smart_quote(quote).should == '“'
172
+ end
173
+ end
174
+
175
+ context "rdquo" do
176
+ let(:doc) { Kramdown::Document.new('"hello world"') }
177
+ let(:quote) { doc.root.children[0].children.last }
178
+
179
+ it "should convert lsquo quotes into '”'" do
180
+ subject.convert_smart_quote(quote).should == '”'
181
+ end
182
+ end
183
+ end
184
+
185
+ describe "#convert_header" do
186
+ context "when level is 1" do
187
+ let(:doc) { Kramdown::Document.new("# Header") }
188
+ let(:header) { doc.root.children[0] }
189
+
190
+ it "should convert level 1 headers into '.TH text'" do
191
+ subject.convert_header(header).should == ".TH Header"
192
+ end
193
+ end
194
+
195
+ context "when level is 2" do
196
+ let(:doc) { Kramdown::Document.new("## Header") }
197
+ let(:header) { doc.root.children[0] }
198
+
199
+ it "should convert level 2 headers into '.SH text'" do
200
+ subject.convert_header(header).should == ".SH Header"
201
+ end
202
+ end
203
+
204
+ context "when level is 3" do
205
+ let(:doc) { Kramdown::Document.new("### Header") }
206
+ let(:header) { doc.root.children[0] }
207
+
208
+ it "should convert level 2 headers into '.SS text'" do
209
+ subject.convert_header(header).should == ".SS Header"
210
+ end
211
+ end
212
+
213
+ context "when level is 4 or greater" do
214
+ let(:doc) { Kramdown::Document.new("#### Header") }
215
+ let(:header) { doc.root.children[0] }
216
+
217
+ it "should convert level 2 headers into '.SS text'" do
218
+ subject.convert_header(header).should == ".SS Header"
219
+ end
220
+ end
221
+ end
222
+
223
+ describe "#convert_hr" do
224
+ let(:doc) { Kramdown::Document.new('------------------------------------') }
225
+ let(:hr) { doc.root.children[0] }
226
+
227
+ it "should convert hr elements into '.ti 0\\n\\\\l'\\\\n(.lu\\''" do
228
+ subject.convert_hr(hr).should == ".ti 0\n\\l'\\n(.lu'"
229
+ end
230
+ end
231
+
232
+ describe "#convert_ul" do
233
+ let(:text1) { 'foo' }
234
+ let(:text2) { 'bar' }
235
+ let(:doc) { Kramdown::Document.new("* #{text1}\n* #{text2}") }
236
+ let(:ul) { doc.root.children[0] }
237
+
238
+ it "should convert ul elements into '.RS\\n...\\n.RE'" do
239
+ subject.convert_ul(ul).should == [
240
+ ".RS",
241
+ ".IP \\(bu 2",
242
+ text1,
243
+ ".IP \\(bu 2",
244
+ text2,
245
+ ".RE"
246
+ ].join("\n")
247
+ end
248
+ end
249
+
250
+ describe "#convert_ul_li" do
251
+ let(:text) { 'hello world' }
252
+ let(:doc) { Kramdown::Document.new("* #{text}") }
253
+ let(:li) { doc.root.children[0].children[0] }
254
+
255
+ it "should convert the first p element to '.IP \\\\(bu 2\\n...'" do
256
+ subject.convert_ul_li(li).should == ".IP \\(bu 2\n#{text}"
257
+ end
258
+
259
+ context "with multiple multiple paragraphs" do
260
+ let(:text1) { 'hello' }
261
+ let(:text2) { 'world' }
262
+ let(:doc) { Kramdown::Document.new("* #{text1}\n\n #{text2}") }
263
+
264
+ it "should convert the other p elements to '.IP \\\\( 2\\n...'" do
265
+ subject.convert_ul_li(li).should == [
266
+ ".IP \\(bu 2",
267
+ text1,
268
+ ".IP \\( 2",
269
+ text2
270
+ ].join("\n")
271
+ end
272
+ end
273
+ end
274
+
275
+ describe "#convert_ol" do
276
+ let(:text1) { 'foo' }
277
+ let(:text2) { 'bar' }
278
+ let(:doc) { Kramdown::Document.new("1. #{text1}\n2. #{text2}") }
279
+ let(:ol) { doc.root.children[0] }
280
+
281
+ it "should convert ol elements into '.RS\\n...\\n.RE'" do
282
+ subject.convert_ol(ol).should == [
283
+ ".nr step1 0 1",
284
+ ".RS",
285
+ ".IP \\n+[step1]",
286
+ text1,
287
+ ".IP \\n+[step1]",
288
+ text2,
289
+ ".RE"
290
+ ].join("\n")
291
+ end
292
+ end
293
+
294
+ describe "#convert_ol_li" do
295
+ let(:text) { 'hello world' }
296
+ let(:doc) { Kramdown::Document.new("1. #{text}") }
297
+ let(:li) { doc.root.children[0].children[0] }
298
+
299
+ it "should convert the first p element to '.IP \\\\n+[step0]\\n...'" do
300
+ subject.convert_ol_li(li).should == ".IP \\n+[step0]\n#{text}"
301
+ end
302
+
303
+ context "with multiple multiple paragraphs" do
304
+ let(:text1) { 'hello' }
305
+ let(:text2) { 'world' }
306
+ let(:doc) { Kramdown::Document.new("1. #{text1}\n\n #{text2}") }
307
+
308
+ it "should convert the other p elements to '.IP \\\\n\\n...'" do
309
+ p li
310
+
311
+ subject.convert_ol_li(li).should == [
312
+ ".IP \\n+[step0]",
313
+ text1,
314
+ ".IP \\n",
315
+ text2
316
+ ].join("\n")
317
+ end
318
+ end
319
+ end
320
+
321
+ describe "#convert_abbreviation" do
322
+ let(:acronym) { 'HTML' }
323
+ let(:definition) { 'Hyper Text Markup Language' }
324
+ let(:doc) { Kramdown::Document.new("This is an #{acronym} example.\n\n*[#{acronym}]: #{definition}") }
325
+ let(:abbreviation) { doc.root.children[0].children[1] }
326
+
327
+ it "should convert abbreviation elements into their text" do
328
+ subject.convert_abbreviation(abbreviation).should == acronym
329
+ end
330
+ end
331
+
332
+ describe "#convert_blockquote" do
333
+ let(:text) { "Some quote." }
334
+ let(:doc) { Kramdown::Document.new("> #{text}") }
335
+ let(:blockquote) { doc.root.children[0] }
336
+
337
+ it "should convert blockquote elements into '.PP\\n.RS\\ntext...\\n.RE'" do
338
+ subject.convert_blockquote(blockquote).should == ".PP\n.RS\n#{text}\n.RE"
339
+ end
340
+ end
341
+
342
+ describe "#convert_codeblock" do
343
+ let(:code) { "puts 'hello world'" }
344
+ let(:doc) { Kramdown::Document.new(" #{code}\n") }
345
+ let(:codeblock) { doc.root.children[0] }
346
+
347
+ it "should convert codeblock elements into '.nf\\ntext...\\n.fi'" do
348
+ subject.convert_codeblock(codeblock).should == ".nf\n#{code}\n.fi"
349
+ end
350
+ end
351
+
352
+ describe "#convert_comment" do
353
+ let(:text) { "Copyright (c) 2013" }
354
+ let(:doc) { Kramdown::Document.new("{::comment}\n#{text}\n{:/comment}") }
355
+ let(:comment) { doc.root.children[0] }
356
+
357
+ it "should convert comment elements into '.\\\" text...'" do
358
+ subject.convert_comment(comment).should == ".\\\" #{text}"
359
+ end
360
+ end
361
+
362
+ describe "#convert_p" do
363
+ let(:text) { "Hello world." }
364
+ let(:doc) { Kramdown::Document.new(text) }
365
+ let(:p) { doc.root.children[0] }
366
+
367
+ it "should convert p elements into '.PP\\ntext'" do
368
+ subject.convert_p(p).should == ".PP\n#{text}"
369
+ end
370
+
371
+ context "when the second line is indented with two spaces" do
372
+ let(:option) { '--foo' }
373
+ let(:text) { 'Foo bar baz' }
374
+ let(:doc) { Kramdown::Document.new("`#{option}`\n #{text}") }
375
+
376
+ it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
377
+ subject.convert_p(p).should == ".TP\n\\fB\\fC#{option}\\fR\n#{text}"
378
+ end
379
+ end
380
+
381
+ context "when the second line is indented with a tab" do
382
+ let(:option) { '--foo' }
383
+ let(:text) { 'Foo bar baz' }
384
+ let(:doc) { Kramdown::Document.new("`#{option}`\n\t#{text}") }
385
+
386
+ it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
387
+ subject.convert_p(p).should == ".TP\n\\fB\\fC#{option}\\fR\n#{text}"
388
+ end
389
+ end
390
+ end
391
+
392
+ describe "#convert_em" do
393
+ let(:text) { "hello world" }
394
+ let(:doc) { Kramdown::Document.new("*#{text}*") }
395
+ let(:em) { doc.root.children[0].children[0] }
396
+
397
+ it "should convert em elements into '\\fItext\\fP'" do
398
+ subject.convert_em(em).should == "\\fI#{text}\\fP"
399
+ end
400
+ end
401
+
402
+ describe "#convert_strong" do
403
+ let(:text) { "hello world" }
404
+ let(:doc) { Kramdown::Document.new("**#{text}**") }
405
+ let(:strong) { doc.root.children[0].children[0] }
406
+
407
+ it "should convert strong elements into '\\fBtext\\fP'" do
408
+ subject.convert_strong(strong).should == "\\fB#{text}\\fP"
409
+ end
410
+ end
411
+
412
+ describe "#convert_codespan" do
413
+ let(:code) { "puts 'hello world'" }
414
+ let(:doc) { Kramdown::Document.new("`#{code}`") }
415
+ let(:codespan) { doc.root.children[0].children[0] }
416
+
417
+ it "should convert codespan elements into '\\fB\\fCcode\\fR'" do
418
+ subject.convert_codespan(codespan).should == "\\fB\\fC#{code}\\fR"
419
+ end
420
+ end
421
+
422
+ describe "#convert_a" do
423
+ let(:text) { 'example' }
424
+ let(:href) { 'http://example.com/' }
425
+ let(:doc) { Kramdown::Document.new("[#{text}](#{href})") }
426
+ let(:link) { doc.root.children[0].children[0] }
427
+
428
+ it "should convert a link elements into 'text\\n.UR href\\n.UE'" do
429
+ subject.convert_a(link).should == "#{text}\n.UR #{href}\n.UE"
430
+ end
431
+
432
+ context "when the href begins with mailto:" do
433
+ let(:text) { 'Bob' }
434
+ let(:email) { 'bob@example.com' }
435
+ let(:doc) { Kramdown::Document.new("[#{text}](mailto:#{email})") }
436
+
437
+ it "should convert the link elements into '.MT email\\n.ME'" do
438
+ subject.convert_a(link).should == "#{text}\n.MT #{email}\n.ME"
439
+ end
440
+
441
+ context "when link is <email>" do
442
+ let(:email) { 'bob@example.com' }
443
+ let(:doc) { Kramdown::Document.new("<#{email}>") }
444
+
445
+ it "should convert the link elements into '.MT email\\n.ME'" do
446
+ subject.convert_a(link).should == "\n.MT #{email}\n.ME"
447
+ end
448
+ end
449
+ end
450
+
451
+ context "when the href begins with man:" do
452
+ let(:man) { 'bash' }
453
+ let(:doc) { Kramdown::Document.new("[#{man}](man:#{man})") }
454
+
455
+ it "should convert the link elements into '.BR man'" do
456
+ subject.convert_a(link).should == "\n.BR #{man}"
457
+ end
458
+
459
+ context "when a section number is specified" do
460
+ let(:section) { '1' }
461
+ let(:doc) { Kramdown::Document.new("[#{man}](man:#{man}(#{section}))") }
462
+
463
+ it "should convert the link elements into '.BR man (section)'" do
464
+ subject.convert_a(link).should == "\n.BR #{man} (#{section})"
465
+ end
466
+ end
467
+ end
468
+ end
469
+
470
+ describe "#escape" do
471
+ it "should escape '\\' as '\\\\'" do
472
+ subject.escape("hello\\ world").should == "hello\\\\ world"
473
+ end
474
+
475
+ it "should escape '-' as '\\-'" do
476
+ subject.escape("foo-bar").should == "foo\\-bar"
477
+ end
478
+ end
479
+ end