Class: MicronMarkup::Renderer
- Inherits:
-
Object
- Object
- MicronMarkup::Renderer
- Defined in:
- lib/micron_markup.rb
Constant Summary collapse
- ANSI_COLORS =
{ '0' => :black, '1' => :red, '2' => :green, '3' => :yellow, '4' => :blue, '5' => :magenta, '6' => :cyan, '7' => :white, '8' => :light_black, '9' => :light_red, 'a' => :light_green, 'b' => :light_yellow, 'c' => :light_blue, 'd' => :light_magenta, 'e' => :light_cyan, 'f' => :light_white }
Instance Method Summary collapse
-
#initialize(source) ⇒ Renderer
constructor
A new instance of Renderer.
- #reset_state ⇒ Object
-
#to_html ⇒ Object
render micron as html.
-
#to_text ⇒ Object
render micron as terminal text.
Constructor Details
#initialize(source) ⇒ Renderer
Returns a new instance of Renderer.
19 20 21 22 23 |
# File 'lib/micron_markup.rb', line 19 def initialize(source) @source = source @lines = source.split("\n") reset_state end |
Instance Method Details
#reset_state ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/micron_markup.rb', line 25 def reset_state @state = { bold: false, italic: false, underline: false, foreground: nil, background: nil, alignment: :left, section_level: 0, in_literal: false, literal_content: [] } end |
#to_html ⇒ Object
render micron as html
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/micron_markup.rb', line 40 def to_html reset_state output = ['<div class="micron-content">'] @lines.each do |line| output << process_line_html(line) end output << '</div>' output.join("\n") end |
#to_text ⇒ Object
render micron as terminal text
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/micron_markup.rb', line 53 def to_text reset_state output = [] @lines.each do |line| output << process_line_text(line) end output.join("\n") end |