module RedCloth::Formatters::HTML
def acronym(opts)
def acronym(opts) opts[:block] = true "<acronym#{pba(opts)}>#{caps(:text => opts[:text])}</acronym>" end
def after_transform(text)
def after_transform(text) text.chomp! end
def amp(opts)
def amp(opts) "&" end
def apos(opts)
def apos(opts) "'" end
def arrow(opts)
def arrow(opts) "→" end
def bc_close(opts)
def bc_close(opts) "</pre>\n" end
def bc_open(opts)
def bc_open(opts) opts[:block] = true "<pre#{pba(opts)}>" end
def before_transform(text)
def before_transform(text) clean_html(text) if sanitize_html end
def bq_close(opts)
def bq_close(opts) "</blockquote>\n" end
def bq_open(opts)
def bq_open(opts) opts[:block] = true cite = opts[:cite] ? " cite=\"#{ escape_attribute opts[:cite] }\"" : '' "<blockquote#{cite}#{pba(opts)}>\n" end
def br(opts)
def br(opts) if hard_breaks == false "\n" else "<br#{pba(opts)} />\n" end end
def caps(opts)
def caps(opts) if no_span_caps opts[:text] else opts[:class] = 'caps' span(opts) end end
def clean_html( text, allowed_tags = BASIC_TAGS )
def clean_html( text, allowed_tags = BASIC_TAGS ) text.gsub!( /<!\[CDATA\[/, '' ) text.gsub!( /<(\/*)([A-Za-z]\w*+)([^>]*?)(\s?\/?)>/ ) do |m| raw = $~ tag = raw[2].downcase if allowed_tags.has_key? tag pcs = [tag] allowed_tags[tag].each do |prop| ['"', "'", ''].each do |q| q2 = ( q != '' ? q : '\s' ) if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i attrv = $1 next if (prop == 'src' or prop == 'href') and not attrv =~ %r{^(http|https|ftp):} pcs << "#{prop}=\"#{attrv.gsub('"', '\\"')}\"" break end end end if allowed_tags[tag] "<#{raw[1]}#{pcs.join " "}#{raw[4]}>" else # Unauthorized tag if block_given? yield m else '' end end end end
def copyright(opts)
def copyright(opts) "©" end
def del(opts)
def del(opts) opts[:block] = true "<del#{pba(opts)}>#{opts[:text]}</del>" end
def dim(opts)
def dim(opts) opts[:text].gsub!('x', '×') opts[:text].gsub!("'", '′') opts[:text].gsub!('"', '″') opts[:text] end
def dl_close(opts=nil)
def dl_close(opts=nil) "</dl>\n" end
def dl_open(opts)
def dl_open(opts) opts[:block] = true "<dl#{pba(opts)}>\n" end
def ellipsis(opts)
def ellipsis(opts) "#{opts[:text]}…" end
def emdash(opts)
def emdash(opts) "—" end
def endash(opts)
def endash(opts) " – " end
def entity(opts)
def entity(opts) "&#{opts[:text]};" end
def escape(text)
def escape(text) html_esc(text) end
def escape_attribute(text)
def escape_attribute(text) html_esc(text, :html_escape_attributes) end
def escape_pre(text)
def escape_pre(text) html_esc(text, :html_escape_preformatted) end
def fn(opts)
def fn(opts) no = opts[:id] opts[:id] = "fn#{no}" opts[:class] = ["footnote", opts[:class]].compact.join(" ") "<p#{pba(opts)}><a href=\"#fnr#{no}\"><sup>#{no}</sup></a> #{opts[:text]}</p>\n" end
def footno(opts)
def footno(opts) opts[:id] ||= opts[:text] %Q{<sup class="footnote" id=\"fnr#{opts[:id]}\"><a href=\"#fn#{opts[:id]}\">#{opts[:text]}</a></sup>} end
def gt(opts)
def gt(opts) ">" end
def hr(opts)
def hr(opts) "<hr#{pba(opts)} />\n" end
def html(opts)
def html(opts) "#{opts[:text]}\n" end
def html_block(opts)
def html_block(opts) inline_html(:text => "#{opts[:indent_before_start]}#{opts[:start_tag]}#{opts[:indent_after_start]}") + "#{opts[:text]}" + inline_html(:text => "#{opts[:indent_before_end]}#{opts[:end_tag]}#{opts[:indent_after_end]}") end
def ignored_line(opts)
def ignored_line(opts) opts[:text] + "\n" end
def image(opts)
def image(opts) if (filter_html || sanitize_html) && ( opts[:src] =~ /^\s*javascript:/i || opts[:href] =~ /^\s*javascript:/i ) opts[:title] else opts.delete(:align) opts[:alt] = opts[:title] img = "<img src=\"#{escape_attribute opts[:src]}\"#{pba(opts)} alt=\"#{escape_attribute opts[:alt].to_s}\" />" img = "<a href=\"#{escape_attribute opts[:href]}\">#{img}</a>" if opts[:href] img end end
def inline_html(opts)
def inline_html(opts) if filter_html html_esc(opts[:text], :html_escape_preformatted) else "#{opts[:text]}" # nil-safe end end
def li_close(opts=nil)
def li_close(opts=nil) "</li>\n" end
def li_open(opts)
def li_open(opts) "#{"\t" * opts[:nest]}<li#{pba(opts)}>#{opts[:text]}" end
def link(opts)
def link(opts) if (filter_html || sanitize_html) && opts[:href] =~ /^\s*javascript:/i opts[:name] else "<a href=\"#{escape_attribute opts[:href]}\"#{pba(opts)}>#{opts[:name]}</a>" end end
def lt(opts)
def lt(opts) "<" end
def multi_paragraph_quote(opts)
def multi_paragraph_quote(opts) "“#{opts[:text]}" end
def notextile(opts)
def notextile(opts) if filter_html html_esc(opts[:text], :html_escape_preformatted) else opts[:text] end end
def quot(opts)
def quot(opts) """ end
def quote1(opts)
def quote1(opts) "‘#{opts[:text]}’" end
def quote2(opts)
def quote2(opts) "“#{opts[:text]}”" end
def registered(opts)
def registered(opts) "®" end
def snip(opts)
def snip(opts) "<pre#{pba(opts)}><code>#{opts[:text]}</code></pre>\n" end
def squot(opts)
def squot(opts) "’" end
def table_close(opts)
def table_close(opts) "</table>\n" end
def table_open(opts)
def table_open(opts) "<table#{pba(opts)}>\n" end
def td(opts)
def td(opts) tdtype = opts[:th] ? 'th' : 'td' "\t\t<#{tdtype}#{pba(opts)}>#{opts[:text]}</#{tdtype}>\n" end
def tr_close(opts)
def tr_close(opts) "\t</tr>\n" end
def tr_open(opts)
def tr_open(opts) "\t<tr#{pba(opts)}>\n" end
def trademark(opts)
def trademark(opts) "™" end