module Md2Man::HTML
Constants
- ENGINE
- HEADER_PARTS
see “Title line” in man-pages(7) or “Top-level headings” in md2man(5)
- SYNTAX_HIGHLIGHTER
Public Instance Methods
block_code(code, language)
click to toggle source
Calls superclass method
Md2Man::Document#block_code
# File lib/md2man/html.rb, line 72 def block_code code, language SYNTAX_HIGHLIGHTER.block_code super, language end
codespan(code)
click to toggle source
# File lib/md2man/html.rb, line 80 def codespan code "<code>#{CGI.escape_html super}</code>" end
header(text, level, _=nil)
click to toggle source
# File lib/md2man/html.rb, line 39 def header text, level, _=nil if level == 1 and not @h1_seen @h1_seen = true text = CGI.unescape_html(text) # unescape " for Shellwords.split() text = Shellwords.split(text).zip(HEADER_PARTS).map do |value, part| part ? %{<span class="md2man-#{part}">#{value}</span>} : value end.compact.join(' ') end # decode here, since we will emit this heading below as raw HTML anyway text = decode_references(text) # strip all HTML tags, squeeze all non-word characters, and lowercase it id = text.gsub(/<.+?>/, '-').gsub(/\W+/, '-').gsub(/^-|-$/, '').downcase # make duplicate anchors unique by appending numerical suffixes to them count = @seen_count_by_id[id] += 1 id += "-#{count - 1}" if count > 1 [ %{<h#{level} id="#{id}">}, text, %{<a name="#{id}" href="##{id}" class="md2man-permalink" title="permalink"></a>}, "</h#{level}>", ].join end
indented_paragraph(text)
click to toggle source
# File lib/md2man/html.rb, line 32 def indented_paragraph text "<dl><dd>#{text}</dd></dl>" end
normal_paragraph(text)
click to toggle source
# File lib/md2man/html.rb, line 23 def normal_paragraph text "<p>#{text}</p>" end
preprocess(document)
click to toggle source
Calls superclass method
Md2Man::Document#preprocess
# File lib/md2man/html.rb, line 13 def preprocess document @h1_seen = false @seen_count_by_id = Hash.new {|h,k| h[k] = 0 } super end
reference(input_match, output_match)
click to toggle source
# File lib/md2man/html.rb, line 84 def reference input_match, output_match if output_match.pre_match =~ /<[^>]*\z/ input_match.to_s else url = reference_url(input_match[:page], input_match[:section]) %{<a class="md2man-reference" href="#{url}">#{input_match}</a>} end + output_match[:addendum].to_s end
reference_url(page, section)
click to toggle source
You can override this in a derived class to compute URLs as you like!
# File lib/md2man/html.rb, line 94 def reference_url page, section "../man#{section}/#{page}.#{section}.html" end
tagged_paragraph(text)
click to toggle source
# File lib/md2man/html.rb, line 27 def tagged_paragraph text head, *body = text.lines.to_a "<dl><dt>#{head.chomp}</dt><dd>#{body.join}</dd></dl>" end