Class: Kramdown::Man::Converter Private
- Inherits:
-
Converter::Base
- Object
- Converter::Base
- Kramdown::Man::Converter
- Defined in:
- lib/kramdown/man/converter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Converts markdown into a roff man-page.
Constant Summary collapse
- HEADER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Comment header
<<~ROFF .\\\" Generated by kramdown-man #{VERSION} .\\\" https://github.com/postmodern/kramdown-man#readme ROFF
- TYPOGRAPHIC_SYMS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Typographic Symbols and their UTF8 chars
{ :ndash => '\-\-', :mdash => '\[em]', :hellip => '\.\.\.', :laquo => '\[Fo]', :raquo => '\[Fc]', :laquo_space => '\[Fo]', :raquo_space => '\[Fc]' }
- SMART_QUOTES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Smart Quotes and their UTF8 chars
{ :lsquo => '\[oq]', :rsquo => '\[cq]', :ldquo => '\[lq]', :rdquo => '\[rq]' }
- GLYPHS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 'Ð' => '\[-D]', 'ð' => '\[Sd]', 'Þ' => '\[TP]', 'þ' => '\[Tp]', 'ß' => '\[ss]', # Ligatures and Other Latin Glyphs 'ff' => '\[ff]', 'fi' => '\[fi]', 'fl' => '\[fl]', 'ffi' => '\[Fi]', 'ffl' => '\[Fl]', 'Ł' => '\[/L]', 'ł' => '\[/l]', 'Ø' => '\[/O]', 'ø' => '\[/o]', 'Æ' => '\[AE]', 'æ' => '\[ae]', 'Œ' => '\[OE]', 'œ' => '\[oe]', 'IJ' => '\[IJ]', 'ij' => '\[ij]', 'ı' => '\[.i]', 'ȷ' => '\[.j]', # Accented Characters 'Á' => '\[\'A]', 'Ć' => '\[\'C]', 'É' => '\[\'E]', 'Í' => '\[\'I]', 'Ó' => '\[\'O]', 'Ú' => '\[\'U]', 'Ý' => '\[\'Y]', 'á' => '\[\'a]', 'ć' => '\[\'c]', 'é' => '\[\'e]', 'í' => '\[\'i]', 'ó' => '\[\'o]', 'ú' => '\[\'u]', 'ý' => '\[\'y]', 'Ä' => '\[:A]', 'Ë' => '\[:E]', 'Ï' => '\[:I]', 'Ö' => '\[:O]', 'Ü' => '\[:U]', 'Ÿ' => '\[:Y]', 'ä' => '\[:a]', 'ë' => '\[:e]', 'ï' => '\[:i]', 'ö' => '\[:o]', 'ü' => '\[:u]', 'ÿ' => '\[:y]', 'Â' => '\[^A]', 'Ê' => '\[^E]', 'Î' => '\[^I]', 'Ô' => '\[^O]', 'Û' => '\[^U]', 'â' => '\[^a]', 'ê' => '\[^e]', 'î' => '\[^i]', 'ô' => '\[^o]', 'û' => '\[^u]', 'À' => '\[`A]', 'È' => '\[`E]', 'Ì' => '\[`I]', 'Ò' => '\[`O]', 'Ù' => '\[`U]', 'à' => '\[`a]', 'è' => '\[`e]', 'ì' => '\[`i]', 'ò' => '\[`o]', 'ù' => '\[`u]', 'Ã' => '\[~A]', 'Ñ' => '\[~N]', 'Õ' => '\[~O]', 'ã' => '\[~a]', 'ñ' => '\[~n]', 'õ' => '\[~o]', 'Š' => '\[vS]', 'š' => '\[vs]', 'Ž' => '\[vZ]', 'ž' => '\[vz]', 'Ç' => '\[,C]', 'ç' => '\[,c]', 'Å' => '\[oA]', 'å' => '\[oa]', # Accents '˝' => '\[a"]', '¯' => '\[a-]', '˙' => '\[a.]', # '^' => '\[a^]', '´' => "\\´", '`' => '\`', '˘' => '\[ab]', '¸' => '\[ac]', '¨' => '\[ad]', 'ˇ' => '\[ah]', '˚' => '\[ao]', # '~' => '\(ti', '˛' => '\[ho]', '^' => '\(ha', '~' => '\[ti]', # Quotes '„' => '\[Bq]', '‚' => '\[bq]', '“' => '\[lq]', '”' => '\[rq]', '‘' => '\[oq]', '’' => '\[cq]', "'" => '\(aq', '"' => '\[dq]', '«' => '\[Fo]', '»' => '\[Fc]', '‹' => '\[fo]', '›' => '\[fc]', # Punctuation '.' => '\.', '¡' => '\[r!]', '¿' => '\[r?]', '—' => '\[em]', '–' => '\[en]', '‐' => '\[hy]', # Brackets '[' => '\[lB]', ']' => '\[rB]', '{' => '\[lC]', '}' => '\[rC]', '⟨' => '\[la]', '⟩' => '\[ra]', # '⎪' => '\[bv]', # '⎪' => '\[braceex]', '⎡' => '\[bracketlefttp]', '⎣' => '\[bracketleftbt]', '⎢' => '\[bracketleftex]', '⎤' => '\[bracketrighttp]', '⎦' => '\[bracketrightbt]', '⎥' => '\[bracketrightex]', '╭' => '\[lt]', '⎧' => '\[bracelefttp]', '┥' => '\[lk]', '⎨' => '\[braceleftmid]', '╰' => '\[lb]', '⎩' => '\[braceleftbt]', # '⎪' => '\[braceleftex]', '╮' => '\[rt]', '⎫' => '\[bracerighttp]', '┝' => '\[rk]', '⎬' => '\[bracerightmid]', '╯' => '\[rb]', '⎭' => '\[bracerightbt]', '⎪' => '\[bracerightex]', '⎛' => '\[parenlefttp]', '⎝' => '\[parenleftbt]', '⎜' => '\[parenleftex]', '⎞' => '\[parenrighttp]', '⎠' => '\[parenrightbt]', '⎟' => '\[parenrightex]', # Arrows '←' => '\[<-]', '→' => '\[->]', '↔' => '\[<>]', '↓' => '\[da]', '↑' => '\[ua]', '↕' => '\[va]', '⇐' => '\[lA]', '⇒' => '\[rA]', '⇔' => '\[hA]', '⇓' => '\[dA]', '⇑' => '\[uA]', '⇕' => '\[vA]', '⎯' => '\[an]', # Lines # '|' => '\[ba]', '│' => '\[br]', # '_' => '\[ul]', '‾' => '\[rn]', '_' => '\[ru]', '¦' => '\[bb]', '/' => '\[sl]', '\\' => '\e', # Text markers '○' => '\[ci]', # '·' => '\[bu]', '‡' => '\[dd]', '†' => '\[dg]', '◊' => '\[lz]', '□' => '\[sq]', '¶' => '\[ps]', '§' => '\[sc]', '☜' => '\[lh]', '☞' => '\[rh]', '@' => '\[at]', '#' => '\[sh]', '↵' => '\[CR]', '✓' => '\[OK]', # Legal Symbols '©' => '\[co]', '®' => '\[rg]', '™' => '\[tm]', # Currency symbols '$' => '\[Do]', '¢' => '\[ct]', # '€' => '\[eu]', '€' => '\[Eu]', '¥' => '\[Ye]', '£' => '\[Po]', '¤' => '\[Cs]', 'ƒ' => '\[Fn]', # Units '°' => '\[de]', '‰' => '\[%0]', '′' => '\[fm]', '″' => '\[sd]', 'µ' => '\[mc]', 'ª' => '\[Of]', 'º' => '\[Om]', # Logical Symbols '∧' => '\[AN]', '∨' => '\[OR]', # '¬' => '\[no]', '¬' => '\[tno]', '∃' => '\[te]', '∀' => '\[fa]', '∋' => '\[st]', # '∴' => '\[3d]', '∴' => '\[tf]', '|' => '\[or]', # Mathematical Symbols '½' => '\[12]', '¼' => '\[14]', '¾' => '\[34]', '⅛' => '\[18]', '⅜' => '\[38]', '⅝' => '\[58]', '⅞' => '\[78]', '¹' => '\[S1]', '²' => '\[S2]', '³' => '\[S3]', '+' => '\[pl]', '-' => '\-', '−' => '\[mi]', '∓' => '\[-+]', # '±' => '\[+-]', '±' => '\[t+-]', '·' => '\[pc]', '⋅' => '\[md]', # '×' => '\[mu]', '×' => '\[tmu]', '⊗' => '\[c*]', '⊕' => '\[c+]', # '÷' => '\[di]', '÷' => '\[tdi]', '⁄' => '\[f/]', '∗' => '\[**]', '≤' => '\[<=]', '≥' => '\[>=]', '≪' => '\[<<]', '≫' => '\[>>]', '=' => '\[eq]', '≠' => '\[!=]', '≡' => '\[==]', '≢' => '\[ne]', '≅' => '\[=~]', '≃' => '\[|=]', '∼' => '\[ap]', # '≈' => '\[~~]', '≈' => '\[~=]', '∝' => '\[pt]', '∅' => '\[es]', '∈' => '\[mo]', '∉' => '\[nm]', '⊂' => '\[sb]', '⊄' => '\[nb]', '⊃' => '\[sp]', '⊅' => '\[nc]', '⊆' => '\[ib]', '⊇' => '\[ip]', '∩' => '\[ca]', '∪' => '\[cu]', '∠' => '\[/_]', '⊥' => '\[pp]', # '∫' => '\[is]', '∫' => '\[integral]', '∑' => '\[sum]', '∏' => '\[product]', '∐' => '\[coproduct]', '∇' => '\[gr]', # '√' => '\[sr]', '√' => '\[sqrt]', '⌈' => '\[lc]', '⌉' => '\[rc]', '⌊' => '\[lf]', '⌋' => '\[rf]', '∞' => '\[if]', 'ℵ' => '\[Ah]', 'ℑ' => '\[Im]', 'ℜ' => '\[Re]', '℘' => '\[wp]', '∂' => '\[pd]', # 'ℏ' => '\[-h]', 'ℏ' => '\[hbar]', # Greek glyphs 'Α' => '\[*A]', 'Β' => '\[*B]', 'Γ' => '\[*G]', 'Δ' => '\[*D]', 'Ε' => '\[*E]', 'Ζ' => '\[*Z]', 'Η' => '\[*Y]', 'Θ' => '\[*H]', 'Ι' => '\[*I]', 'Κ' => '\[*K]', 'Λ' => '\[*L]', 'Μ' => '\[*M]', 'Ν' => '\[*N]', 'Ξ' => '\[*C]', 'Ο' => '\[*O]', 'Π' => '\[*P]', 'Ρ' => '\[*R]', 'Σ' => '\[*S]', 'Τ' => '\[*T]', 'Υ' => '\[*U]', 'Φ' => '\[*F]', 'Χ' => '\[*X]', 'Ψ' => '\[*Q]', 'Ω' => '\[*W]', 'α' => '\[*a]', 'β' => '\[*b]', 'γ' => '\[*g]', 'δ' => '\[*d]', 'ε' => '\[*e]', 'ζ' => '\[*z]', 'η' => '\[*y]', 'θ' => '\[*h]', 'ι' => '\[*i]', 'κ' => '\[*k]', 'λ' => '\[*l]', 'μ' => '\[*m]', 'ν' => '\[*n]', 'ξ' => '\[*c]', 'ο' => '\[*o]', 'π' => '\[*p]', 'ρ' => '\[*r]', 'ς' => '\[ts]', 'σ' => '\[*s]', 'τ' => '\[*t]', 'υ' => '\[*u]', 'ϕ' => '\[*f]', 'χ' => '\[*x]', 'ψ' => '\[*q]', 'ω' => '\[*w]', 'ϑ' => '\[+h]', 'φ' => '\[+f]', 'ϖ' => '\[+p]', 'ϵ' => '\[+e]', # Card symbols '♣' => '\[CL]', '♠' => '\[SP]', '♥' => '\[HE]', '♡' => '\[u2661]', '♦' => '\[DI]', '♢' => '\[u2662]' }
- GLYPH_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Regular expression to convert unicode characters into glyphs
Regexp.union(GLYPHS.keys)
Instance Method Summary collapse
-
#convert(root) ⇒ String
private
Converts the markdown document into a man-page.
-
#convert_a(a) ⇒ String
private
Converts a
kd:a
element. -
#convert_abbreviation(abbr) ⇒ String
private
Converts a
kd:abbreviation
element. -
#convert_blank(blank) ⇒ nil
private
Converts a
kd:blank
element. -
#convert_blockquote(blockquote) ⇒ String
private
Converts a
kd:blockquote
element. -
#convert_children_of(element) ⇒ String
private
Converts the children of an element.
-
#convert_codeblock(codeblock) ⇒ String
private
Converts a
kd:codeblock
element. -
#convert_codespan(codespan) ⇒ String
private
Converts a
kd:codespan
element. -
#convert_comment(comment) ⇒ String
private
Converts a
kd:comment
element. -
#convert_dd(dd, index: 0) ⇒ String
private
Converts a
kd:dd
element within akd:dd
. -
#convert_dl(dl) ⇒ String
private
Converts a
kd:dl
element. -
#convert_dt(dt, index: 0) ⇒ String
private
Converts a
kd:dt
element within akd:dl
. -
#convert_element(element) ⇒ String
private
Converts an element.
-
#convert_em(em) ⇒ String
private
Converts a
kd:em
element. -
#convert_header(header) ⇒ String
private
Converts a
kd:header
element. -
#convert_hr(hr) ⇒ nil
private
Ignore
kd:hr
elements. -
#convert_ol(ol) ⇒ String
private
Converts a
kd:ol
element. -
#convert_ol_li(li) ⇒ String
private
Converts a
kd:li
element within akd:ol
list. -
#convert_p(p) ⇒ String
private
Converts a
kd:p
element. -
#convert_root(root) ⇒ String
private
Converts the root of a markdown document.
-
#convert_smart_quote(quote) ⇒ String
private
Converts a
kd:smart_quote
element. -
#convert_strong(strong) ⇒ String
private
Converts a
kd:strong
element. -
#convert_text(text) ⇒ String
private
Converts a
kd:text
element. -
#convert_text_elements(elements) ⇒ String
private
Converts the children of an element.
-
#convert_typographic_sym(sym) ⇒ String
private
Converts a
kd:typographic_sym
element. -
#convert_ul(ul) ⇒ String
private
Converts a
kd:ul
element. -
#convert_ul_li(li) ⇒ String
private
Converts a
kd:li
element within akd:ul
list. -
#escape(text) ⇒ String
private
Escapes text for roff.
-
#initialize(root, options) ⇒ Converter
constructor
private
Initializes the converter.
-
#man_page_link(page, section = nil) ⇒ String
private
Outputs a man page link.
Constructor Details
#initialize(root, options) ⇒ Converter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the converter.
418 419 420 421 422 |
# File 'lib/kramdown/man/converter.rb', line 418 def initialize(root,) super(root,) @ol_index = 0 end |
Instance Method Details
#convert(root) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the markdown document into a man-page.
433 434 435 |
# File 'lib/kramdown/man/converter.rb', line 433 def convert(root) "#{HEADER}#{convert_root(root)}" end |
#convert_a(a) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:a
element.
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 |
# File 'lib/kramdown/man/converter.rb', line 931 def convert_a(a) href = a.attr['href'] scheme, path = href.split(':',2) text = convert_text_elements(a.children) case scheme when 'mailto' email = escape(path) unless text == email <<~ROFF #{text.chomp} .MT #{email} .ME ROFF else <<~ROFF .MT #{email} .ME ROFF end when 'man' if (match = path.match(/\A(?<page>[A-Za-z0-9_-]+)(?:\((?<section>\d[a-z]?)\)|\.(?<section>\d[a-z]?))\z/)) man_page_link(match[:page],match[:section]) else page = escape(path) <<~ROFF .BR #{page} ROFF end else if (match = href.match(/(?<page>[A-Za-z0-9_-]+)\.(?<section>\d[a-z]?)\.md\z/)) man_page_link(match[:page],match[:section]) else <<~ROFF #{text.chomp} .UR #{escape(href)} .UE ROFF end end end |
#convert_abbreviation(abbr) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:abbreviation
element.
784 785 786 |
# File 'lib/kramdown/man/converter.rb', line 784 def convert_abbreviation(abbr) escape(abbr.value) end |
#convert_blank(blank) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:blank
element.
473 474 |
# File 'lib/kramdown/man/converter.rb', line 473 def convert_blank(blank) end |
#convert_blockquote(blockquote) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:blockquote
element.
797 798 799 800 801 802 803 804 805 |
# File 'lib/kramdown/man/converter.rb', line 797 def convert_blockquote(blockquote) contents = convert_children_of(blockquote) return <<~ROFF .RS #{contents.chomp} .RE ROFF end |
#convert_children_of(element) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the children of an element.
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 |
# File 'lib/kramdown/man/converter.rb', line 1009 def convert_children_of(element) roff = String.new(encoding: Encoding::UTF_8) element.children.each do |child| if (contents = convert_element(child)) roff << contents end end return roff end |
#convert_codeblock(codeblock) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:codeblock
element.
816 817 818 819 820 821 822 823 824 825 826 827 |
# File 'lib/kramdown/man/converter.rb', line 816 def convert_codeblock(codeblock) contents = escape(codeblock.value) return <<~ROFF .PP .RS 4 .EX #{contents.chomp} .EE .RE ROFF end |
#convert_codespan(codespan) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:codespan
element.
903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 |
# File 'lib/kramdown/man/converter.rb', line 903 def convert_codespan(codespan) # ``` code fence blocks are parsed as kd:codespans if codespan.[:codespan_delimiter] == '```' # ignore the first and last newlines contents = escape(codespan.value[1..-2]) <<~ROFF .PP .RS 4 .EX #{contents} .EE .RE ROFF else "\\fB#{escape(codespan.value)}\\fR" end end |
#convert_comment(comment) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:comment
element.
838 839 840 841 842 843 844 845 846 847 848 |
# File 'lib/kramdown/man/converter.rb', line 838 def convert_comment(comment) roff = String.new(encoding: Encoding::UTF_8) comment.value.lines.each do |line| roff << <<~ROFF .\\" #{line} ROFF end return roff end |
#convert_dd(dd, index: 0) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:dd
element within a kd:dd
.
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/kramdown/man/converter.rb', line 751 def convert_dd(dd, index: 0) roff = String.new(encoding: Encoding::UTF_8) dd.children.each_with_index do |child,child_index| if index == 0 && child_index == 0 && child.type == :p contents = convert_children_of(child) # omit the .PP macro for the first paragraph roff << "#{contents.chomp}\n" else if (contents = convert_element(child)) # indent all other following paragraphs or other elements roff << <<~ROFF .RS #{contents.chomp} .RE ROFF end end end return roff end |
#convert_dl(dl) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:dl
element.
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/kramdown/man/converter.rb', line 678 def convert_dl(dl) roff = String.new(encoding: Encoding::UTF_8) dt_index = 0 dd_index = 0 dl.children.each do |element| case element.type when :dt roff << convert_dt(element, index: dt_index) dt_index += 1 # increment the dt count dd_index = 0 # reset the dd count when :dd roff << convert_dd(element, index: dd_index) dd_index += 1 # increment the dd count dt_index = 0 # reset the dt count else roff << convert(element) # reset both the dt_index and dd_index counters dt_index = 0 dd_index = 0 end end return roff end |
#convert_dt(dt, index: 0) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:dt
element within a kd:dl
.
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
# File 'lib/kramdown/man/converter.rb', line 721 def convert_dt(dt, index: 0) text = convert_text_elements(dt.children) if index == 0 <<~ROFF .TP #{text} ROFF else <<~ROFF .TQ #{text} ROFF end end |
#convert_element(element) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts an element.
459 460 461 462 463 |
# File 'lib/kramdown/man/converter.rb', line 459 def convert_element(element) method = "convert_#{element.type}" send(method,element) if respond_to?(method) end |
#convert_em(em) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:em
element.
877 878 879 |
# File 'lib/kramdown/man/converter.rb', line 877 def convert_em(em) "\\fI#{convert_text_elements(em.children)}\\fP" end |
#convert_header(header) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:header
element.
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/kramdown/man/converter.rb', line 524 def convert_header(header) text = header.[:raw_text] case header.[:level] when 1 <<~ROFF .TH #{text} ROFF when 2 <<~ROFF .SH #{text} ROFF else <<~ROFF .SS #{text} ROFF end end |
#convert_hr(hr) ⇒ nil
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ignore kd:hr
elements.
551 552 |
# File 'lib/kramdown/man/converter.rb', line 551 def convert_hr(hr) end |
#convert_ol(ol) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:ol
element.
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/kramdown/man/converter.rb', line 619 def convert_ol(ol) @ol_index += 1 contents = String.new(encoding: Encoding::UTF_8) ol.children.each do |li| contents << convert_ol_li(li) end return <<~ROFF .nr step#{@ol_index} 0 1 .RS #{contents.chomp} .RE ROFF end |
#convert_ol_li(li) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:li
element within a kd:ol
list.
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'lib/kramdown/man/converter.rb', line 645 def convert_ol_li(li) roff = String.new(encoding: Encoding::UTF_8) li.children.each_with_index do |child,index| if child.type == :p contents = convert_children_of(child) roff << if index == 0 <<~ROFF .IP \\n+[step#{@ol_index}] #{contents.chomp} ROFF else <<~ROFF .IP \\n #{contents.chomp} ROFF end end end return roff end |
#convert_p(p) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:p
element.
859 860 861 862 863 864 865 866 |
# File 'lib/kramdown/man/converter.rb', line 859 def convert_p(p) contents = convert_text_elements(p.children) return <<~ROFF .PP #{contents.chomp} ROFF end |
#convert_root(root) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the root of a markdown document.
446 447 448 |
# File 'lib/kramdown/man/converter.rb', line 446 def convert_root(root) convert_children_of(root) end |
#convert_smart_quote(quote) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:smart_quote
element.
511 512 513 |
# File 'lib/kramdown/man/converter.rb', line 511 def convert_smart_quote(quote) SMART_QUOTES[quote.value] end |
#convert_strong(strong) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:strong
element.
890 891 892 |
# File 'lib/kramdown/man/converter.rb', line 890 def convert_strong(strong) "\\fB#{convert_text_elements(strong.children)}\\fP" end |
#convert_text(text) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:text
element.
485 486 487 |
# File 'lib/kramdown/man/converter.rb', line 485 def convert_text(text) escape(text.value) end |
#convert_text_elements(elements) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the children of an element.
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
# File 'lib/kramdown/man/converter.rb', line 1030 def convert_text_elements(elements) roff = String.new(encoding: Encoding::UTF_8) elements.each do |element| if (contents = convert_element(element)) if contents.start_with?('.') && !roff.empty? && !roff.end_with?("\n") # roff macross must exist on their own line roff << "\n#{contents}" elsif contents.start_with?(' ') && roff.end_with?("\n") # remove leadning whitespace following a newline roff << contents.lstrip else roff << contents end end end return roff end |
#convert_typographic_sym(sym) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:typographic_sym
element.
498 499 500 |
# File 'lib/kramdown/man/converter.rb', line 498 def convert_typographic_sym(sym) TYPOGRAPHIC_SYMS[sym.value] end |
#convert_ul(ul) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:ul
element.
563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/kramdown/man/converter.rb', line 563 def convert_ul(ul) contents = String.new(encoding: Encoding::UTF_8) ul.children.each do |li| contents << convert_ul_li(li) end return <<~ROFF .RS #{contents.chomp} .RE ROFF end |
#convert_ul_li(li) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a kd:li
element within a kd:ul
list.
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/kramdown/man/converter.rb', line 586 def convert_ul_li(li) roff = String.new(encoding: Encoding::UTF_8) li.children.each_with_index do |child,index| if child.type == :p contents = convert_children_of(child) roff << if index == 0 <<~ROFF .IP \\(bu 2 #{contents.chomp} ROFF else <<~ROFF .IP \\( 2 #{contents.chomp} ROFF end end end return roff end |
#escape(text) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Escapes text for roff.
1059 1060 1061 |
# File 'lib/kramdown/man/converter.rb', line 1059 def escape(text) text.gsub(GLYPH_REGEXP,GLYPHS) end |
#man_page_link(page, section = nil) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Outputs a man page link.
988 989 990 991 992 993 994 995 996 997 998 |
# File 'lib/kramdown/man/converter.rb', line 988 def man_page_link(page,section=nil) if section <<~ROFF .BR #{escape(page)} (#{escape(section)}) ROFF else <<~ROFF .BR #{escape(page)} ROFF end end |