Module: MCMarkdown::Formatter::Lists

Included in:
Base
Defined in:
lib/mc_markdown/formatters/lists.rb

Instance Method Summary collapse

Instance Method Details

#list(content, list_type) ⇒ Object



5
6
7
8
9
10
# File 'lib/mc_markdown/formatters/lists.rb', line 5

def list content, list_type
  tag = ( list_type == :ordered ) ? "ol" : "ul"
  tag = (/\<dt\>/.match(content) ) ? "dl" : tag

  "<#{tag} class='list markers'>#{content}</#{tag}>"
end

#list_item(text, list_type) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mc_markdown/formatters/lists.rb', line 12

def list_item text, list_type
  if /\n\:\s*\n/.match(text)
    match_data = /^((.*)\n\:\s*\n)/.match(text)
    title = "<p>" << match_data[2].gsub('<p>','') << "</p>"

    # strip the title from the text, but leave <p> tags
    text = text.gsub( match_data[1].gsub(/\<\/?p\>/,''), '')

    # strip opening and closing p tags
    text = text.strip.gsub( /(\A\<p\>|\<\/p\>\z)/, '' )

    text = "<p>" << text << "</p>"

    "<dt>#{title}</dt><dd>#{text}</dd>"
  else
    "<li>#{text.strip}</li>"
  end
end