Class: Kramdown::Converter::Html
- Inherits:
-
Base
- Object
- Base
- Kramdown::Converter::Html
- Defined in:
- lib/nesta-contentfocus-extensions/kramdown.rb
Instance Method Summary collapse
- #convert_blockquote(el, indent) ⇒ Object
- #convert_header(el, indent) ⇒ Object
- #convert_ul(el, indent) ⇒ Object
- #pre_headstartup_convert_blockquote ⇒ Object
- #pre_headstartup_convert_header ⇒ Object
- #pre_headstartup_convert_ul ⇒ Object
Instance Method Details
#convert_blockquote(el, indent) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 58 def convert_blockquote(el, indent) if el.attr['class'] == 'testimonial' p = el.children.detect{ |c| c.type == :p } if p mdash_idx = p.children.index{ |c| c.type == :typographic_sym && c.value == :mdash } if mdash_idx next_el = p.children[mdash_idx + 1] if (next_el.type == :text) && (next_el.value.strip.empty?) && (p.children[mdash_idx + 2].type == :a) p.children.delete_at(mdash_idx) cite = Element.new(:html_element, 'cite') cite.children = p.children.pop(p.children.size - mdash_idx) p.children.push cite elsif next_el.type == :a end end end end output = pre_headstartup_convert_blockquote(el, indent) end |
#convert_header(el, indent) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 78 def convert_header(el, indent) output = pre_headstartup_convert_header(el, indent) matched, open, content, close = *output.match(%r{(.*<h[1-6][^>]*>)(.*)(</h[1-6]>)}) split_content = content.split(' ') if split_content.size > 3 split_content[-1] = [split_content[-2], ' ', split_content.pop].join content = split_content.join(' ') end [open, content, close].join end |
#convert_ul(el, indent) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 37 def convert_ul(el, indent) if ['benefits', 'how', 'features'].include? el.attr['class'] el.children.each do |li| p = li.children.detect{ |c| c.type == :p } if p img = p.children.detect{ |c| c.type == :img} if img description = Element.new(:html_element, 'div', :class => 'description') example = Element.new(:html_element, 'div', :class => 'example') p.children.delete(img) example.children = [img] description.children = li.children li.children = [example, description] end end end end output = pre_headstartup_convert_ul(el, indent) output end |
#pre_headstartup_convert_blockquote ⇒ Object
34 |
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 34 alias_method :pre_headstartup_convert_blockquote, :convert_blockquote |
#pre_headstartup_convert_header ⇒ Object
35 |
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 35 alias_method :pre_headstartup_convert_header, :convert_header |
#pre_headstartup_convert_ul ⇒ Object
33 |
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 33 alias_method :pre_headstartup_convert_ul, :convert_ul |