Congrats on shipping RedCloth 4.0! It looks like to fix a few problems that I''ve had with it. I do have a quick question: how do I disable certain rules? For example, Superusers/Administrators are allowed to use images, but regular users are not. There does not appear to be much documentation about disabling/custom rules. Ryan Alyea Fangamer Founder, Lead Developer ryan at fangamer.com
That''s correct; disabling specific rules is not something I anticipated. Were you able to disable certain rules with 3.0.4? The restrictions :filter_html and :sanitize_html persist in this new version. Are you aware of those? Do they meet your needs? I can think of a couple of image-specific workarounds: One is to prefilter your text before it ever hits RedCloth. Just one regex looking for images shouldn''t be too expensive. The other is to modify the output of just images by redefining that method in a new module that you use to extend the RedCloth object when the user isn''t a superuser. Best, Jason On Jul 23, 2008, at 7:22 PM, Ryan Alyea wrote:> Congrats on shipping RedCloth 4.0! It looks like to fix a few > problems that I''ve had with it. > > I do have a quick question: how do I disable certain rules? For > example, Superusers/Administrators are allowed to use images, but > regular users are not. There does not appear to be much > documentation about disabling/custom rules. > > Ryan Alyea > Fangamer Founder, Lead Developer > ryan at fangamer.com > > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/redcloth-upwards/attachments/20080724/b8572f4a/attachment-0001.html>
Yeah, it was really easy to disable whole rules with RedCloth(string).to_html(array_of_rules_to_run). For example my array_of_rules has images added for Administrators. In addition, some of my users didn''t like how loose the strikethrough was. It was really easy to disable by putting RedCloth::QTAGS.reject!{|x| x[0] == "-"} in my Rails initializers. The HTML filtering is post rendering, and while it might work, I would rather the filter chain not render what I do not want instead of post- filtering. I thought of extending the RedCloth::Formatters::HTML, or creating my own. The problem is that it''s not very future-forward. I would have to update my custom Formatters to fit the latest version. If there are no explicit disablers, do you mind if I fork and play around? Ideally I would love for my end to be: body = RedCloth(body_original).to_html(:disable_images unless @user.superuser?) where disable_images is a rule from a custom module I included. Ryan Alyea Fangamer Founder, Lead Developer ryan at fangamer.com On Jul 24, 2008, at 4:21 AM, Jason Garber wrote:> That''s correct; disabling specific rules is not something I > anticipated. Were you able to disable certain rules with 3.0.4? > The restrictions :filter_html and :sanitize_html persist in this new > version. Are you aware of those? Do they meet your needs? > > I can think of a couple of image-specific workarounds: One is to > prefilter your text before it ever hits RedCloth. Just one regex > looking for images shouldn''t be too expensive. The other is to > modify the output of just images by redefining that method in a new > module that you use to extend the RedCloth object when the user > isn''t a superuser. > > Best, > Jason > > On Jul 23, 2008, at 7:22 PM, Ryan Alyea wrote: > >> Congrats on shipping RedCloth 4.0! It looks like to fix a few >> problems that I''ve had with it. >> >> I do have a quick question: how do I disable certain rules? For >> example, Superusers/Administrators are allowed to use images, but >> regular users are not. There does not appear to be much >> documentation about disabling/custom rules. >> >> Ryan Alyea >> Fangamer Founder, Lead Developer >> ryan at fangamer.com >> >> _______________________________________________ >> Redcloth-upwards mailing list >> Redcloth-upwards at rubyforge.org >> http://rubyforge.org/mailman/listinfo/redcloth-upwards > > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/redcloth-upwards/attachments/20080724/4e7b1b15/attachment.html>
Fork away. That''s what GitHub is for! On Jul 24, 2008, at 9:58 PM, Ryan Alyea wrote:> Yeah, it was really easy to disable whole rules with RedCloth > (string).to_html(array_of_rules_to_run). For example my > array_of_rules has images added for Administrators. > > In addition, some of my users didn''t like how loose the > strikethrough was. It was really easy to disable by putting > > RedCloth::QTAGS.reject!{|x| x[0] == "-"} > > in my Rails initializers. > > The HTML filtering is post rendering, and while it might work, I > would rather the filter chain not render what I do not want instead > of post-filtering. > > I thought of extending the RedCloth::Formatters::HTML, or creating > my own. The problem is that it''s not very future-forward. I would > have to update my custom Formatters to fit the latest version. > > If there are no explicit disablers, do you mind if I fork and play > around? Ideally I would love for my end to be: > > body = RedCloth(body_original).to_html(:disable_images unless > @user.superuser?) > > where disable_images is a rule from a custom module I included. > > Ryan Alyea > Fangamer Founder, Lead Developer > ryan at fangamer.com > > On Jul 24, 2008, at 4:21 AM, Jason Garber wrote: > >> That''s correct; disabling specific rules is not something I >> anticipated. Were you able to disable certain rules with 3.0.4? >> The restrictions :filter_html and :sanitize_html persist in this >> new version. Are you aware of those? Do they meet your needs? >> >> I can think of a couple of image-specific workarounds: One is to >> prefilter your text before it ever hits RedCloth. Just one regex >> looking for images shouldn''t be too expensive. The other is to >> modify the output of just images by redefining that method in a >> new module that you use to extend the RedCloth object when the >> user isn''t a superuser. >> >> Best, >> Jason >> >> On Jul 23, 2008, at 7:22 PM, Ryan Alyea wrote: >> >>> Congrats on shipping RedCloth 4.0! It looks like to fix a few >>> problems that I''ve had with it. >>> >>> I do have a quick question: how do I disable certain rules? For >>> example, Superusers/Administrators are allowed to use images, but >>> regular users are not. There does not appear to be much >>> documentation about disabling/custom rules. >>> >>> Ryan Alyea >>> Fangamer Founder, Lead Developer >>> ryan at fangamer.com >>> >>> _______________________________________________ >>> Redcloth-upwards mailing list >>> Redcloth-upwards at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/redcloth-upwards >> >> _______________________________________________ >> Redcloth-upwards mailing list >> Redcloth-upwards at rubyforge.org >> http://rubyforge.org/mailman/listinfo/redcloth-upwards > > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/redcloth-upwards/attachments/20080724/a967aea0/attachment.html>
Okay, I forked and created a copy that works for me. You can take a look at it here: http://github.com/ROFISH/redcloth The syntax is a lovely RedCloth.new("*string*", [:disable_inline=>:strong]). In addition to images, DRYing things up allowed me to disable any inline element I wanted. Ryan Alyea Fangamer Founder, Lead Developer ryan at fangamer.com On Jul 24, 2008, at 9:29 PM, Jason Garber wrote:> Fork away. That''s what GitHub is for! > > On Jul 24, 2008, at 9:58 PM, Ryan Alyea wrote: > >> Yeah, it was really easy to disable whole rules with >> RedCloth(string).to_html(array_of_rules_to_run). For example my >> array_of_rules has images added for Administrators. >> >> In addition, some of my users didn''t like how loose the >> strikethrough was. It was really easy to disable by putting >> >> RedCloth::QTAGS.reject!{|x| x[0] == "-"} >> >> in my Rails initializers. >> >> The HTML filtering is post rendering, and while it might work, I >> would rather the filter chain not render what I do not want instead >> of post-filtering. >> >> I thought of extending the RedCloth::Formatters::HTML, or creating >> my own. The problem is that it''s not very future-forward. I would >> have to update my custom Formatters to fit the latest version. >> >> If there are no explicit disablers, do you mind if I fork and play >> around? Ideally I would love for my end to be: >> >> body = RedCloth(body_original).to_html(:disable_images unless >> @user.superuser?) >> >> where disable_images is a rule from a custom module I included. >> >> Ryan Alyea >> Fangamer Founder, Lead Developer >> ryan at fangamer.com >> >> On Jul 24, 2008, at 4:21 AM, Jason Garber wrote: >> >>> That''s correct; disabling specific rules is not something I >>> anticipated. Were you able to disable certain rules with 3.0.4? >>> The restrictions :filter_html and :sanitize_html persist in this >>> new version. Are you aware of those? Do they meet your needs? >>> >>> I can think of a couple of image-specific workarounds: One is to >>> prefilter your text before it ever hits RedCloth. Just one regex >>> looking for images shouldn''t be too expensive. The other is to >>> modify the output of just images by redefining that method in a >>> new module that you use to extend the RedCloth object when the >>> user isn''t a superuser. >>> >>> Best, >>> Jason >>> >>> On Jul 23, 2008, at 7:22 PM, Ryan Alyea wrote: >>> >>>> Congrats on shipping RedCloth 4.0! It looks like to fix a few >>>> problems that I''ve had with it. >>>> >>>> I do have a quick question: how do I disable certain rules? For >>>> example, Superusers/Administrators are allowed to use images, but >>>> regular users are not. There does not appear to be much >>>> documentation about disabling/custom rules. >>>> >>>> Ryan Alyea >>>> Fangamer Founder, Lead Developer >>>> ryan at fangamer.com >>>> >>>> _______________________________________________ >>>> Redcloth-upwards mailing list >>>> Redcloth-upwards at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/redcloth-upwards >>> >>> _______________________________________________ >>> Redcloth-upwards mailing list >>> Redcloth-upwards at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/redcloth-upwards >> >> _______________________________________________ >> Redcloth-upwards mailing list >> Redcloth-upwards at rubyforge.org >> http://rubyforge.org/mailman/listinfo/redcloth-upwards > > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/redcloth-upwards/attachments/20080727/e0dbb171/attachment-0001.html>
Hello, I am a Ruby newbie, but I would like to disable a specific rule. I do not want (c) to become the copyright symbol and (r) to become the registered symbol. I commented our all the instances I could find of these in the various RedCloth files, but it does not seem to be working. How can I remove a rule? And will it affect my ability to upgrade when the new RedCloth comes out? Thanks, Jonathan -- Posted via http://www.ruby-forum.com/.
Well, off the top of my head I don''t know how you can disable a rule so it isn''t recognized, but probably the easiest way to have the same net result is to change the formatting that happens when it _is_ recognized so that it''s unchanged. $ irb -rubygems irb(main):001:0> require ''RedCloth'' => true irb(main):003:0> RedCloth.new(''This is my trademark(r)'').to_html => "<p>This is my trademark®</p>" irb(main):004:0> module RedCloth::Formatters::HTML irb(main):005:1> def registered(opts) irb(main):006:2> " (r)" irb(main):007:2> end irb(main):008:1> end => nil irb(main):009:0> RedCloth.new(''This is just a normal (r).'').to_html => "<p>This is just a normal (r).</p>" Now the problem is that by design the registered symbol consumes any spaces before it. I don''t have a solution for that. The other thing you could do is to preprocess your text and surround any instance of (r) or (c) with one of the Textile escaping patterns. $ irb -rubygems irb(main):001:0> require ''RedCloth'' => true irb(main):002:0> text = "No trademarks (r) in here!" => "No trademarks (r) in here!" irb(main):003:0> text.gsub!(/(\([cr]\))/, "==\\1==") => "No trademarks ==(r)== in here!" irb(main):004:0> RedCloth.new(text).to_html => "<p>No trademarks (r) in here!</p>" This latter suggestion is likely to never break with an upgrade; the former one will only break if the name of the method changes. Good luck! Jason On Oct 30, 2008, at 11:46 AM, Jonathan Brun wrote:> Hello, > > I am a Ruby newbie, but I would like to disable a specific rule. I do > not want (c) to become the copyright symbol and (r) to become the > registered symbol. I commented our all the instances I could find of > these in the various RedCloth files, but it does not seem to be > working. > How can I remove a rule? And will it affect my ability to upgrade when > the new RedCloth comes out? > > Thanks, > Jonathan > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Redcloth-upwards mailing list > Redcloth-upwards at rubyforge.org > http://rubyforge.org/mailman/listinfo/redcloth-upwards-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/redcloth-upwards/attachments/20081031/0e90af32/attachment.html>