dcwatson / bbcode

A pure python bbcode parser and formatter.
BSD 2-Clause "Simplified" License
68 stars 17 forks source link

Add more basic tags #5

Closed slav0nic closed 10 years ago

slav0nic commented 11 years ago

Some basic tags not implemented. For example:

[img]
[email]
[size]
[quote <name>]
[code [codetype]]
[font]
[sub]
[sup]

http://bb.bbboy.net/man/BbCode.html http://www.bbcode.org/reference.php

dcwatson commented 11 years ago

I want to think on this one a little more. I've previously held that things like [img] should not be included (see #2) by default. However, maybe there should be a way to easily install a more "batteries included" set of formatters without having to write them yourself.

Most of these would be trivial to write yourself in the meantime. Here's an example of a quote formatter I've written in the past:

def _render_quote(tag_name, value, options, parent, context):
   extra = u''
   if 'author' in options:
       extra = u' from %s' % options['author']
   elif 'quote' in options:
       extra = u' from %s' % options['quote']
   elif len(options) == 1:
       key, val = options.items()[0]
       if val:
           extra = u' from %s' % val
       elif key:
           extra = u' from %s' % key
   elif options:
       val = ' '.join([k for k in options.keys()])
       extra = u' from %s' % val
   return '<p class="quote">Quote%s:</p><blockquote>%s</blockquote>' % (extra, value)
slav0nic commented 11 years ago

will be better if u added some extra tags to lib but not enabling it by default if in u opinion this is evil

dcwatson commented 10 years ago

I've since added [sup] and [sub], and documented an advanced [quote] tag here:

http://bbcode.readthedocs.org/en/latest/formatters.html#advanced-quote-example

I've already commented on why [img] won't be included, and [font]/[size] are relics of a web long past. [code language] should be a custom tag, since the markup is going to vary depending how you do highlighting, etc. I'm on the fence about [email], since I'd imagine many implementations will want to obfuscate the link to prevent scraping, but it's super simple to add a less sophisticated simple formatter:

parser.add_simple_formatter('email', '<a href="mailto:%(value)s">%(value)s</a>')