B
bdarcus
Newbie question:
How do I add a new inline rule to RedCloth?
I want to add support for inline semantic quotes, including
support for citation markup. So, I want ``this'':someid#pages=23, to
be converted to:
<q cite="someid#pages=23">this</q>
I'm not getting the pattern processed though. I'm thinking it's because
RedCloth (and in particular the to_html method) doesn't know about the
new method I want to add, but have no idea how to resolve that (or if
I'm even right).
Bruce
#! /usr/bin/env ruby
require 'rubygems'
require 'redcloth'
class RedCloth
QUOTE_RE = /
([\s\[{(]|[#{PUNCT}])? # $pre
`` # start
(#{C}) # $atts
([^"]+?) # $text
\s?
(?:\(([^)]+?)\)(?="))? # $quote
'':
(\S+?) # $citeid
(\/)? # $slash
([^\w\/;]*?) # $post
(?=<|\s|$)
/x
def inline_textile_quote( text )
text.gsub!( QUOTE_RE ) do |m|
pre,atts,text,quote,citeid,slash,post = $~[1..7]
# citeid, citeid_quote = check_refs( citeid )
# quote ||= citeid_quote
atts = pba( atts )
atts = " cite=\"#{ citeid }\"#{ atts }"
text << "#{ quote }" if title
atts = shelve( atts ) if atts
"#{ pre }<q#{ atts }>#{ text }</q>#{ post }"
end
end
end
How do I add a new inline rule to RedCloth?
I want to add support for inline semantic quotes, including
support for citation markup. So, I want ``this'':someid#pages=23, to
be converted to:
<q cite="someid#pages=23">this</q>
I'm not getting the pattern processed though. I'm thinking it's because
RedCloth (and in particular the to_html method) doesn't know about the
new method I want to add, but have no idea how to resolve that (or if
I'm even right).
Bruce
#! /usr/bin/env ruby
require 'rubygems'
require 'redcloth'
class RedCloth
QUOTE_RE = /
([\s\[{(]|[#{PUNCT}])? # $pre
`` # start
(#{C}) # $atts
([^"]+?) # $text
\s?
(?:\(([^)]+?)\)(?="))? # $quote
'':
(\S+?) # $citeid
(\/)? # $slash
([^\w\/;]*?) # $post
(?=<|\s|$)
/x
def inline_textile_quote( text )
text.gsub!( QUOTE_RE ) do |m|
pre,atts,text,quote,citeid,slash,post = $~[1..7]
# citeid, citeid_quote = check_refs( citeid )
# quote ||= citeid_quote
atts = pba( atts )
atts = " cite=\"#{ citeid }\"#{ atts }"
text << "#{ quote }" if title
atts = shelve( atts ) if atts
"#{ pre }<q#{ atts }>#{ text }</q>#{ post }"
end
end
end