md2man 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.markdown CHANGED
@@ -1,13 +1,27 @@
1
- ------------------------------------------------------------------------------
2
- Version 1.1.0 (2012-02-02)
3
- ------------------------------------------------------------------------------
1
+ ## Version 1.2.0 (2012-02-06)
4
2
 
5
- Improvements:
3
+ Minor:
4
+
5
+ * The `Md2Man::Document` module now handles paragraph() nodes and dispatches
6
+ their content accordingly to hook methods for indented, tagged, and normal
7
+ paragraphs. A Redcarpet markdown parser need only include that module and
8
+ implement those hook methods in order to benefit from md2man's extensions
9
+ to markdown syntax programmatically.
10
+
11
+ Other:
12
+
13
+ * README: mention features; revise markdown; cleanup.
14
+
15
+ * LICENSE: @tanoku created initial Manpage renderer.
16
+
17
+ ## Version 1.1.0 (2012-02-02)
18
+
19
+ Minor:
6
20
 
7
21
  * Add `Md2Man::Document` module for programmatic processing of
8
22
  cross-references to other UNIX manual pages within Redcarpet.
9
23
 
10
- Housekeeping:
24
+ Other:
11
25
 
12
26
  * README: not all systems support `man -l` option.
13
27
 
@@ -19,17 +33,15 @@ Housekeeping:
19
33
 
20
34
  * README: simplify project slogan to be more memorable.
21
35
 
22
- ------------------------------------------------------------------------------
23
- Version 1.0.2 (2012-01-09)
24
- ------------------------------------------------------------------------------
36
+ ## Version 1.0.2 (2012-01-09)
25
37
 
26
- Corrections:
38
+ Patch:
27
39
 
28
40
  * Blockquote's leading paragraph regexp was not anchored.
29
41
 
30
42
  * Freezing internal constants prevents monkey patching.
31
43
 
32
- Housekeeping:
44
+ Other:
33
45
 
34
46
  * Upgraded to Binman 3 for better interoperability with Bundler.
35
47
 
@@ -37,11 +49,9 @@ Housekeeping:
37
49
 
38
50
  * Forgot to change project slogan in the gem package.
39
51
 
40
- ------------------------------------------------------------------------------
41
- Version 1.0.1 (2011-12-06)
42
- ------------------------------------------------------------------------------
52
+ ## Version 1.0.1 (2011-12-06)
43
53
 
44
- Divergences:
54
+ Major:
45
55
 
46
56
  * Renamed the project from "redcarpet-manpage" to "md2man".
47
57
 
@@ -52,7 +62,7 @@ Divergences:
52
62
  * Tagged paragraphs no longer require the first line to begin with italic or
53
63
  bold styling. All that matters is that the subsequent lines are indented.
54
64
 
55
- Improvements:
65
+ Minor:
56
66
 
57
67
  * Added md2man(1) executable for command-line usage.
58
68
 
@@ -64,12 +74,10 @@ Improvements:
64
74
 
65
75
  * Improved README with some new and revised documentation.
66
76
 
67
- Housekeeping:
77
+ Other:
68
78
 
69
79
  * Rewrote entire Markdown to Roff conversion from scratch while doing TDD.
70
80
 
71
- ------------------------------------------------------------------------------
72
- Version 0.0.1 (2011-10-13)
73
- ------------------------------------------------------------------------------
81
+ ## Version 0.0.1 (2011-10-13)
74
82
 
75
83
  First release! Happy birthday! Woohoo! :-)
data/LICENSE CHANGED
@@ -1,6 +1,7 @@
1
1
  (the ISC license)
2
2
 
3
3
  Copyright 2011 Suraj N. Kurapati <sunaku@gmail.com>
4
+ Thanks to 2011 Vicent Marti <tanoku@gmail.com>
4
5
 
5
6
  Permission to use, copy, modify, and/or distribute this software for any
6
7
  purpose with or without fee is hereby granted, provided that the above
data/README.markdown CHANGED
@@ -1,27 +1,40 @@
1
- md2man - markdown to manpage
2
- ==============================================================================
1
+ # md2man - markdown to manpage
3
2
 
4
3
  md2man is a Ruby library and command-line program that converts [Markdown]
5
- documents into UNIX man pages (really [Roff] documents) using [Redcarpet2].
4
+ documents into UNIX manual pages (really [Roff] documents) using [Redcarpet].
6
5
 
7
- [Roff]: http://troff.org
8
- [Markdown]: http://daringfireball.net/projects/markdown/
9
- [Redcarpet2]: https://github.com/tanoku/redcarpet
10
- [example]: https://raw.github.com/sunaku/md2man/master/EXAMPLE.markdown
6
+ ## Features
7
+
8
+ * Formats tagged and indented paragraphs (see "document format" below).
11
9
 
12
- ------------------------------------------------------------------------------
13
- Demonstration
14
- ------------------------------------------------------------------------------
10
+ * Translates all HTML4 and XHTML1 entities into native Roff equivalents.
15
11
 
16
- Try converting [this example Markdown file][example] into a UNIX man page:
12
+ * Supports markdown extensions such as [PHP Markdown Extra tables][tables].
17
13
 
18
- md2man EXAMPLE.markdown > EXAMPLE.man && man ./EXAMPLE.man
14
+ * Usable from the command line as a filter in a UNIX pipeline.
15
+
16
+ ### Demonstration
17
+
18
+ Try converting [this example Markdown file][example] into a UNIX manual page:
19
+
20
+ md2man EXAMPLE.markdown > EXAMPLE.1
21
+ man EXAMPLE.1
19
22
 
20
23
  ![Obligatory screenshot of md2man(1) in action!](http://ompldr.org/vYnFvbw)
21
24
 
22
- ------------------------------------------------------------------------------
23
- Installation
24
- ------------------------------------------------------------------------------
25
+ ### Limitations
26
+
27
+ At present, md2man does not translate the following [Redcarpet] node types:
28
+
29
+ * `block_html`
30
+ * `strikethrough`
31
+ * `superscript`
32
+ * `image`
33
+ * `raw_html`
34
+
35
+ It issues a warning when it encounters these instead. Patches are welcome!
36
+
37
+ ## Installation
25
38
 
26
39
  gem install md2man
27
40
 
@@ -33,15 +46,13 @@ Installation
33
46
  bundle_bin/md2man --help # run it directly
34
47
  bundle exec rake -T # packaging tasks
35
48
 
36
- ------------------------------------------------------------------------------
37
- Usage
38
- ------------------------------------------------------------------------------
49
+ ## Usage
39
50
 
40
51
  ### At the command line
41
52
 
42
53
  md2man --help
43
54
 
44
- ### In your Ruby scripts
55
+ ### Inside a Ruby script
45
56
 
46
57
  Use the default renderer:
47
58
 
@@ -77,14 +88,10 @@ Mix-in your own renderer:
77
88
  engine = Redcarpet::Markdown.new(YourManpageRenderer, your_options_hash)
78
89
  your_roff_output = engine.render(your_markdown_input)
79
90
 
80
- ------------------------------------------------------------------------------
81
- Document format
82
- ------------------------------------------------------------------------------
83
-
84
- md2man attaches the following additional semantics to its [Markdown] input:
91
+ ### Document format
85
92
 
86
- * There can be at most one top-level heading (H1). It is emitted as `.TH`
87
- in the [Roff] output, specifying the UNIX man page's header and footer.
93
+ md2man extends [Markdown] syntax in the following ways, as provisioned in the
94
+ `Md2Man::Document` module and defined in its derivative `Md2Man::Roff` module:
88
95
 
89
96
  * Paragraphs whose lines are all uniformly indented by two spaces are
90
97
  considered to be "indented paragraphs". They are unindented accordingly
@@ -94,22 +101,17 @@ md2man attaches the following additional semantics to its [Markdown] input:
94
101
  indented by two spaces are considered to be a "tagged paragraphs". They
95
102
  are unindented accordingly before emission as `.TP` in the [Roff] output.
96
103
 
97
- ------------------------------------------------------------------------------
98
- Known issues
99
- ------------------------------------------------------------------------------
100
-
101
- At present, md2man does not translate the following [Redcarpet2] node types:
102
-
103
- * `block_html`
104
- * `strikethrough`
105
- * `superscript`
106
- * `image`
107
- * `raw_html`
104
+ md2man extends [Markdown] semantics in the following ways:
108
105
 
109
- It issues a warning when it encounters these instead. Patches are welcome!
106
+ * There can be at most one top-level heading (H1). It is emitted as `.TH`
107
+ in the [Roff] output, defining the UNIX manual page's header and footer.
110
108
 
111
- ------------------------------------------------------------------------------
112
- License
113
- ------------------------------------------------------------------------------
109
+ ## License
114
110
 
115
111
  Released under the ISC license. See the LICENSE file for details.
112
+
113
+ [Roff]: http://troff.org
114
+ [Markdown]: http://daringfireball.net/projects/markdown/
115
+ [Redcarpet]: https://github.com/tanoku/redcarpet
116
+ [example]: https://raw.github.com/sunaku/md2man/master/EXAMPLE.markdown
117
+ [tables]: http://michelf.com/projects/php-markdown/extra/#table
data/bin/md2man CHANGED
@@ -1,32 +1,26 @@
1
1
  #!/usr/bin/env ruby
2
- =begin
2
+ =begin =======================================================================
3
3
 
4
- MD2MAN 1 "2012-02-02" "1.1.0"
5
- =============================
4
+ # MD2MAN 1 2012-02-06 1.2.0
6
5
 
7
- NAME
8
- ----
6
+ ## NAME
9
7
 
10
8
  md2man - convert markdown(7) into roff(7)
11
9
 
12
- SYNOPSIS
13
- --------
10
+ ## SYNOPSIS
14
11
 
15
12
  `md2man` [*OPTION*]... [*FILE*]
16
13
 
17
- DESCRIPTION
18
- -----------
14
+ ## DESCRIPTION
19
15
 
20
16
  [md2man] converts markdown(7) input from the given *FILE* into roff(7) using
21
- [Redcarpet2] and then prints the result to the standard output stream. If
17
+ [Redcarpet] and then prints the result to the standard output stream. If
22
18
  *FILE* is not given, then the standard input stream is read in its place.
23
19
 
24
- ### Document Format
20
+ ### Document format
25
21
 
26
- The following additional semantics are attached to markdown(7):
27
-
28
- * There can be at most one top-level heading (H1). It is emitted as `.TH`
29
- in the roff(7) output, specifying the UNIX man page's header and footer.
22
+ md2man extends markdown(7) syntax in the following ways, as provisioned in the
23
+ `Md2Man::Document` module and defined in its derivative `Md2Man::Roff` module:
30
24
 
31
25
  * Paragraphs whose lines are all uniformly indented by two spaces are
32
26
  considered to be "indented paragraphs". They are unindented accordingly
@@ -36,30 +30,33 @@ The following additional semantics are attached to markdown(7):
36
30
  indented by two spaces are considered to be a "tagged paragraphs". They
37
31
  are unindented accordingly before emission as `.TP` in the roff(7) output.
38
32
 
39
- ### Markdown Extensions
33
+ md2man extends markdown(7) semantics in the following ways:
34
+
35
+ * There can be at most one top-level heading (H1). It is emitted as `.TH`
36
+ in the roff(7) output, defining the UNIX manual page's header and footer.
37
+
38
+ ### Markdown extensions
40
39
 
41
- The following [Redcarpet2] extensions for markdown(7) are enabled:
40
+ The following [Redcarpet] extensions are enabled while processing markdown(7):
42
41
 
43
- * tables
44
- * autolink
45
- * superscript
46
- * strikethrough
47
- * no_intra_emphasis
48
- * fenced_code_blocks
42
+ * tables
43
+ * autolink
44
+ * superscript
45
+ * strikethrough
46
+ * no_intra_emphasis
47
+ * fenced_code_blocks
49
48
 
50
- OPTIONS
51
- -------
49
+ ## OPTIONS
52
50
 
53
51
  `-h`, `--help`
54
- Display this help manual using man(1).
52
+ Show this help manual.
55
53
 
56
- SEE ALSO
57
- --------
54
+ ## SEE ALSO
58
55
 
59
56
  markdown(7), roff(7)
60
57
 
61
58
  [md2man]: https://github.com/sunaku/md2man
62
- [Redcarpet2]: https://github.com/tanoku/redcarpet
59
+ [Redcarpet]: https://github.com/tanoku/redcarpet
63
60
 
64
61
  =end =========================================================================
65
62
 
@@ -10,5 +10,36 @@ module Document
10
10
  warn "md2man/document: reference not implemented: #{page}(#{section})"
11
11
  end
12
12
 
13
+ PARAGRAPH_INDENT = /^\s*$|^ (?=\S)/
14
+
15
+ def paragraph text
16
+ head, *body = text.lines.to_a
17
+ head_indented = head =~ PARAGRAPH_INDENT
18
+ body_indented = !body.empty? && body.all? {|s| s =~ PARAGRAPH_INDENT }
19
+
20
+ if head_indented || body_indented
21
+ text = text.gsub(PARAGRAPH_INDENT, '')
22
+ if head_indented && body_indented
23
+ indented_paragraph text
24
+ else
25
+ tagged_paragraph text
26
+ end
27
+ else
28
+ normal_paragraph text.chomp
29
+ end
30
+ end
31
+
32
+ def indented_paragraph text
33
+ warn "md2man/document: indented_paragraph not implemented: #{text.inspect}"
34
+ end
35
+
36
+ def tagged_paragraph text
37
+ warn "md2man/document: tagged_paragraph not implemented: #{text.inspect}"
38
+ end
39
+
40
+ def normal_paragraph text
41
+ warn "md2man/document: normal_paragraph not implemented: #{text.inspect}"
42
+ end
43
+
13
44
  end
14
45
  end
data/lib/md2man/roff.rb CHANGED
@@ -29,22 +29,16 @@ module Roff
29
29
  # block-level processing
30
30
  #---------------------------------------------------------------------------
31
31
 
32
- PARAGRAPH_INDENT = /^\s*$|^ (?=\S)/
33
-
34
- def paragraph text
35
- head, *body = text.lines.to_a
36
- head_indented = head =~ PARAGRAPH_INDENT
37
- body_indented = !body.empty? && body.all? {|s| s =~ PARAGRAPH_INDENT }
32
+ def indented_paragraph text
33
+ "\n.IP\n#{text}\n"
34
+ end
38
35
 
39
- if head_indented || body_indented
40
- macro = if head_indented && body_indented then :IP else :TP end
41
- text.gsub! PARAGRAPH_INDENT, ''
42
- else
43
- macro = :PP
44
- text.chomp!
45
- end
36
+ def tagged_paragraph text
37
+ "\n.TP\n#{text}\n"
38
+ end
46
39
 
47
- "\n.#{macro}\n#{text}\n"
40
+ def normal_paragraph text
41
+ "\n.PP\n#{text}\n"
48
42
  end
49
43
 
50
44
  def block_code code, language
@@ -1,3 +1,3 @@
1
1
  module Md2Man
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/man/man1/md2man.1 CHANGED
@@ -1,4 +1,4 @@
1
- .TH MD2MAN 1 "2012\-02\-02" "1.1.0"
1
+ .TH MD2MAN 1 2012\-02\-06 1.2.0
2
2
  .SH NAME
3
3
  .PP
4
4
  md2man \- convert
@@ -18,22 +18,19 @@ converts
18
18
  input from the given \fIFILE\fP into
19
19
  .BR roff (7)
20
20
  using
21
- Redcarpet2
21
+ Redcarpet
22
22
  .UR https://github.com/tanoku/redcarpet
23
23
  .UE
24
24
  and then prints the result to the standard output stream. If
25
25
  \fIFILE\fP is not given, then the standard input stream is read in its place.
26
- .SS Document Format
26
+ .SS Document format
27
27
  .PP
28
- The following additional semantics are attached to
29
- .BR markdown (7):
28
+ md2man extends
29
+ .BR markdown (7)
30
+ syntax in the following ways, as provisioned in the
31
+ \fB\fCMd2Man::Document\fR module and defined in its derivative \fB\fCMd2Man::Roff\fR module:
30
32
  .RS
31
33
  .IP \(bu 2
32
- There can be at most one top\-level heading (H1). It is emitted as \fB\fC.TH\fR
33
- in the
34
- .BR roff (7)
35
- output, specifying the UNIX man page's header and footer.
36
- .IP \(bu 2
37
34
  Paragraphs whose lines are all uniformly indented by two spaces are
38
35
  considered to be "indented paragraphs". They are unindented accordingly
39
36
  before emission as \fB\fC.IP\fR in the
@@ -46,14 +43,24 @@ are unindented accordingly before emission as \fB\fC.TP\fR in the
46
43
  .BR roff (7)
47
44
  output.
48
45
  .RE
49
- .SS Markdown Extensions
50
46
  .PP
51
- The following Redcarpet2
47
+ md2man extends
48
+ .BR markdown (7)
49
+ semantics in the following ways:
50
+ .RS
51
+ .IP \(bu 2
52
+ There can be at most one top\-level heading (H1). It is emitted as \fB\fC.TH\fR
53
+ in the
54
+ .BR roff (7)
55
+ output, defining the UNIX manual page's header and footer.
56
+ .RE
57
+ .SS Markdown extensions
58
+ .PP
59
+ The following Redcarpet
52
60
  .UR https://github.com/tanoku/redcarpet
53
61
  .UE
54
- extensions for
55
- .BR markdown (7)
56
- are enabled:
62
+ extensions are enabled while processing
63
+ .BR markdown (7):
57
64
  .RS
58
65
  .IP \(bu 2
59
66
  tables
@@ -71,8 +78,7 @@ fenced_code_blocks
71
78
  .SH OPTIONS
72
79
  .TP
73
80
  \fB\fC-h\fR, \fB\fC--help\fR
74
- Display this help manual using
75
- .BR man (1).
81
+ Show this help manual.
76
82
  .SH SEE ALSO
77
83
  .PP
78
84
  .BR markdown (7),
data/md2man.gemspec CHANGED
@@ -1,20 +1,20 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "md2man/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'md2man/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "md2man"
6
+ s.name = 'md2man'
7
7
  s.version = Md2Man::VERSION
8
8
  s.authors,
9
9
  s.email = File.read('LICENSE').scan(/Copyright \d+ (.+) <(.+?)>/).transpose
10
- s.homepage = "http://github.com/sunaku/md2man"
11
- s.summary = "Markdown to manpage."
12
- s.description = "Write UNIX man pages in Markdown."
10
+ s.homepage = 'http://github.com/sunaku/md2man'
11
+ s.summary = 'markdown to manpage'
12
+ s.description = 'Converts markdown documents into UNIX manual pages.'
13
13
 
14
- s.files = `git ls-files`.split("\n") + Dir["man/**/*"]
14
+ s.files = `git ls-files`.split("\n") + Dir['man/**/*']
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
- s.require_paths = ["lib"]
17
+ s.require_paths = ['lib']
18
18
 
19
19
  s.add_runtime_dependency 'binman', '~> 3'
20
20
  s.add_runtime_dependency 'redcarpet', '>= 2.1.0', '< 3'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md2man
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-03 00:00:00.000000000 Z
12
+ date: 2012-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: binman
16
- requirement: &24893480 !ruby/object:Gem::Requirement
16
+ requirement: &10700940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24893480
24
+ version_requirements: *10700940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redcarpet
27
- requirement: &24892820 !ruby/object:Gem::Requirement
27
+ requirement: &10729140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '3'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *24892820
38
+ version_requirements: *10729140
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: minitest
41
- requirement: &24891000 !ruby/object:Gem::Requirement
41
+ requirement: &10749980 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ! '>='
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: '3'
50
50
  type: :development
51
51
  prerelease: false
52
- version_requirements: *24891000
52
+ version_requirements: *10749980
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rake
55
- requirement: &24888980 !ruby/object:Gem::Requirement
55
+ requirement: &10742800 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -63,8 +63,8 @@ dependencies:
63
63
  version: '1'
64
64
  type: :development
65
65
  prerelease: false
66
- version_requirements: *24888980
67
- description: Write UNIX man pages in Markdown.
66
+ version_requirements: *10742800
67
+ description: Converts markdown documents into UNIX manual pages.
68
68
  email:
69
69
  - sunaku@gmail.com
70
70
  executables:
@@ -103,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  segments:
105
105
  - 0
106
- hash: -102355908338846194
106
+ hash: -3638600068202015028
107
107
  required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  none: false
109
109
  requirements:
@@ -112,13 +112,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: -102355908338846194
115
+ hash: -3638600068202015028
116
116
  requirements: []
117
117
  rubyforge_project:
118
118
  rubygems_version: 1.8.11
119
119
  signing_key:
120
120
  specification_version: 3
121
- summary: Markdown to manpage.
121
+ summary: markdown to manpage
122
122
  test_files:
123
123
  - test/md2man/roff_test.rb
124
124
  - test/test_helper.rb