module RedCloth::Formatters::HTML
Constants
- BASIC_TAGS
-
HTML
cleansing stuff
Public Instance Methods
Source
# File lib/redcloth/formatters/html.rb 21 def acronym(opts) 22 opts[:block] = true 23 "<acronym#{pba(opts)}>#{caps(:text => opts[:text])}</acronym>" 24 end
Source
# File lib/redcloth/formatters/html.rb 173 def arrow(opts) 174 "→" 175 end
Source
# File lib/redcloth/formatters/html.rb 99 def bc_close(opts) 100 "</pre>\n" 101 end
Source
# File lib/redcloth/formatters/html.rb 94 def bc_open(opts) 95 opts[:block] = true 96 "<pre#{pba(opts)}>" 97 end
Source
# File lib/redcloth/formatters/html.rb 109 def bq_close(opts) 110 "</blockquote>\n" 111 end
Source
# File lib/redcloth/formatters/html.rb 103 def bq_open(opts) 104 opts[:block] = true 105 cite = opts[:cite] ? " cite=\"#{ escape_attribute opts[:cite] }\"" : '' 106 "<blockquote#{cite}#{pba(opts)}>\n" 107 end
Source
# File lib/redcloth/formatters/html.rb 212 def br(opts) 213 if hard_breaks == false 214 "\n" 215 else 216 "<br#{pba(opts)} />\n" 217 end 218 end
Source
# File lib/redcloth/formatters/html.rb 26 def caps(opts) 27 if no_span_caps 28 opts[:text] 29 else 30 opts[:class] = 'caps' 31 span(opts) 32 end 33 end
Source
# File lib/redcloth/formatters/html.rb 192 def copyright(opts) 193 "©" 194 end
Source
# File lib/redcloth/formatters/html.rb 35 def del(opts) 36 opts[:block] = true 37 "<del#{pba(opts)}>#{opts[:text]}</del>" 38 end
Source
# File lib/redcloth/formatters/html.rb 177 def dim(opts) 178 opts[:text].gsub!('x', '×') 179 opts[:text].gsub!("'", '′') 180 opts[:text].gsub!('"', '″') 181 opts[:text] 182 end
Source
# File lib/redcloth/formatters/html.rb 63 def dl_close(opts=nil) 64 "</dl>\n" 65 end
Source
# File lib/redcloth/formatters/html.rb 58 def dl_open(opts) 59 opts[:block] = true 60 "<dl#{pba(opts)}>\n" 61 end
Source
# File lib/redcloth/formatters/html.rb 161 def ellipsis(opts) 162 "#{opts[:text]}…" 163 end
Source
# File lib/redcloth/formatters/html.rb 165 def emdash(opts) 166 "—" 167 end
Source
# File lib/redcloth/formatters/html.rb 169 def endash(opts) 170 " – " 171 end
Source
# File lib/redcloth/formatters/html.rb 196 def entity(opts) 197 "&#{opts[:text]};" 198 end
Source
# File lib/redcloth/formatters/html.rb 138 def fn(opts) 139 no = opts[:id] 140 opts[:id] = "fn#{no}" 141 opts[:class] = ["footnote", opts[:class]].compact.join(" ") 142 "<p#{pba(opts)}><a href=\"#fnr#{no}\"><sup>#{no}</sup></a> #{opts[:text]}</p>\n" 143 end
Source
# File lib/redcloth/formatters/html.rb 133 def footno(opts) 134 opts[:id] ||= opts[:text] 135 %Q{<sup class="footnote" id=\"fnr#{opts[:id]}\"><a href=\"#fn#{opts[:id]}\">#{opts[:text]}</a></sup>} 136 end
Source
# File lib/redcloth/formatters/html.rb 17 def hr(opts) 18 "<hr#{pba(opts)} />\n" 19 end
Source
# File lib/redcloth/formatters/html.rb 232 def html(opts) 233 "#{opts[:text]}\n" 234 end
Source
# File lib/redcloth/formatters/html.rb 236 def html_block(opts) 237 inline_html(:text => "#{opts[:indent_before_start]}#{opts[:start_tag]}#{opts[:indent_after_start]}") + 238 "#{opts[:text]}" + 239 inline_html(:text => "#{opts[:indent_before_end]}#{opts[:end_tag]}#{opts[:indent_after_end]}") 240 end
Source
# File lib/redcloth/formatters/html.rb 258 def ignored_line(opts) 259 opts[:text] + "\n" 260 end
Source
# File lib/redcloth/formatters/html.rb 121 def image(opts) 122 if (filter_html || sanitize_html) && ( opts[:src] =~ /^\s*javascript:/i || opts[:href] =~ /^\s*javascript:/i ) 123 opts[:title] 124 else 125 opts.delete(:align) 126 opts[:alt] = opts[:title] 127 img = "<img src=\"#{escape_attribute opts[:src]}\"#{pba(opts)} alt=\"#{escape_attribute opts[:alt].to_s}\" />" 128 img = "<a href=\"#{escape_attribute opts[:href]}\">#{img}</a>" if opts[:href] 129 img 130 end 131 end
Source
# File lib/redcloth/formatters/html.rb 250 def inline_html(opts) 251 if filter_html 252 html_esc(opts[:text], :html_escape_preformatted) 253 else 254 "#{opts[:text]}" # nil-safe 255 end 256 end
Source
# File lib/redcloth/formatters/html.rb 54 def li_close(opts=nil) 55 "</li>\n" 56 end
Source
# File lib/redcloth/formatters/html.rb 50 def li_open(opts) 51 "#{"\t" * opts[:nest]}<li#{pba(opts)}>#{opts[:text]}" 52 end
Source
# File lib/redcloth/formatters/html.rb 113 def link(opts) 114 if (filter_html || sanitize_html) && opts[:href] =~ /^\s*javascript:/i 115 opts[:name] 116 else 117 "<a href=\"#{escape_attribute opts[:href]}\"#{pba(opts)}>#{opts[:name]}</a>" 118 end 119 end
Source
# File lib/redcloth/formatters/html.rb 157 def multi_paragraph_quote(opts) 158 "“#{opts[:text]}" 159 end
Source
# File lib/redcloth/formatters/html.rb 242 def notextile(opts) 243 if filter_html 244 html_esc(opts[:text], :html_escape_preformatted) 245 else 246 opts[:text] 247 end 248 end
Source
# File lib/redcloth/formatters/html.rb 149 def quote1(opts) 150 "‘#{opts[:text]}’" 151 end
Source
# File lib/redcloth/formatters/html.rb 153 def quote2(opts) 154 "“#{opts[:text]}”" 155 end
Source
# File lib/redcloth/formatters/html.rb 188 def registered(opts) 189 "®" 190 end
Source
# File lib/redcloth/formatters/html.rb 145 def snip(opts) 146 "<pre#{pba(opts)}><code>#{opts[:text]}</code></pre>\n" 147 end
Source
# File lib/redcloth/formatters/html.rb 224 def squot(opts) 225 "’" 226 end
Source
# File lib/redcloth/formatters/html.rb 90 def table_close(opts) 91 "</table>\n" 92 end
Source
# File lib/redcloth/formatters/html.rb 86 def table_open(opts) 87 "<table#{pba(opts)}>\n" 88 end
Source
# File lib/redcloth/formatters/html.rb 73 def td(opts) 74 tdtype = opts[:th] ? 'th' : 'td' 75 "\t\t<#{tdtype}#{pba(opts)}>#{opts[:text]}</#{tdtype}>\n" 76 end
Source
# File lib/redcloth/formatters/html.rb 82 def tr_close(opts) 83 "\t</tr>\n" 84 end
Source
# File lib/redcloth/formatters/html.rb 78 def tr_open(opts) 79 "\t<tr#{pba(opts)}>\n" 80 end
Source
# File lib/redcloth/formatters/html.rb 184 def trademark(opts) 185 "™" 186 end
Private Instance Methods
Source
# File lib/redcloth/formatters/html.rb 279 def after_transform(text) 280 text.chomp! 281 end
Source
# File lib/redcloth/formatters/html.rb 284 def before_transform(text) 285 clean_html(text) if sanitize_html 286 end
Source
# File lib/redcloth/formatters/html.rb 325 def clean_html( text, allowed_tags = BASIC_TAGS ) 326 text.gsub!( /<!\[CDATA\[/, '' ) 327 text.gsub!( /<(\/*)([A-Za-z]\w*)([^>]*?)(\s?\/?)>/ ) do |m| 328 raw = $~ 329 tag = raw[2].downcase 330 if allowed_tags.has_key? tag 331 pcs = [tag] 332 allowed_tags[tag].each do |prop| 333 ['"', "'", ''].each do |q| 334 q2 = ( q != '' ? q : '\s' ) 335 if raw[3] =~ /#{prop}\s*=\s*#{q}([^#{q2}]+)#{q}/i 336 attrv = $1 337 next if (prop == 'src' or prop == 'href') and not attrv =~ %r{^(http|https|ftp):} 338 pcs << "#{prop}=\"#{attrv.gsub('"', '\\"')}\"" 339 break 340 end 341 end 342 end if allowed_tags[tag] 343 "<#{raw[1]}#{pcs.join " "}#{raw[4]}>" 344 else # Unauthorized tag 345 if block_given? 346 yield m 347 else 348 '' 349 end 350 end 351 end 352 end
Clean unauthorized tags.
Source
# File lib/redcloth/formatters/html.rb 265 def escape(text) 266 html_esc(text) 267 end
escapement for regular HTML
(not in PRE tag)
Source
# File lib/redcloth/formatters/html.rb 275 def escape_attribute(text) 276 html_esc(text, :html_escape_attributes) 277 end
escaping for HTML
attributes
Source
# File lib/redcloth/formatters/html.rb 270 def escape_pre(text) 271 html_esc(text, :html_escape_preformatted) 272 end
escapement for HTML
in a PRE tag