Sha256: 7406e90e47c45de7b1a5bdcd46092f8f382848be5322aba7d5cb4b3626931bef

Contents?: true

Size: 1.35 KB

Versions: 4

Compression:

Stored size: 1.35 KB

Contents

require 'cgi'
require 'md2man/document'

module Md2Man::HTML

  include Md2Man::Document

  #---------------------------------------------------------------------------
  # block-level processing
  #---------------------------------------------------------------------------

  def normal_paragraph text
    "<p>#{text}</p>"
  end

  def tagged_paragraph text
    head, *body = text.lines.to_a
    "<dl><dt>#{head.chomp}</dt><dd>#{body.join}</dd></dl>"
  end

  def indented_paragraph text
    "<dl><dd>#{text}</dd></dl>"
  end

  def header text, level
    id = text.gsub(/<.+?>/, '-').        # strip all HTML tags
      gsub(/\W+/, '-').gsub(/^-|-$/, '') # fold non-word chars
    %{<h#{level} id="#{id}">#{text}</h#{level}>}
  end

  #---------------------------------------------------------------------------
  # span-level processing
  #---------------------------------------------------------------------------

  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-xref" href="#{url}">#{input_match}</a>}
    end + output_match[:addendum].to_s
  end

  # You can override this in a derived class to compute URLs as you like!
  def reference_url page, section
    "../man#{section}/#{page}.#{section}.html"
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
md2man-2.0.3 lib/md2man/html.rb
md2man-2.0.2 lib/md2man/html.rb
md2man-2.0.1 lib/md2man/html.rb
md2man-2.0.0 lib/md2man/html.rb