kramdown-man 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.md +6 -0
- data/README.md +5 -1
- data/Rakefile +2 -2
- data/lib/kramdown/converter/man.rb +14 -9
- data/lib/kramdown/man/version.rb +1 -1
- data/man/kramdown-man.1 +8 -1
- data/man/kramdown-man.1.md +4 -0
- data/spec/kramdown/converter/man_spec.rb +77 -5
- metadata +1 -1
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -15,7 +15,7 @@ A [Kramdown][kramdown] convert for converting Markdown files into man pages.
|
|
15
15
|
|
16
16
|
* Converts markdown to [roff]:
|
17
17
|
* Supports codespans, emphasis and strong fonts.
|
18
|
-
* Supports normal and tagged paragraphs.
|
18
|
+
* Supports normal, hanging and tagged paragraphs.
|
19
19
|
* Supports bullet lists.
|
20
20
|
* Supports multi-paragraph list items and blockquotes.
|
21
21
|
* Supports horizontal rules.
|
@@ -69,6 +69,10 @@ Define a `man` and file tasks which render all `*.md` files within the
|
|
69
69
|
|
70
70
|
Normal paragraph.
|
71
71
|
|
72
|
+
`command` [`--foo`] *FILE*
|
73
|
+
|
74
|
+
`command` [`--foo`] *FILE*
|
75
|
+
|
72
76
|
`--tagged`
|
73
77
|
Text here.
|
74
78
|
|
data/Rakefile
CHANGED
@@ -115,7 +115,7 @@ module Kramdown
|
|
115
115
|
# The roff output.
|
116
116
|
#
|
117
117
|
def convert_text(text)
|
118
|
-
escape(text.value)
|
118
|
+
escape(text.value.gsub(/^( +|\t)/,''))
|
119
119
|
end
|
120
120
|
|
121
121
|
#
|
@@ -325,14 +325,19 @@ module Kramdown
|
|
325
325
|
children = p.children
|
326
326
|
|
327
327
|
if (children.length >= 2) &&
|
328
|
-
(children
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
convert_children(children[
|
335
|
-
|
328
|
+
(children.first.type == :em || children.first.type == :codespan)
|
329
|
+
newline = children.find_index { |el|
|
330
|
+
el.type == :text && el.value.start_with?("\n")
|
331
|
+
}
|
332
|
+
|
333
|
+
if newline
|
334
|
+
first_line = convert_children(children[0...newline])
|
335
|
+
rest = convert_children(children[newline..-1]).strip
|
336
|
+
|
337
|
+
".TP\n#{first_line}\n#{rest}"
|
338
|
+
else
|
339
|
+
".HP\n#{convert_children(children)}"
|
340
|
+
end
|
336
341
|
else
|
337
342
|
".PP\n#{convert_children(children)}"
|
338
343
|
end
|
data/lib/kramdown/man/version.rb
CHANGED
data/man/kramdown-man.1
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
.\" Generated by kramdown-man 0.1.
|
1
|
+
.\" Generated by kramdown-man 0.1.4
|
2
2
|
.\" https://github.com/postmodern/kramdown-roff#readme
|
3
3
|
.TH kramdown-man.1 "April 2013" kramdown-man "User Manuals"
|
4
4
|
.LP
|
@@ -55,6 +55,13 @@ Normal paragraph.
|
|
55
55
|
Normal paragraph.
|
56
56
|
.LP
|
57
57
|
.nf
|
58
|
+
`command` [`\-\-foo`] *FILE*
|
59
|
+
.fi
|
60
|
+
.LP
|
61
|
+
.HP
|
62
|
+
\fB\fCcommand\fR [\fB\fC--foo\fR] \fIFILE\fP
|
63
|
+
.LP
|
64
|
+
.nf
|
58
65
|
`\-\-tagged`
|
59
66
|
Text here.
|
60
67
|
.fi
|
data/man/kramdown-man.1.md
CHANGED
@@ -77,6 +77,22 @@ Hello world.
|
|
77
77
|
it "should convert text elements" do
|
78
78
|
subject.convert_text(text).should == content
|
79
79
|
end
|
80
|
+
|
81
|
+
context "when the text has two-space indentation" do
|
82
|
+
let(:content) { "Foo\n bar\n baz" }
|
83
|
+
|
84
|
+
it "should strip leading whitespace from each line" do
|
85
|
+
subject.convert_text(text).should == content.gsub("\n ","\n")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when the text has tab indentation" do
|
90
|
+
let(:content) { "Foo\n\tbar\n\tbaz" }
|
91
|
+
|
92
|
+
it "should strip leading whitespace from each line" do
|
93
|
+
subject.convert_text(text).should == content.gsub("\n\t","\n")
|
94
|
+
end
|
95
|
+
end
|
80
96
|
end
|
81
97
|
|
82
98
|
describe "#convert_typographic_sym" do
|
@@ -368,23 +384,79 @@ Hello world.
|
|
368
384
|
subject.convert_p(p).should == ".PP\n#{text}"
|
369
385
|
end
|
370
386
|
|
371
|
-
context "when the
|
387
|
+
context "when the paragraph starts with a codespan element" do
|
372
388
|
let(:option) { '--foo' }
|
373
389
|
let(:text) { 'Foo bar baz' }
|
374
|
-
let(:doc) { Kramdown::Document.new("`#{option}`\n
|
390
|
+
let(:doc) { Kramdown::Document.new("`#{option}`\n\t#{text}") }
|
375
391
|
|
376
392
|
it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
|
377
393
|
subject.convert_p(p).should == ".TP\n\\fB\\fC#{option}\\fR\n#{text}"
|
378
394
|
end
|
395
|
+
|
396
|
+
context "when there is only one codespan element" do
|
397
|
+
let(:code) { 'code' }
|
398
|
+
let(:doc) { Kramdown::Document.new("`#{code}`") }
|
399
|
+
|
400
|
+
it "should convert p elements into '.PP\\n\\fB\\fC...\\fR'" do
|
401
|
+
subject.convert_p(p).should == ".PP\n\\fB\\fC#{code}\\fR"
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
context "when there are more than one codespan element" do
|
406
|
+
let(:flag) { '-f' }
|
407
|
+
let(:option) { '--foo' }
|
408
|
+
let(:text) { 'Foo bar baz' }
|
409
|
+
let(:doc) { Kramdown::Document.new("`#{flag}`, `#{option}`\n\t#{text}") }
|
410
|
+
|
411
|
+
it "should convert p elements into '.TP\\n\\fB\\fC-o\\fR, \\fB\\fC--option\\fR\\ntext...'" do
|
412
|
+
subject.convert_p(p).should == ".TP\n\\fB\\fC#{flag}\\fR, \\fB\\fC#{option}\\fR\n#{text}"
|
413
|
+
end
|
414
|
+
|
415
|
+
context "when there is no newline" do
|
416
|
+
let(:doc) { Kramdown::Document.new("`#{flag}` `#{option}`") }
|
417
|
+
|
418
|
+
it "should convert the p element into a '.HP\\n...'" do
|
419
|
+
subject.convert_p(p).should == ".HP\n\\fB\\fC#{flag}\\fR \\fB\\fC#{option}\\fR"
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
379
423
|
end
|
380
424
|
|
381
|
-
context "when the
|
425
|
+
context "when the paragraph starts with a em element" do
|
382
426
|
let(:option) { '--foo' }
|
383
427
|
let(:text) { 'Foo bar baz' }
|
384
|
-
let(:doc) { Kramdown::Document.new("
|
428
|
+
let(:doc) { Kramdown::Document.new("*#{option}*\n\t#{text}") }
|
385
429
|
|
386
430
|
it "should convert p elements into '.TP\\n\\fB\\fC--option\\fR\\ntext...'" do
|
387
|
-
subject.convert_p(p).should == ".TP\n\\
|
431
|
+
subject.convert_p(p).should == ".TP\n\\fI#{option}\\fP\n#{text}"
|
432
|
+
end
|
433
|
+
|
434
|
+
context "when there is only one em element" do
|
435
|
+
let(:text) { 'foo' }
|
436
|
+
let(:doc) { Kramdown::Document.new("*#{text}*") }
|
437
|
+
|
438
|
+
it "should convert p elements into '.PP\\n\\fB\\fC...\\fR'" do
|
439
|
+
subject.convert_p(p).should == ".PP\n\\fI#{text}\\fP"
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
context "when there are more than one em element" do
|
444
|
+
let(:flag) { '-f' }
|
445
|
+
let(:option) { '--foo' }
|
446
|
+
let(:text) { 'Foo bar baz' }
|
447
|
+
let(:doc) { Kramdown::Document.new("*#{flag}*, *#{option}*\n\t#{text}") }
|
448
|
+
|
449
|
+
it "should convert p elements into '.TP\\n\\fI-o\\fP, \\fI--option\\fP\\ntext...'" do
|
450
|
+
subject.convert_p(p).should == ".TP\n\\fI\\#{flag}\\fP, \\fI#{option}\\fP\n#{text}"
|
451
|
+
end
|
452
|
+
|
453
|
+
context "when there is no newline" do
|
454
|
+
let(:doc) { Kramdown::Document.new("*#{flag}* *#{option}*") }
|
455
|
+
|
456
|
+
it "should convert the p element into a '.HP\\n...'" do
|
457
|
+
subject.convert_p(p).should == ".HP\n\\fI\\#{flag}\\fP \\fI#{option}\\fP"
|
458
|
+
end
|
459
|
+
end
|
388
460
|
end
|
389
461
|
end
|
390
462
|
end
|