Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "html_filter"
- class TextileFilter < HTMLFilter
- # Replace h[1-6]. Tjo with <h[1-6]>Tjo</h[1-6]>
- (1..6).each do |i|
- tag = "h#{i}"
- define_rule(on_one_line(chars("#{tag}. ") + capture)) do |match|
- content_tag tag, match.captures.first
- end
- end
- star = char("*")
- # Replace *tjo* with <strong>tjo</strong>
- define_rule(star + capture + star) do |match|
- content_tag :strong, match.captures.first
- end
- define_rule(/!(.*?)!/) do |match|
- tag :img, :src => match.captures.first
- end
- at = char("@")
- # Replace @tjo@ with <code>tjo</code>
- define_rule(at + capture + at) do |match|
- content_tag :code, match.captures.first
- end
- define_rule(quoted(capture) + char(":") + capture + white_space) do |match|
- content_tag :a, match.captures.first, :href => match.captures.second
- end
- # define_rule(/\n\n+/) { "\n\n" }
- define_rule(on_one_line(capture + newline)) do |match|
- if enclosing_tag(match.captures.first)
- match
- else
- match.to_s + tag(:br) + "\n"
- end
- end
- define_rule(/(\n\n|\A)(.*?)(\n\n|\Z)/) do |match|
- if is_block_level_tag? enclosing_tag(match)
- # Don't put block level tags in <p>s
- match
- else
- "\n\n" + content_tag(:p, match.captures.second) + "\n\n"
- end
- end
- end
Add Comment
Please, Sign In to add comment