module Md2Man::Document
Constants
- PARAGRAPH_INDENT
Public Instance Methods
block_code(code, language)
click to toggle source
# File lib/md2man/document.rb, line 60 def block_code code, language decode_references code, true end
codespan(code)
click to toggle source
# File lib/md2man/document.rb, line 68 def codespan code decode_references (code || ' '), true end
indented_paragraph(text)
click to toggle source
# File lib/md2man/document.rb, line 48 def indented_paragraph text warn "md2man/document: indented_paragraph not implemented: #{text.inspect}" end
normal_paragraph(text)
click to toggle source
# File lib/md2man/document.rb, line 56 def normal_paragraph text warn "md2man/document: normal_paragraph not implemented: #{text.inspect}" end
paragraph(text)
click to toggle source
This method blocks Redcarpet's default behavior, which cannot be accessed using super() due to the limitation of how Redcarpet is implemented in C. See github.com/vmg/redcarpet/issues/51 for the complete details.
We don't call super() here deliberately: to replace paragraph nodes with normal_paragraph
, tagged_paragraph
, or indented_paragraph
as appropriate.
# File lib/md2man/document.rb, line 31 def paragraph text head, *body = text.lines.to_a head_indented = head =~ PARAGRAPH_INDENT body_indented = !body.empty? && body.all? {|s| s =~ PARAGRAPH_INDENT } if head_indented || body_indented text = text.gsub(PARAGRAPH_INDENT, '') if head_indented && (body_indented || body.empty?) indented_paragraph text else tagged_paragraph text end else normal_paragraph text.chomp end end
postprocess(document)
click to toggle source
# File lib/md2man/document.rb, line 14 def postprocess document decode_references document end
preprocess(document)
click to toggle source
# File lib/md2man/document.rb, line 9 def preprocess document @references = {} encode_references document end
reference(input_match, output_match)
click to toggle source
# File lib/md2man/document.rb, line 72 def reference input_match, output_match warn "md2man/document: reference not implemented: #{input_match}" end
tagged_paragraph(text)
click to toggle source
# File lib/md2man/document.rb, line 52 def tagged_paragraph text warn "md2man/document: tagged_paragraph not implemented: #{text.inspect}" end
Protected Instance Methods
encode(object)
click to toggle source
# File lib/md2man/document.rb, line 78 def encode object "\0#{object.object_id}\0" end
Private Instance Methods
decode_references(text, restore_original=false)
click to toggle source
# File lib/md2man/document.rb, line 93 def decode_references text, restore_original=false @references.delete_if do |key, input_match| # the [^\S\n] captures all non-newline whitespace # basically, it's meant to be \s but excluding \n text.sub! /#{Regexp.escape key}(?<addendum>\S*[^\S\n]*)/ do output_match = $~ if restore_original input_match.to_s + output_match[:addendum] else reference input_match, output_match end end end text end
encode_references(text)
click to toggle source
# File lib/md2man/document.rb, line 84 def encode_references text text.gsub(/(?<page>[\w\-\.]+)\((?<section>\w+)\)/) do match = $~ key = encode(match) @references[key] = match key end end