Hi there. I have this line in my view: <%= RedCloth.new(@news.long, [:filter_html, :filter_styles]).to_html(:textile) %> but it doesn''t filter out the html out, from this input: --------- h1. Header some paragraph <h1>BOOM</h1> #This should be filtered away ? other paragraph ---------- What am i doing wrong ? it renderes the h1. and all hte paragraph fine, but it doesn''t filter the <> type html tags. - Emil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
augustlilleaas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jan-21  11:46 UTC
Re: Problems using the RedCloth gem !?!
I think it filters some HTML tags, but not normal and safe ones like <br />, <p>, <h1> etc. On Jan 21, 11:42 am, Emil Kampp <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi there. > > I have this line in my view: > > <%= RedCloth.new(@news.long, [:filter_html, > :filter_styles]).to_html(:textile) %> > > but it doesn''t filter out the html out, from this input: > > --------- > h1. Header > > some paragraph > > <h1>BOOM</h1> #This should be filtered away ? > > other paragraph > ---------- > > What am i doing wrong ? it renderes the h1. and all hte paragraph fine, > but it doesn''t filter the <> type html tags. > > - Emil > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Is there any way, that i can filter all html tags from the text, while rendering it with the gem ? - Emil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
If there is, I haven''t found it. I _have_ though found a useful Regex
for
doing that. It''s a slightly modified version of the one used in Typo.
[No
source code will go scavenged!] I know I might catch some flack for doing so
but I choose to add this method to the String class itself, as I use it a
lot.
class String
  def strip_html(leave_whitespace = false)
    name = /[\w:_-]+/
    value =
/([A-Za-z0-9]+|(''[^'']*?''|"[^"]*?"))/
    attr = /(#{name}(\s*=\s*#{value})?)/
    rx
/<[!\/?\[]?(#{name}|--)(\s+(#{attr}(\s+#{attr})*))?\s*([!\/?\]]+|--)?>/
    (leave_whitespace) ?  self.gsub(rx, "").strip : self.gsub(rx,
"").gsub(/\s+/, " ").strip
  end
end
Be aware, though, that there is stil a lot of HTML entities left in the
Textilized string. [™, etc.] Depending on your end use, you may need
to strip those entities as well. Let me know if you do need that because
I''ve written some really handy code for it, completely based on what
transformations RedCloth does. You know, only make the server work as hard
as it has to.
RSL
On 1/21/07, Emil Kampp
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> Is there any way, that i can filter all html tags from the text, while
> rendering it with the gem ?
>
> - Emil
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
I do need to remove ALL HTML enteties from the text, before rendering it. Is there any way to allow only some redcloth formatting to be enterpreted ? such as not enterpreting lets say the h1. tag but accept the h2. tag ? - Emil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
In what circumstances would you want an h1 and not an h2? Sounds like
you''re
definitely going to need to Regex that one.
Anyhow, here''s the two additional methods [both on the String class as
before] for dealing with RedClothed HTML entities.
  def strip_accents
    self.gsub(/&([A-Za-z])(grave|acute|circ|tilde|uml|ring|lig|cedil);/,
''\1'')
  end
  def convert_entities
    dummy = self.dup
    {
      "#822[01]" => "\"",
      "#821[67]" => "''",
      "#8230" => "...",
      "#8211" => "-",
      "#8212" => "--",
      "#215" => "x",
      "gt" => ">",
      "lt" => "<",
      "(#8482|trade)" => "(tm)",
      "(#174|reg)" => "(r)",
      "(#169|copy)" => "(c)",
      "(#38|amp)" => "&",
      "nbsp" => " ",
      "cent" => " cent",
      "pound" => " pound",
    }.each do |textiled, normal|
      dummy.gsub!(/&#{textiled};/, normal)
    end
    dummy.gsub(/&[^;]+;/, "")
  end
On 1/22/07, Emil Kampp
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> I do need to remove ALL HTML enteties from the text, before rendering
> it.
>
> Is there any way to allow only some redcloth formatting to be
> enterpreted ? such as not enterpreting lets say the h1. tag but accept
> the h2. tag ?
>
> - Emil
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---