Class: Gmi2LaTeX::Renderer
- Inherits:
-
Object
- Object
- Gmi2LaTeX::Renderer
- Defined in:
- lib/gmi2latex/renderer.rb
Instance Method Summary collapse
- #end_itemize ⇒ Object
-
#initialize(document, header: nil, footer: nil) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
- #render_node(node) ⇒ Object
Constructor Details
#initialize(document, header: nil, footer: nil) ⇒ Renderer
Returns a new instance of Renderer.
5 6 7 8 9 |
# File 'lib/gmi2latex/renderer.rb', line 5 def initialize(document, header: nil, footer: nil) @document = document @header = header @footer = end |
Instance Method Details
#end_itemize ⇒ Object
76 77 78 79 80 |
# File 'lib/gmi2latex/renderer.rb', line 76 def end_itemize @listing or return @listing = false print "\\end{itemize}\n" end |
#render ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/gmi2latex/renderer.rb', line 13 def render @header and print @header @document.nodes.each do |node| render_node(node) end end_itemize @footer and print @footer end |
#render_node(node) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/gmi2latex/renderer.rb', line 22 def render_node(node) case node in Gemtext::Heading[content:] end_itemize print "\\section{#{content}}\n" in Gemtext::SubHeading[content:] end_itemize print "\\subsection{#{content}}\n" in Gemtext::SubSubHeading[content:] end_itemize print "\\subsubsection{#{content}}\n" in Gemtext::Whitespace end_itemize print "\n" in Gemtext::Text[content:] end_itemize content.each_char do |char| case char in "_" print "\\_" else print char end end print "\n" in Gemtext::Link[target:, description:] end_itemize print "#{description} (\\url{#{target}})\n" in Gemtext::Preformatted[content:] end_itemize print <<~LaTeX \\begin{verbatim} #{content} \\end{verbatim} LaTeX in Gemtext::ListItem[content:] if @listing print <<~LaTeX \\item{} #{content} LaTeX else print <<~LaTeX \\begin{itemize} \\item{} #{content} LaTeX @listing = true end else raise node.inspect end end |