try:
    yield path
finally:
    shutil.rmtree(path, ignore_errors=True)

def magic_convert_function(text):
    with mkdtemp() as outdir:
        with mkdtemp() as indir:
            with open(os.path.join(indir, 'test.rst'), 'w') as infile:
                infile.write(text)
support = WebSupport(srcdir=indir, builddir=outdir, search='xapian')
support.build()
contents = support.get_document('test')
return contents['body']
Is there any API for formatting Sphinx text?