dcwatson / bbcode

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

url should allow specifying target and rel attributes #19

Closed rbu closed 6 years ago

rbu commented 9 years ago

It would be nice if we could replace

[url=example.com]page[/url]

with this: <a href="http://example.com/" target="_blank" rel="nofollow">link</a>

by setting an config option to the BBCode instance.

dcwatson commented 9 years ago

I'm not sure how many bells and whistles I want to tack on to the default url tag implementation, considering you can do whatever you like by creating your own. To see how the default one works:

https://github.com/dcwatson/bbcode/blob/master/bbcode.py#L156

That said, this isn't the first request for custom behavior, so maybe it's worth making something like a template string that the default url tag can use. Something along the lines of Parser.url_template = '<a href="%s">%s</a>' that the default implementation could use.

rbu commented 9 years ago

That would also work for us. If you go this route, consider using a format() string like this: '<a href="{href}">{text}</a>'.format(href='https://example.com', text='site')

That allows reordering the arguments and improves self-documentation of the parameter for users (like me!).

rbu commented 9 years ago

@dcwatson, any update on this? I could provide a PR if you haven't started on this yet and you'd consider merging it

dcwatson commented 9 years ago

A PR would be much appreciated.

dcwatson commented 6 years ago

Implemented by #28