module RedCloth::Formatters::HTML
Constants
- BASIC_TAGS
HTML cleansing stuff
Public Instance Methods
acronym(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 21 def acronym(opts) opts[:block] = true "<acronym#{pba(opts)}>#{caps(:text => opts[:text])}</acronym>" end
amp(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 192 def amp(opts) "&" end
apos(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 220 def apos(opts) "'" end
arrow(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 165 def arrow(opts) "→" end
bc_close(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 99 def bc_close(opts) "</pre>\n" end
bc_open(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 94 def bc_open(opts) opts[:block] = true "<pre#{pba(opts)}>" end
bq_close(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 109 def bq_close(opts) "</blockquote>\n" end
bq_open(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 103 def bq_open(opts) opts[:block] = true cite = opts[:cite] ? " cite=\"#{ escape_attribute opts[:cite] }\"" : '' "<blockquote#{cite}#{pba(opts)}>\n" end
br(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 204 def br(opts) if hard_breaks == false "\n" else "<br#{pba(opts)} />\n" end end
caps(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 26 def caps(opts) if no_span_caps opts[:text] else opts[:class] = 'caps' span(opts) end end
copyright(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 184 def copyright(opts) "©" end
del(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 35 def del(opts) opts[:block] = true "<del#{pba(opts)}>#{opts[:text]}</del>" end
dim(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 169 def dim(opts) opts[:text].gsub!('x', '×') opts[:text].gsub!("'", '′') opts[:text].gsub!('"', '″') opts[:text] end
dl_close(opts=nil)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 63 def dl_close(opts=nil) "</dl>\n" end
dl_open(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 58 def dl_open(opts) opts[:block] = true "<dl#{pba(opts)}>\n" end
ellipsis(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 153 def ellipsis(opts) "#{opts[:text]}…" end
emdash(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 157 def emdash(opts) "—" end
endash(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 161 def endash(opts) " – " end
entity(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 188 def entity(opts) "&#{opts[:text]};" end
fn(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 130 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
footno(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 125 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
gt(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 196 def gt(opts) ">" end
hr(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 17 def hr(opts) "<hr#{pba(opts)} />\n" end
html(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 224 def html(opts) "#{opts[:text]}\n" end
html_block(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 228 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
ignored_line(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 250 def ignored_line(opts) opts[:text] + "\n" end
image(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 117 def image(opts) 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
inline_html(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 242 def inline_html(opts) if filter_html html_esc(opts[:text], :html_escape_preformatted) else "#{opts[:text]}" # nil-safe end end
li_close(opts=nil)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 54 def li_close(opts=nil) "</li>\n" end
li_open(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 50 def li_open(opts) "#{"\t" * opts[:nest]}<li#{pba(opts)}>#{opts[:text]}" end
link(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 113 def link(opts) "<a href=\"#{escape_attribute opts[:href]}\"#{pba(opts)}>#{opts[:name]}</a>" end
lt(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 200 def lt(opts) "<" end
multi_paragraph_quote(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 149 def multi_paragraph_quote(opts) "“#{opts[:text]}" end
notextile(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 234 def notextile(opts) if filter_html html_esc(opts[:text], :html_escape_preformatted) else opts[:text] end end
quot(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 212 def quot(opts) """ end
quote1(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 141 def quote1(opts) "‘#{opts[:text]}’" end
quote2(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 145 def quote2(opts) "“#{opts[:text]}”" end
registered(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 180 def registered(opts) "®" end
snip(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 137 def snip(opts) "<pre#{pba(opts)}><code>#{opts[:text]}</code></pre>\n" end
squot(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 216 def squot(opts) "’" end
table_close(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 90 def table_close(opts) "</table>\n" end
table_open(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 86 def table_open(opts) "<table#{pba(opts)}>\n" end
td(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 73 def td(opts) tdtype = opts[:th] ? 'th' : 'td' "\t\t<#{tdtype}#{pba(opts)}>#{opts[:text]}</#{tdtype}>\n" end
tr_close(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 82 def tr_close(opts) "\t</tr>\n" end
tr_open(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 78 def tr_open(opts) "\t<tr#{pba(opts)}>\n" end
trademark(opts)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 176 def trademark(opts) "™" end
Private Instance Methods
after_transform(text)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 271 def after_transform(text) text.chomp! end
before_transform(text)
click to toggle source
# File lib/redcloth/formatters/html.rb, line 276 def before_transform(text) clean_html(text) if sanitize_html end
clean_html( text, allowed_tags = BASIC_TAGS ) { |m| ... }
click to toggle source
Clean unauthorized tags.
# File lib/redcloth/formatters/html.rb, line 317 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
escape(text)
click to toggle source
escapement for regular HTML (not in PRE tag)
# File lib/redcloth/formatters/html.rb, line 257 def escape(text) html_esc(text) end
escape_attribute(text)
click to toggle source
escaping for HTML attributes
# File lib/redcloth/formatters/html.rb, line 267 def escape_attribute(text) html_esc(text, :html_escape_attributes) end
escape_pre(text)
click to toggle source
escapement for HTML in a PRE tag
# File lib/redcloth/formatters/html.rb, line 262 def escape_pre(text) html_esc(text, :html_escape_preformatted) end