customizing redcloth?

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
 
B

bdarcus

Tom said:
In case you haven't figured this out already, you need to either:
a) add :inline_textile_quote to the list of rules in the RedCloth
to_html method or
b) call to_html with to_html:)textile,:inline_textile_quote) or
c) add :inline_textile_quote DEFAULT_RULES constant.

Thanks Tom. Tied b, but no luck. I'll need to see if something's wrong
with my method.

That aside, is there some way for me to do a or c without touching the
redcloth.rb source?

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,947
Members
47,498
Latest member
yelene6679

Latest Threads

Top