ContentBBcode examples
Check out the new site at https://rkblog.dev.
13 November 2008
Comments
ContentBBcode is a pluggable set of BBcode-like tags that can perform various operations - from inserting some data from the database to JS wrappers.The code is located in /diamandas/cbcplugins:
- cbcparser.py - the parser
- tags.py - file with tags code, this file you may want to hack
def tagname(dic, text):
for i in dic:
text = text.replace(i['tag'], 'the thing plugin makes')
return text
[ rk : tagname someparam="somevalue" ]
[ rk : tagname someparam="somevalue" ] some text [ /rk : tagname ]
The dic argument contains data parsed from the thags in a dictionary:
[ rk : tagname someparam="somevalue" ] some text [ /rk : tagname ]
- i['tag'] - full code of the tag (for replacing)
- i['attributes']['ATRIBUTE_NAME'] - value of an attribute
- i['code'] - for double tags - text between tags
def h(dic, text):
"""
display h1-4 tags with labes/links
"""
s = 1
for i in dic:
text = text.replace(i['tag'], '<a name="' + str(s) +'" class="' + i['attributes']['id'] + '" title="' + i['code'] + '"></a><h' + i['attributes']['id'] + ' class="pageh"><a href="#' + str(s) +'">' + i['code'] + '</a></h' + i['attributes']['id'] + '>')
s = s+1
return text
def thumb(dic, text):
"""
display an image with a thumbnail and lightbox like script
"""
THUMB = '<a href="/site_media/resources/%s/images/%s" rel="facebox"><img src="/site_media/resources/%s/images/%s" alt="%s" /></a>'
for i in dic:
img = i['attributes']['src'].split('/')
thumb = 'thumb_' + img[-1]
im = img[-1]
domain = img[0]
if isfile(settings.MEDIA_ROOT + '/resources/' + domain + '/images/' + im):
if not isfile(settings.MEDIA_ROOT + '/resources/' + domain + '/images/' + thumb):
imi = Image.open(settings.MEDIA_ROOT + '/resources/' + domain + '/images/' + im)
imi.thumbnail((145, 145), Image.ANTIALIAS)
sharpener = ImageEnhance.Sharpness(imi)
imi = sharpener.enhance(2.4)
imi.save(settings.MEDIA_ROOT + '/resources/' + domain + '/images/' + thumb)
thm = THUMB % (domain, im, domain, thumb, im)
text = text.replace(i['tag'], thm)
return text
RkBlog
Check out the new site at https://rkblog.dev.
Comment article