pirave / postmarkup

Automatically exported from code.google.com/p/postmarkup
0 stars 0 forks source link

FEATURE: isolate the HTML from the tag generation logic #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The basic idea is to allow overriding the HTML of tags easily without 
duplicating other logic like escaping harmful contents.

It is useful if you want to use a framework like jQuery to assign CSS rulesets 
(aka classes) as to than manipulate BBCode generated contents e.g. shrink 
pictures to fit page.

Here is an example for the ImgTag - html is isolated in the get_pattern() 
method.

  def get_pattern(self):
    return u'<div class="BBImage" ><img src="%%s" /></div>'
  def render_open(self, parser, node_index):

      contents = self.get_contents(parser)
      self.skip_contents(parser)

      # Validate url to avoid any XSS attacks
      if self.params:
          url = self.params.strip()
      else:
          url = postmarkup.strip_bbcode(contents)

      url = url.replace(u'"', "%22").strip()
      if not url:
          return u''
      scheme, netloc, path, params, query, fragment = urlparse(url)
      if not scheme:
          url = 'http://' + url
          scheme, netloc, path, params, query, fragment = urlparse(url)
      if scheme.lower() not in ('http', 'https', 'ftp'):
          return u''

      return self.get_pattern() % postmarkup.PostMarkup.standard_replace_no_break(url)  

Original issue reported on code.google.com by karaatan...@gmail.com on 6 Sep 2011 at 1:44

GoogleCodeExporter commented 8 years ago
That is a good idea. I don't have much time to work on Postmarkup (bugs only 
for a while). I'd be happy to accept a patch for this if it doesn't break 
anything.

Original comment by willmcgugan on 6 Sep 2011 at 1:49

GoogleCodeExporter commented 8 years ago
Thanks!

I will think about it - a patch ought to cover all tags and be useful in more 
than one scenario.

Original comment by karaatan...@gmail.com on 6 Sep 2011 at 2:12

GoogleCodeExporter commented 8 years ago
Going to close this ticket for now. I'll keep it in mind though, and may 
implement it the next time I work on new features.

Original comment by willmcgugan on 4 Dec 2011 at 9:51