kramdown-man 0.1.3 → 0.1.4

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.
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.1.4 / 2013-05-05
2
+
3
+ * Improve detection of tagged paragraphs.
4
+ * Support emitted a hanging paragraph (`.HP`) for command synopsis lines.
5
+ * Strip leading whitespace from each line of emitted text.
6
+
1
7
  ### 0.1.3 / 2013-05-05
2
8
 
3
9
  * Initial release:
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
@@ -41,5 +41,5 @@ task :doc => :yard
41
41
 
42
42
  $LOAD_PATH.unshift(File.expand_path('lib'))
43
43
 
44
- require 'kramdown/man/tasks'
45
- Kramdown::Man::Tasks.new
44
+ require 'kramdown/man/task'
45
+ Kramdown::Man::Task.new
@@ -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[0].type == :em || children[0].type == :codespan) &&
329
- (children[1].type == :text && children[1].value =~ /^( |\t)/)
330
- [
331
- '.TP',
332
- convert_element(children[0]),
333
- convert_text(children[1]).lstrip,
334
- convert_children(children[2..-1])
335
- ].join("\n").rstrip
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
@@ -1,6 +1,6 @@
1
1
  module Kramdown
2
2
  module Man
3
3
  # kramdown-man version
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
6
6
  end
data/man/kramdown-man.1 CHANGED
@@ -1,4 +1,4 @@
1
- .\" Generated by kramdown-man 0.1.0
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
@@ -35,6 +35,10 @@ A [Kramdown][kramdown] convert for converting Markdown files into man pages.
35
35
 
36
36
  Normal paragraph.
37
37
 
38
+ `command` [`--foo`] *FILE*
39
+
40
+ `command` [`--foo`] *FILE*
41
+
38
42
  `--tagged`
39
43
  Text here.
40
44
 
@@ -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 second line is indented with two spaces" do
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 #{text}") }
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 second line is indented with a tab" do
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("`#{option}`\n\t#{text}") }
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\\fB\\fC#{option}\\fR\n#{text}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kramdown-man
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: