redcarpet-manpage 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/LICENSE +16 -0
- data/README.markdown +78 -0
- data/Rakefile +1 -0
- data/lib/redcarpet-manpage.rb +107 -0
- data/lib/redcarpet-manpage/version.rb +3 -0
- data/redcarpet-manpage.gemspec +23 -0
- metadata +66 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
(the ISC license)
|
2
|
+
|
3
|
+
Copyright 2011 Vicent Martí <vicent@github.com>
|
4
|
+
Copyright 2011 Suraj N. Kurapati <sunaku@gmail.com>
|
5
|
+
|
6
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
7
|
+
purpose with or without fee is hereby granted, provided that the above
|
8
|
+
copyright notice and this permission notice appear in all copies.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
11
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
12
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
13
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
14
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
15
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
16
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
RedcarpetManpage - UNIX man page renderer for Redcarpet2
|
2
|
+
========================================================
|
3
|
+
|
4
|
+
RedcarpetManpage is a Ruby library that converts [Markdown] documents into
|
5
|
+
UNIX man pages ([roff] documents) using the awesome [Redcarpet2] library.
|
6
|
+
|
7
|
+
[Markdown]: http://daringfireball.net/projects/markdown/
|
8
|
+
[roff]: http://man.cx/roff(7)
|
9
|
+
[Redcarpet2]: https://github.com/tanoku/redcarpet
|
10
|
+
|
11
|
+
------------------------------------------------------------------------------
|
12
|
+
Installation
|
13
|
+
------------------------------------------------------------------------------
|
14
|
+
|
15
|
+
As a Ruby gem:
|
16
|
+
|
17
|
+
gem install redcarpet-manpage
|
18
|
+
|
19
|
+
As a Git clone:
|
20
|
+
|
21
|
+
git clone git://github.com/sunaku/redcarpet-manpage
|
22
|
+
cd redcarpet-manpage
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
------------------------------------------------------------------------------
|
26
|
+
Specification
|
27
|
+
------------------------------------------------------------------------------
|
28
|
+
|
29
|
+
### Markdown Processing Extensions
|
30
|
+
|
31
|
+
`RedcarpetManpage::RENDERER` enables the following [Redcarpet2] extensions:
|
32
|
+
|
33
|
+
* `autolink`
|
34
|
+
* `no_intra_emphasis`
|
35
|
+
* `fenced_code_blocks`
|
36
|
+
* `space_after_headers`
|
37
|
+
|
38
|
+
### Markdown Processing Divergence
|
39
|
+
|
40
|
+
Although your input documents are written in [Markdown], RedcarpetManpage
|
41
|
+
introduces the following additional conventions to simplify common tasks:
|
42
|
+
|
43
|
+
1. Paragraphs beginning with bold/italic and followed by at least
|
44
|
+
one two-space indented line are considered to be definitions.
|
45
|
+
The first line of such a paragraph is the term being defined and
|
46
|
+
the subsequent two-space indented lines are the definition body.
|
47
|
+
|
48
|
+
------------------------------------------------------------------------------
|
49
|
+
Usage
|
50
|
+
------------------------------------------------------------------------------
|
51
|
+
|
52
|
+
Use the default renderer:
|
53
|
+
|
54
|
+
``` ruby
|
55
|
+
require 'redcarpet-manpage'
|
56
|
+
your_roff_output = RedcarpetManpage::RENDERER.render(your_markdown_input)
|
57
|
+
```
|
58
|
+
|
59
|
+
Or extend it for yourself:
|
60
|
+
|
61
|
+
``` ruby
|
62
|
+
require 'redcarpet-manpage'
|
63
|
+
|
64
|
+
class YourManpageRenderer < RedcarpetManpage::Renderer
|
65
|
+
# ... your stuff here ...
|
66
|
+
# See Redcarpet::Render::Base documentation for more information:
|
67
|
+
# http://rdoc.info/github/tanoku/redcarpet/master/Redcarpet/Render/Base
|
68
|
+
end
|
69
|
+
|
70
|
+
renderer = Redcarpet::Markdown.new(YourManpageRenderer, your_options_hash)
|
71
|
+
your_roff_output = renderer.render(your_markdown_input)
|
72
|
+
```
|
73
|
+
|
74
|
+
------------------------------------------------------------------------------
|
75
|
+
License
|
76
|
+
------------------------------------------------------------------------------
|
77
|
+
|
78
|
+
Released under the ISC license. See the LICENSE file for details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
|
3
|
+
module RedcarpetManpage
|
4
|
+
|
5
|
+
class Renderer < Redcarpet::Render::Base
|
6
|
+
def normal_text(text)
|
7
|
+
text.gsub(/(?<=\W)-(?=\W)/, '\\-') if text
|
8
|
+
end
|
9
|
+
|
10
|
+
def triple_emphasis(text)
|
11
|
+
"\\fB#{text}\\fP"
|
12
|
+
end
|
13
|
+
|
14
|
+
alias double_emphasis triple_emphasis
|
15
|
+
|
16
|
+
def emphasis(text)
|
17
|
+
"\\fI#{text}\\fP"
|
18
|
+
end
|
19
|
+
|
20
|
+
def block_code(code, language)
|
21
|
+
"\n.nf\n#{normal_text(code)}\n.fi\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
alias codespan double_emphasis
|
25
|
+
|
26
|
+
def link(link, title, content)
|
27
|
+
"#{triple_emphasis(content)} #{emphasis(link)}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def autolink(link, link_type)
|
31
|
+
emphasis(link)
|
32
|
+
end
|
33
|
+
|
34
|
+
def header(title, level)
|
35
|
+
case level
|
36
|
+
when 1
|
37
|
+
"\n.TH #{title}\n"
|
38
|
+
|
39
|
+
when 2
|
40
|
+
"\n.SH #{title}\n"
|
41
|
+
|
42
|
+
when 3
|
43
|
+
"\n.SS #{title}\n"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def paragraph(text)
|
48
|
+
"\n.PP\n#{text}\n"
|
49
|
+
end
|
50
|
+
|
51
|
+
def linebreak
|
52
|
+
"\n.LP\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def list(content, list_type)
|
56
|
+
case list_type
|
57
|
+
when :ordered
|
58
|
+
"\n\n.nr step 0 1\n#{content}\n"
|
59
|
+
when :unordered
|
60
|
+
"\n.\n#{content}\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def list_item(content, list_type)
|
65
|
+
case list_type
|
66
|
+
when :ordered
|
67
|
+
".IP \\n+[step]\n#{content.strip}\n"
|
68
|
+
when :unordered
|
69
|
+
".IP \\[bu] 2 \n#{content.strip}\n"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
DEFINITION_INDENT = ' ' # two spaces
|
74
|
+
|
75
|
+
def postprocess document
|
76
|
+
document.
|
77
|
+
# squeeze blank lines to prevent double-spaced output
|
78
|
+
gsub(/^\n/, '').
|
79
|
+
|
80
|
+
# first paragraphs inside list items
|
81
|
+
gsub(/^(\.IP.*)\n\.PP/, '\1').
|
82
|
+
|
83
|
+
# paragraphs beginning with bold/italic and followed by
|
84
|
+
# at least one definition-indented line are definitions
|
85
|
+
gsub(/^\.PP(?=\n\\f.+\n#{DEFINITION_INDENT}\S)/, '.TP').
|
86
|
+
|
87
|
+
# make indented paragraphs occupy less space on screen:
|
88
|
+
# roff will fit the second line of the paragraph along
|
89
|
+
# side the first line if it has enough room to do so!
|
90
|
+
gsub(/^#{DEFINITION_INDENT}(?=\S)/, '').
|
91
|
+
|
92
|
+
# encode references to other man pages as "hyperlinks"
|
93
|
+
gsub(/(\w+)(\([1-9nol]\)[[:punct:]]?\s*)/, "\n.BR \\1 \\2\n").
|
94
|
+
# keep the SEE ALSO sequence of references in-line
|
95
|
+
gsub(/(?:^\.BR.+\n)+/m){ |sequence| sequence.squeeze("\n") }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
RENDERER = Redcarpet::Markdown.new(Renderer,
|
100
|
+
#:tables => true,
|
101
|
+
:autolink => true,
|
102
|
+
#:superscript => true,
|
103
|
+
:no_intra_emphasis => true,
|
104
|
+
:fenced_code_blocks => true,
|
105
|
+
:space_after_headers => true)
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "redcarpet-manpage/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "redcarpet-manpage"
|
7
|
+
s.version = RedcarpetManpage::VERSION
|
8
|
+
s.authors,
|
9
|
+
s.email = File.read('LICENSE').scan(/Copyright \d+ (.+) <(.+?)>/).transpose
|
10
|
+
s.homepage = "http://github.com/sunaku/redcarpet-manpage"
|
11
|
+
s.summary = "UNIX man page renderer for Redcarpet2"
|
12
|
+
s.description = nil
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
# specify any dependencies here; for example:
|
20
|
+
# s.add_development_dependency "rspec"
|
21
|
+
# s.add_runtime_dependency "rest-client"
|
22
|
+
s.add_runtime_dependency "redcarpet", ">= 2.0.0b5"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redcarpet-manpage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vicent Martí
|
9
|
+
- Suraj N. Kurapati
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-10-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redcarpet
|
17
|
+
requirement: &14053840 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0b5
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *14053840
|
26
|
+
description: ''
|
27
|
+
email:
|
28
|
+
- vicent@github.com
|
29
|
+
- sunaku@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.markdown
|
38
|
+
- Rakefile
|
39
|
+
- lib/redcarpet-manpage.rb
|
40
|
+
- lib/redcarpet-manpage/version.rb
|
41
|
+
- redcarpet-manpage.gemspec
|
42
|
+
homepage: http://github.com/sunaku/redcarpet-manpage
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.11
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: UNIX man page renderer for Redcarpet2
|
66
|
+
test_files: []
|