module RedCloth::Formatters::HTML
include RedCloth::Formatters::Base
# escapement for regular HTML (not in PRE tag)
def escape(text)
html_esc(text)
end
# escapement for HTML in a PRE tag
def escape_pre(text)
html_esc(text, :html_escape_preformatted)
end
# escaping for HTML attributes
def escape_attribute(text)
html_esc(text, :html_escape_attributes)
end
def after_transform(text)
text.chomp!
end
[:h1, :h2, :h3, :h4, :h5, :h6, :p, :pre, :div].each do |m|
define_method(m) do |opts|
"<#{m}#{pba(opts)}>#{opts[:text]}#{m}>\n"
end
end
[:strong, :code, :em, :i, :b, :ins, :sup, :sub, :span, :cite].each do |m|
define_method(m) do |opts|
opts[:block] = true
"<#{m}#{pba(opts)}>#{opts[:text]}#{m}>"
end
end
def acronym(opts)
opts[:block] = true
"#{caps(:text => opts[:text])}"
end
def caps(opts)
if no_span_caps
opts[:text]
else
opts[:class] = 'caps'
span(opts)
end
end
def del(opts)
opts[:block] = true
"#{opts[:text]}"
end
[:ol, :ul].each do |m|
define_method("#{m}_open") do |opts|
opts[:block] = true
"#{"\n" if opts[:nest] > 1}#{"\t" * (opts[:nest] - 1)}<#{m}#{pba(opts)}>\n"
end
define_method("#{m}_close") do |opts|
"#{li_close}#{"\t" * (opts[:nest] - 1)}#{m}>#{"\n" if opts[:nest] <= 1}"
end
end
def li_open(opts)
"#{li_close unless opts.delete(:first)}#{"\t" * opts[:nest]}
" end def bc_close(opts) "\n" end def bq_open(opts) opts[:block] = true cite = opts[:cite] ? " cite=\"#{ escape_attribute opts[:cite] }\"" : '' "
\n" end def bq_close(opts) "\n" end LINK_TEXT_WITH_TITLE_RE = / ([^"]+?) # $text \s? \(([^)]+?)\) # $title $ /x def link(opts) if opts[:name] =~ LINK_TEXT_WITH_TITLE_RE md = LINK_TEXT_WITH_TITLE_RE.match(opts[:name]) opts[:name] = md[1] opts[:title] = md[2] end "#{opts[:name]}" end def image(opts) opts.delete(:align) opts[:alt] = opts[:title] img = "
#{no} #{opts[:text]}
\n" end def snip(opts) "#{opts[:text]}
\n"
end
def quote1(opts)
"‘#{opts[:text]}’"
end
def quote2(opts)
"“#{opts[:text]}”"
end
def multi_paragraph_quote(opts)
"“#{opts[:text]}"
end
def ellipsis(opts)
"#{opts[:text]}…"
end
def emdash(opts)
"—"
end
def endash(opts)
" – "
end
def arrow(opts)
"→"
end
def dim(opts)
opts[:text].gsub!('x', '×')
opts[:text].gsub!("'", '′')
opts[:text].gsub!('"', '″')
opts[:text]
end
def trademark(opts)
"™"
end
def registered(opts)
"®"
end
def copyright(opts)
"©"
end
def entity(opts)
"{opts[:text]};"
end
def amp(opts)
"&"
end
def gt(opts)
">"
end
def lt(opts)
"<"
end
def br(opts)
if hard_breaks == false
"\n"
else
"