-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(the ISC license) | ||
|
||
Copyright 2011 Suraj N. Kurapati <sunaku@gmail.com> | ||
|
||
Permission to use, copy, modify, and/or distribute this software for any | ||
purpose with or without fee is hereby granted, provided that the above | ||
copyright notice and this permission notice appear in all copies. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
require 'redcarpet' | ||
require 'redcarpet/render_man' | ||
|
||
module BinMan | ||
class Renderer < Redcarpet::Render::ManPage | ||
def normal_text text | ||
text.gsub(/(?<=\W)-(?=\W)/, '\\-') if text | ||
end | ||
|
||
def paragraph(text) | ||
"\n.PP\n#{text}\n" | ||
end | ||
|
||
alias codespan double_emphasis | ||
alias triple_emphasis double_emphasis | ||
|
||
def autolink link, link_type | ||
emphasis link | ||
end | ||
|
||
def link link, title, content | ||
"#{triple_emphasis content} #{emphasis link}" | ||
end | ||
|
||
DEFINITION_INDENT = ' ' # two spaces | ||
|
||
def postprocess document | ||
document. | ||
# squeeze blank lines to prevent double-spaced output | ||
gsub(/^\n/, ''). | ||
|
||
# first paragraphs inside list items | ||
gsub(/^(\.IP.*)\n\.PP/, '\1'). | ||
|
||
# paragraphs beginning with bold/italic and followed by | ||
# at least one definition-indented line are definitions | ||
gsub(/^\.PP(?=\n\\f.+\n#{DEFINITION_INDENT}\S)/, '.TP'). | ||
|
||
# make indented paragraphs occupy less space on screen: | ||
# roff will fit the second line of the paragraph along | ||
# side the first line if it has enough room to do so! | ||
gsub(/^#{DEFINITION_INDENT}(?=\S)/, ''). | ||
|
||
# encode references to other man pages as "hyperlinks" | ||
gsub(/(\w+)(\([1-9nol]\)[[:punct:]]?\s*)/, "\n.BR \\1 \\2\n"). | ||
# keep the SEE ALSO sequence of references in-line | ||
gsub(/(?:^\.BR.+\n)+/m){ |sequence| sequence.squeeze("\n") } | ||
end | ||
end | ||
|
||
RENDERER = Redcarpet::Markdown.new(Renderer, | ||
#:tables => true, | ||
:autolink => true, | ||
#:superscript => true, | ||
:no_intra_emphasis => true, | ||
:fenced_code_blocks => true, | ||
:space_after_headers => true) | ||
end |