Skip to content

Commit

Permalink
Merge branch 'binman-import'
Browse files Browse the repository at this point in the history
  • Loading branch information
sunaku committed Oct 13, 2011
2 parents 50f1330 + b4c851f commit 260c3fd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
15 changes: 15 additions & 0 deletions LICENSE
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.
58 changes: 58 additions & 0 deletions lib/binman/renderer.rb
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

0 comments on commit 260c3fd

Please sign in to comment.