Module: MaRuKu::Helpers

Included in:
In::Markdown::BlockLevelParser
Defined in:
lib/omf-web/widget/text/maruku/helpers.rb

Instance Method Summary collapse

Instance Method Details

#md_abbr(abbr, title) ⇒ Object



79
80
81
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 79

def md_abbr(abbr, title)
  md_el(:abbr, [abbr], {:title=>title})
end

#md_abbr_def(abbr, text, al = nil) ⇒ Object



75
76
77
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 75

def md_abbr_def(abbr, text, al=nil)
  md_el(:abbr_def, [], {:abbr=>abbr, :text=>text}, al)
end

#md_ald(id, al) ⇒ Object

Attribute list definition



183
184
185
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 183

def md_ald(id, al)
  md_el(:ald, [], {:ald_id=>id,:ald=>al})
end

#md_brObject



125
126
127
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 125

def md_br()
  md_el(:linebreak, [], {}, nil)
end

#md_code(code, al = nil) ⇒ Object

Inline code



54
55
56
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 54

def md_code(code, al=nil)
  md_el(:inline_code, [], {:raw_code => code}, al)
end

#md_codeblock(source, al = nil) ⇒ Object

Code block



59
60
61
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 59

def md_codeblock(source, al=nil)
  md_el(:code, [], {:raw_code => source}, al)
end

#md_el(node_type, children = [], meta = {}, al = nil) ⇒ Object

if the first is a md_ial, it is used as such



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 34

def md_el(node_type, children=[], meta={}, al=nil)
  if  (e=children.first).kind_of?(MDElement) and
    e.node_type == :ial then
    if al
      al += e.ial
    else
      al = e.ial
    end
    children.shift
  end
  e = MDElement.new(node_type, children, meta, al)
  e.doc = @doc
  return e
end

#md_em(children, al = nil) ⇒ Object



121
122
123
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 121

def md_em(children, al=nil)
  md_el(:emphasis, [children].flatten, {}, al)
end

#md_email(email, al = nil) ⇒ Object



149
150
151
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 149

def md_email(email, al=nil)
  md_el(:email_address, [], {:email=>email}, al)
end

#md_emstrong(children, al = nil) ⇒ Object



137
138
139
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 137

def md_emstrong(children, al=nil)
  md_strong(md_em(children), al)
end

#md_entity(entity_name, al = nil) ⇒ Object



153
154
155
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 153

def md_entity(entity_name, al=nil)
  md_el(:entity, [], {:entity_name=>entity_name}, al)
end

#md_foot_ref(ref_id, al = nil) ⇒ Object

Markdown extra



158
159
160
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 158

def md_foot_ref(ref_id, al=nil)
  md_el(:footnote_reference, [], {:footnote_id=>ref_id}, al)
end

#md_footnote(footnote_id, children, al = nil) ⇒ Object



71
72
73
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 71

def md_footnote(footnote_id, children, al=nil)
  md_el(:footnote, children, {:footnote_id=>footnote_id}, al)
end

#md_header(level, children, al = nil, line_no = -1)) ⇒ Object



49
50
51
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 49

def md_header(level, children, al=nil, line_no = -1)
  md_el(:header, children, {:level => level, :line_no => line_no}, al)
end

#md_hruleObject



129
130
131
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 129

def md_hrule()
  md_el(:hrule, [], {}, nil)
end

#md_html(raw_html, al = nil) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 83

def md_html(raw_html, al=nil)
  e = md_el(:raw_html, [], {:raw_html=>raw_html})
  begin
    # remove newlines and whitespace at begin
    # end end of string, or else REXML gets confused
    raw_html = raw_html.gsub(/\A\s*</,'<').
                        gsub(/>[\s\n]*\Z/,'>')

    raw_html = "<marukuwrap>#{raw_html}</marukuwrap>"
    e.instance_variable_set :@parsed_html,
       REXML::Document.new(raw_html)
  rescue   	REXML::ParseException => ex
    e.instance_variable_set :@parsed_html, nil
    maruku_recover "REXML cannot parse this block of HTML/XML:\n"+
    add_tabs(raw_html,1,'|') + "\n"+ex.inspect
#			"  #{raw_html.inspect}\n\n"+ex.inspect
  end
  e
end

#md_ial(al) ⇒ Object

inline attribute list



176
177
178
179
180
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 176

def md_ial(al)
  al = Maruku::AttributeList.new(al) if
    not al.kind_of?Maruku::AttributeList
  md_el(:ial, [], {:ial=>al})
end

#md_im_image(children, url, title = nil, al = nil) ⇒ Object



117
118
119
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 117

def md_im_image(children, url, title=nil, al=nil)
  md_el(:im_image, children, {:url=>url,:title=>title},al)
end


108
109
110
111
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 108

def md_im_link(children, url, title=nil, al=nil)
  #puts "IM_LINK>>> '#{url}'"
  md_el(:im_link, children, {:url=>url,:title=>title}, al)
end

#md_image(children, ref_id, al = nil) ⇒ Object



113
114
115
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 113

def md_image(children, ref_id, al=nil)
  md_el(:image, children, {:ref_id=>ref_id}, al)
end

#md_li(children, want_my_par, al = nil) ⇒ Object



67
68
69
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 67

def md_li(children, want_my_par, al=nil)
  md_el(:li, children, {:want_my_paragraph=>want_my_par}, al)
end


103
104
105
106
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 103

def md_link(children, ref_id, al=nil)
  #puts "LINK>>> '#{ref_id}'"
  md_el(:link, children, {:ref_id=>ref_id.downcase}, al)
end

#md_par(children, al = nil, line_no = -1)) ⇒ Object



162
163
164
165
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 162

def md_par(children, al=nil, line_no = -1)
  #md_el(:paragraph, children, meta={}, al)
  md_el(:paragraph, children, {:line_no => line_no}, al)
end

#md_quote(children, al = nil) ⇒ Object



63
64
65
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 63

def md_quote(children, al=nil)
  md_el(:quote, children, {}, al)
end

#md_ref_def(ref_id, url, title = nil, meta = {}, al = nil) ⇒ Object

1]: url [properties


168
169
170
171
172
173
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 168

def md_ref_def(ref_id, url, title=nil, meta={}, al=nil)
  meta[:url] = url
  meta[:ref_id] = ref_id
  meta[:title] = title if title
  md_el(:ref_definition, [], meta, al)
end

#md_strong(children, al = nil) ⇒ Object



133
134
135
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 133

def md_strong(children, al=nil)
  md_el(:strong, [children].flatten, {}, al)
end

#md_url(url, al = nil) ⇒ Object



142
143
144
145
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 142

def md_url(url, al=nil)
  #puts "URL>>> '#{url}'"
  md_el(:immediate_link, [], {:url=>url}, al)
end

#md_xml_instr(target, code) ⇒ Object

Server directive <?target code… ?>



188
189
190
# File 'lib/omf-web/widget/text/maruku/helpers.rb', line 188

def md_xml_instr(target, code)
  md_el(:xml_instr, [], {:target=>target, :code=>code})
end