Class: Marker::Heading
- Inherits:
-
ParseNode
- Object
- Treetop::Runtime::SyntaxNode
- ParseNode
- Marker::Heading
- Defined in:
- lib/marker/headings.rb
Instance Method Summary collapse
-
#l ⇒ Object
– defaults ++.
- #label(format, options = {}) ⇒ Object
-
#to_html(options = {}) ⇒ Object
HTML-rendered headings, using <h#> tags.
-
#to_s(options = {}) ⇒ Object
Text-rendered headings.
Methods inherited from Treetop::Runtime::SyntaxNode
Instance Method Details
#l ⇒ Object
– defaults ++
75 76 77 |
# File 'lib/marker/headings.rb', line 75 def l #:nodoc: nil end |
#label(format, options = {}) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/marker/headings.rb', line 65 def label( format, = {} ) case format when :html l.to_html( ) else l.to_s( ) end end |
#to_html(options = {}) ⇒ Object
HTML-rendered headings, using <h#> tags.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/marker/headings.rb', line 12 def to_html( = {} ) # find out how deep it is d = [s.text_value.size, e.text_value.size].min sn = s.text_value.size - d en = e.text_value.size - d if sn > 0 "<h#{d}>#{'=' * sn} #{label( :html, )}</h#{d}>" elsif en > 0 "<h#{d}>#{label( :html, )} #{'=' * en}</h#{d}>" else "<h#{d}>#{label( :html, )}</h#{d}>" end end |
#to_s(options = {}) ⇒ Object
Text-rendered headings. Should look like this:
Heading Level 1
Heading Level 2
-
Heading Level 3 ——————————————————–
— Heading Level 4 ——————————————————
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 |
# File 'lib/marker/headings.rb', line 38 def to_s( = {} ) width = [:width] || 80 d = [s.text_value.size, e.text_value.size].min sn = s.text_value.size - d en = e.text_value.size - d l = if sn > 0 "#{'=' * sn} #{label( :text, )}" elsif en > 0 "#{label( :text, )} #{'=' * en}" else label( :text, ) end case d when 1 "#{l}\n" + ('=' * width) when 2 "#{l}\n" + ('-' * width) else l = " #{l} " h = '-'*width h[2*(d-3)+1, l.size] = l # slice substitution h end end |