Class: Kramdown::Converter::Html

Inherits:
Base
  • Object
show all
Defined in:
lib/nesta-contentfocus-extensions/kramdown.rb

Instance Method Summary collapse

Instance Method Details

#convert_blockquote(el, indent) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 59

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



79
80
81
82
83
84
85
86
87
88
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 79

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], '&nbsp;', split_content.pop].join
    content = split_content.join(' ')
  end
  [open, content, close].join
end

#convert_ul(el, indent) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 38

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_blockquoteObject



35
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 35

alias_method :pre_headstartup_convert_blockquote, :convert_blockquote

#pre_headstartup_convert_headerObject



36
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 36

alias_method :pre_headstartup_convert_header, :convert_header

#pre_headstartup_convert_ulObject



34
# File 'lib/nesta-contentfocus-extensions/kramdown.rb', line 34

alias_method :pre_headstartup_convert_ul, :convert_ul