Re: Re: reST
Wari Wahab <[email protected]>
| Newsgroups | gmane.comp.web.pyblosxom.user |
|---|---|
| Message-ID | <[email protected]> |
[email protected] wrote: > I solved this problem in the simplest manner I could think of: I have > an "images" directory in my public_html directory, and a script that > uses ImageMagick to create thumbnails for all the images in the > directory. Then I just refer to the images by relative url in my > posts. Hmmm.. That's one way :) > I don't know how to use a postformatter to do thumbnails without > mucking around in reStructuredText stuff, which I really don't want > to do. Maybe there's a good, easy way and I just don't see it. There's no need to muck around with the reST at all, I know the example I gave you with Kai can be a little too much, but he did what he did because there was no such thing as postformatter at all when he mucked up the textism markup (no pun intended). Postformatters are plugins that happens after you formatted your text, it should look for certain strings in your text and then reformat it to whatever.. A glossary postformatter would see '{me}' and expand it to '<a href="mailto:[email protected]">Wari Wahab</a>', acronym expanders would see 'XHTML' and expand the thing to '<acronym title="eXtensible HyperText Markup Language">XHTML</acronym>'.. Kai's postformatter in theory, would see (without reST mucking up such markup first) !_imgurl(alttext)!, and all hell breaks loose as if the thumbnail is not there in the first place, it will actually create the thumbnail and then insert the thumbnail image url and link it to the big one.. > Attached is a version of rst.py with a usage docstring. Let me know > if the instructions are good enough. I attached a modified one and it calls a postformatter (if available) after rendering the text (see what you can gain from it, possibilities are endless). I've refactored it a bit and now it is also a preformatter for plain old files that ends with .txt See if you like the changes. For all other users wanting to try this out, unfortunately it's not pyblosxom 0.6 compatible, it's using a new plugin API that's brewing in CVS. Those of you who is not willing to figure out CVS, you can always ask me for the latest snapshot (I might make it easy for it to be accessible).
rst.py
(text/plain, 1.6 KB)
"""
A reStructuredText entry formatter for pyblosxom. reStructuredText is
part of the docutils project (http://docutils.sourceforge.net/). To
use, you need a *recent* version of docutils. A development snapshot
(http://docutils.sourceforge.net/#development-snapshots) will work fine.
Install docutils, copy this file to your pyblosxom libs/plugins
directory, and you're ready to go. Files with a .rst extension will be
marked up as reStructuredText.
You can configure this as your default preformatter for .txt files by
configuring it in your config file as follows::
py['parser'] = 'reST'
or in your blosxom .txt file entries, place a '#parser reST' line after the
title of your blog::
My Little Blog Entry
#parser reST
My main story...
"""
__version__ = '$Id:$'
__author__ = 'Sean Bowman <sean dot bowman at acm dot org>'
PREFORMATTER_ID = 'reST'
from docutils.core import publish_string
from libs import tools
def cb_entryparser(args):
args['rst'] = readfile
return args
def cb_preformat(args):
if args['parser'] == PREFORMATTER_ID:
return parse(''.join(args['story']))
def parse(story):
html = publish_string(story, writer_name='html')
return html[html.find('<body>') + 6:html.find('</body>')]
def readfile(filename, request):
entryData = {}
d = file(filename).read()
entryData['title'] = d.split('\n')[0]
d = d[len(title):]
entryData['body'] = parse(d)
entryData = {'title': title,
'body': body}
# Call the postformat callbacks
tools.run_callback('postformat',
{'request': request,
'entry_data': entryData})
return entryData