class Kramdown::Converter::Man
Converts a Kramdown::Document
to a manpage in groff format. See man(7), groff_man(7) and man-pages(7) for information regarding the output.
Constants
- TABLE_CELL_ALIGNMENT
- TYPOGRAPHIC_SYMS_MAP
Private Instance Methods
convert_a(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 191 def convert_a(el, opts) 192 if el.children.size == 1 && el.children[0].type == :text && 193 el.attr['href'] == el.children[0].value 194 newline(opts[:result]) << macro("UR", escape(el.attr['href'])) << macro("UE") 195 elsif el.attr['href'].start_with?('mailto:') 196 newline(opts[:result]) << macro("MT", escape(el.attr['href'].sub(/^mailto:/, ''))) << 197 macro("UE") 198 else 199 newline(opts[:result]) << macro("UR", escape(el.attr['href'])) 200 inner(el, opts) 201 newline(opts[:result]) << macro("UE") 202 end 203 end
convert_abbreviation(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 229 def convert_abbreviation(el, opts) 230 opts[:result] << escape(el.value) 231 end
convert_blank(*)
click to toggle source
# File lib/kramdown/converter/man.rb 46 def convert_blank(*) 47 end
Also aliased as: convert_hr, convert_xml_pi
convert_blockquote(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 94 def convert_blockquote(el, opts) 95 opts[:result] << macro("RS") 96 inner(el, opts) 97 opts[:result] << macro("RE") 98 end
convert_br(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 225 def convert_br(el, opts) 226 newline(opts[:result]) << macro("br") 227 end
convert_codeblock(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 88 def convert_codeblock(el, opts) 89 opts[:result] << macro("sp") << macro("RS", 4) << macro("EX") 90 opts[:result] << newline(escape(el.value, true)) 91 opts[:result] << macro("EE") << macro("RE") 92 end
convert_codespan(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 221 def convert_codespan(el, opts) 222 opts[:result] << "\\fB#{escape(el.value)}\\fP" 223 end
convert_dd(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 126 def convert_dd(el, opts) 127 inner(el, opts, :first) 128 if el.children.size > 1 129 opts[:result] << macro("RS") 130 inner(el, opts, :rest) 131 opts[:result] << macro("RE") 132 end 133 opts[:result] << macro("sp") if opts[:next] && opts[:next].type == :dd 134 end
convert_dt(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 120 def convert_dt(el, opts) 121 opts[:result] << macro(opts[:prev] && opts[:prev].type == :dt ? "TQ" : "TP") 122 inner(el, opts) 123 opts[:result] << "\n" 124 end
convert_em(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 209 def convert_em(el, opts) 210 opts[:result] << '\fI' 211 inner(el, opts) 212 opts[:result] << '\fP' 213 end
convert_entity(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 257 def convert_entity(el, opts) 258 opts[:result] << unicode_char(el.value.code_point) 259 end
convert_footnote(*)
click to toggle source
# File lib/kramdown/converter/man.rb 241 def convert_footnote(*) 242 warning("Footnotes are not supported") 243 end
convert_header(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 60 def convert_header(el, opts) 61 return unless opts[:parent].type == :root 62 case el.options[:level] 63 when 1 64 unless @title_done 65 @title_done = true 66 data = el.options[:raw_text].scan(/([^(]+)\s*\((\d\w*)\)(?:\s*-+\s*(.*))?/).first || 67 el.options[:raw_text].scan(/([^\s]+)\s*(?:-*\s+)?()(.*)/).first 68 return unless data && data[0] 69 name = data[0] 70 section = (data[1].to_s.empty? ? el.attr['data-section'] || '7' : data[1]) 71 description = (data[2].to_s.empty? ? nil : " - #{data[2]}") 72 date = el.attr['data-date'] ? quote(el.attr['data-date']) : nil 73 extra = (el.attr['data-extra'] ? quote(escape(el.attr['data-extra'].to_s)) : nil) 74 opts[:result] << macro("TH", quote(escape(name.upcase)), quote(section), date, extra) 75 if description 76 opts[:result] << macro("SH", "NAME") << escape("#{name}#{description}") << "\n" 77 end 78 end 79 when 2 80 opts[:result] << macro("SH", quote(escape(el.options[:raw_text]))) 81 when 3 82 opts[:result] << macro("SS", quote(escape(el.options[:raw_text]))) 83 else 84 warning("Header levels greater than three are not supported") 85 end 86 end
convert_html_element(*)
click to toggle source
# File lib/kramdown/converter/man.rb 181 def convert_html_element(*) 182 warning("HTML elements are not supported") 183 end
convert_img(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 205 def convert_img(el, opts) 206 warning("Images are not supported") 207 end
convert_li(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 109 def convert_li(el, opts) 110 sym = (opts[:parent].type == :ul ? '\(bu' : "#{opts[:index] + 1}.") 111 opts[:result] << macro("IP", sym, 4) 112 inner(el, opts, :first) 113 if el.children.size > 1 114 opts[:result] << macro("RS") 115 inner(el, opts, :rest) 116 opts[:result] << macro("RE") 117 end 118 end
convert_math(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 233 def convert_math(el, opts) 234 if el.options[:category] == :block 235 convert_codeblock(el, opts) 236 else 237 convert_codespan(el, opts) 238 end 239 end
convert_p(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 51 def convert_p(el, opts) 52 if (opts[:index] != 0 && opts[:prev].type != :header) || 53 (opts[:parent].type == :blockquote && opts[:index] == 0) 54 opts[:result] << macro("P") 55 end 56 inner(el, opts) 57 newline(opts[:result]) 58 end
convert_raw(*)
click to toggle source
# File lib/kramdown/converter/man.rb 245 def convert_raw(*) 246 warning("Raw content is not supported") 247 end
convert_root(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 39 def convert_root(el, opts) 40 @title_done = false 41 opts[:result] = ".\\\" generated by kramdown\n" 42 inner(el, opts) 43 opts[:result] 44 end
convert_smart_quote(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 261 def convert_smart_quote(el, opts) 262 opts[:result] << unicode_char(::Kramdown::Utils::Entities.entity(el.value.to_s).code_point) 263 end
convert_strong(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 215 def convert_strong(el, opts) 216 opts[:result] << '\fB' 217 inner(el, opts) 218 opts[:result] << '\fP' 219 end
convert_table(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 138 def convert_table(el, opts) 139 opts[:alignment] = el.options[:alignment].map {|a| TABLE_CELL_ALIGNMENT[a]} 140 table_options = ["box"] 141 table_options << "center" if el.attr['class'] =~ /\bcenter\b/ 142 opts[:result] << macro("TS") << "#{table_options.join(" ")} ;\n" 143 inner(el, opts) 144 opts[:result] << macro("TE") << macro("sp") 145 end
convert_tbody(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 153 def convert_tbody(el, opts) 154 opts[:result] << ".T&\n" if opts[:index] != 0 155 opts[:result] << opts[:alignment].join(' ') << " .\n" 156 inner(el, opts) 157 opts[:result] << (opts[:next].type == :tfoot ? "=\n" : "_\n") if opts[:next] 158 end
convert_td(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 169 def convert_td(el, opts) 170 result = opts[:result] 171 opts[:result] = '' 172 inner(el, opts) 173 if opts[:result] =~ /\n/ 174 warning("Table cells using links are not supported") 175 result << "\t" 176 else 177 result << opts[:result] << "\t" 178 end 179 end
convert_text(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 251 def convert_text(el, opts) 252 text = escape(el.value) 253 text.lstrip! if opts[:result][-1] == ?\n 254 opts[:result] << text 255 end
convert_tfoot(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 160 def convert_tfoot(el, opts) 161 inner(el, opts) 162 end
convert_thead(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 147 def convert_thead(el, opts) 148 opts[:result] << opts[:alignment].map {|a| "#{a}b"}.join(' ') << " .\n" 149 inner(el, opts) 150 opts[:result] << "=\n" 151 end
convert_tr(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 164 def convert_tr(el, opts) 165 inner(el, opts) 166 opts[:result] << "\n" 167 end
convert_typographic_sym(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 270 def convert_typographic_sym(el, opts) 271 opts[:result] << TYPOGRAPHIC_SYMS_MAP[el.value] 272 end
convert_ul(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 100 def convert_ul(el, opts) 101 compact = (el.attr['class'] =~ /\bcompact\b/) 102 opts[:result] << macro("sp") << macro("PD", 0) if compact 103 inner(el, opts) 104 opts[:result] << macro("PD") if compact 105 end
Also aliased as: convert_dl, convert_ol
convert_xml_comment(el, opts)
click to toggle source
# File lib/kramdown/converter/man.rb 185 def convert_xml_comment(el, opts) 186 newline(opts[:result]) << ".\"#{escape(el.value, true).rstrip.gsub(/\n/, "\n.\"")}\n" 187 end
Also aliased as: convert_comment
escape(text, preserve_whitespace = false)
click to toggle source
# File lib/kramdown/converter/man.rb 287 def escape(text, preserve_whitespace = false) 288 text = (preserve_whitespace ? text.dup : text.gsub(/\s+/, ' ')) 289 text.gsub!('\\', "\\e") 290 text.gsub!(/^\./, '\\\\&.') 291 text.gsub!(/[.'-]/) {|m| "\\#{m}"} 292 text 293 end
inner(el, opts, use = :all)
click to toggle source
# File lib/kramdown/converter/man.rb 25 def inner(el, opts, use = :all) 26 arr = el.children.reject {|e| e.type == :blank} 27 arr.each_with_index do |inner_el, index| 28 next if use == :rest && index == 0 29 break if use == :first && index > 0 30 options = opts.dup 31 options[:parent] = el 32 options[:index] = index 33 options[:prev] = (index == 0 ? nil : arr[index - 1]) 34 options[:next] = (index == arr.length - 1 ? nil : arr[index + 1]) 35 convert(inner_el, options) 36 end 37 end
macro(name, *args)
click to toggle source
# File lib/kramdown/converter/man.rb 274 def macro(name, *args) 275 ".#{[name, *args].compact.join(' ')}\n" 276 end
newline(text)
click to toggle source
# File lib/kramdown/converter/man.rb 278 def newline(text) 279 text << "\n" unless text[-1] == ?\n 280 text 281 end
quote(text)
click to toggle source
# File lib/kramdown/converter/man.rb 283 def quote(text) 284 "\"#{text.gsub(/"/, '\\"')}\"" 285 end
unicode_char(codepoint)
click to toggle source
# File lib/kramdown/converter/man.rb 295 def unicode_char(codepoint) 296 "\\[u#{codepoint.to_s(16).rjust(4, '0')}]" 297 end