Module: Cheepub::Converter::CheeLatex
- Included in:
- Kramdown::Converter::Latex
- Defined in:
- lib/cheepub/converter/cheelatex.rb
Instance Method Summary collapse
- #convert_codeblock(el, opts) ⇒ Object
- #convert_html_element(el, opts) ⇒ Object
- #convert_img(el, opts) ⇒ Object
- #convert_p(el, opts) ⇒ Object
- #convert_standalone_image(el, opts, img) ⇒ Object
Instance Method Details
#convert_codeblock(el, opts) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cheepub/converter/cheelatex.rb', line 36 def convert_codeblock(el, opts) show_whitespace = el.attr['class'].to_s =~ /\bshow-whitespaces\b/ lang = extract_code_language(el.attr) if @options[:syntax_highlighter] == :minted && (highlighted_code = highlight_code(el.value, lang, :block)) @data[:packages] << 'minted' "#{latex_link_target(el)}#{highlighted_code}\n" elsif (show_whitespace || lang) && @options[:syntax_highlighter] = [] << "showspaces=%s,showtabs=%s" % (show_whitespace ? ['true', 'true'] : ['false', 'false']) << "language=#{lang}" if lang << "basicstyle=\\ttfamily\\footnotesize,columns=fixed,frame=tlbr" id = el.attr['id'] << "label=#{id}" if id attrs = attribute_list(el) "#{latex_link_target(el)}\\begin{lstlisting}[#{.join(',')}]\n#{el.value}\n\\end{lstlisting}#{attrs}\n" else "#{latex_link_target(el)}\\begin{verbatim}#{el.value}\\end{verbatim}\n" end end |
#convert_html_element(el, opts) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/cheepub/converter/cheelatex.rb', line 58 def convert_html_element(el, opts) case el.value when :ruby str = inner(el, opts) "\\ruby[g]{#{str}}" when :rt str = inner(el, opts) "}{#{str}" when :span "\\rensuji{#{inner(el, opts)}}" when "p" if el.children.size == 1 && el.children.first.value == "br" "\\rblatexEmptyLine\n" else super end else super end end |
#convert_img(el, opts) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/cheepub/converter/cheelatex.rb', line 21 def convert_img(el, opts) line = el.[:location] angle = @options[:page_direction] == "rtl" ? 90 : 0 if el.attr['src'] =~ /^(https?|ftps?):\/\// warning("Cannot include non-local image#{line ? " (line #{line})" : ''}") '' elsif !el.attr['src'].empty? @data[:packages] << 'graphicx' "#{latex_link_target(el)}\\includegraphics[angle=#{angle}]{#{el.attr['src']}}" else warning("Cannot include image with empty path#{line ? " (line #{line})" : ''}") '' end end |
#convert_p(el, opts) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/cheepub/converter/cheelatex.rb', line 7 def convert_p(el, opts) if el.children.size == 1 && el.children.first.type == :img && !(img = convert_img(el.children.first, opts)).empty? convert_standalone_image(el, opts, img) elsif el.attr['class'].to_s =~ /text\-right/ "#{latex_link_target(el)}\\begin{flushright}#{inner(el, opts)}\\end{flushright}\n\n" else "#{latex_link_target(el)}#{inner(el, opts)}\n\n" end end |
#convert_standalone_image(el, opts, img) ⇒ Object
17 18 19 |
# File 'lib/cheepub/converter/cheelatex.rb', line 17 def convert_standalone_image(el, opts, img) "#{img}\n" end |