lib/kramdown/converter/man.rb in kramdown-man-0.1.8 vs lib/kramdown/converter/man.rb in kramdown-man-0.1.9

- old
+ new

@@ -1,6 +1,7 @@ -# encoding: utf-8 +# frozen_string_literal: true + require_relative '../man/version' require 'kramdown/converter/base' module Kramdown @@ -701,11 +702,11 @@ first_line = convert_children(children[0...newline]) rest = convert_children(children[newline..-1]).strip ".TP\n#{first_line}\n#{rest}" else - ".HP\n#{convert_children(children)}" + ".PP\n#{convert_children(children)}" end else ".PP\n#{convert_children(children)}" end end @@ -758,23 +759,30 @@ # @return [String] # The roff output. # def convert_a(a) href = escape(a.attr['href']) + scheme, path = href.split(':',2) + text = convert_children(a.children) - case href - when /^mailto:/ - email = href[7..-1] + case scheme + when 'mailto' + email = path - unless text == email then "#{text}\n.MT #{email}\n.ME" - else "\n.MT #{email}\n.ME" + unless text == email + "#{text}\n.MT #{email}\n.ME" + else + "\n.MT #{email}\n.ME" end - when /^man:/ - match = href.match(/man:([A-Za-z0-9_-]+)(?:\((\d[a-z]?)\))?/) + when 'man' + if (match = path.match(/\A(?<page>[A-Za-z0-9_-]+)(?:\((?<section>\d[a-z]?)\)|\\\.(?<section>\d[a-z]?))\z/)) + page = match[:page] + section = match[:section] - if match[2] then "\n.BR #{match[1]} (#{match[2]})" - else "\n.BR #{match[1]}" + "\n.BR #{page} (#{section})" + else + "\n.BR #{path}" end else "#{text}\n.UR #{href}\n.UE" end end