From: SonOfLilit Date: 2007-02-18T20:53:27+09:00 Subject: Re: Add custom rules to redcloth/textile how? Here is all the code implementing one of the default rules. To create custom rules would be simple: class RedCloth HYPERLINK = '(\S+?)([^\w\s/;=\?]*?)(?=\s|<|$)' TEXTILE_REFS_RE = /(^ *)\[([^\n]+?)\](#{HYPERLINK})(?=\s|$)/ def refs_textile( text ) text.gsub!( TEXTILE_REFS_RE ) do |m| @urlrefs ||= {} # in RedCloth code, initialized in initialize, but here I am giving an example of how to extend it flag, url = $~[2..3] @urlrefs[flag.downcase] = [url, nil] nil end end end textile_rules = [:refs_textile, :block_textile_table, :block_textile_lists, :block_textile_prefix, :inline_textile_image, :inline_textile_link, :inline_textile_code, :inline_textile_span, :glyphs_textile] redclothvar.to_html(textile_rules) From here, figuring how to add a rule is really simple. Define a method in class RedCloth with some RegExp action in it, call #to_html passing an array which is a copy of the textile_rules array in #to_html but with your rule added (array sets precedence, so it counts where your rule is). Reading _why's code is a pleasure, you should try it once. Careful: It might blow your mind and send you flying in a three headed truck with a bouncy marmoset. Specifically, beware of Camping. That is code on a level that might get those of us with less self confidence to decide that perhaps shoemaking is a more befitting career. Aur Saraf On 2/18/07, Ingo Weiss wrote: > Hi, > > has anybody successfully added custom inline tag rules to > RedCloth/textile? > > Thanks! > Ingo > > -- > Posted via http://www.ruby-forum.com/. > >