aboutsummaryrefslogtreecommitdiffstats
path: root/bn_django/git_wiki/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'bn_django/git_wiki/views.py')
-rw-r--r--bn_django/git_wiki/views.py61
1 files changed, 53 insertions, 8 deletions
diff --git a/bn_django/git_wiki/views.py b/bn_django/git_wiki/views.py
index 2bfc034..6eff54b 100644
--- a/bn_django/git_wiki/views.py
+++ b/bn_django/git_wiki/views.py
@@ -50,7 +50,10 @@ def item(request, reqslug, blob=None):
i.update()
try:
- from docutils.core import publish_parts
+ from docutils.core import publish_parts,Publisher
+ import latex_directive
+ latex_directive.dorawtexstuff = False
+ latex_directive.register()
except ImportError:
if settings.DEBUG:
raise HttpResponseServerError(request)
@@ -72,12 +75,16 @@ def latexitem(request, reqslug, blob=None):
i.update()
try:
- from docutils.core import publish_parts
+ from docutils.core import publish_parts,Publisher
+ import latex_directive
+ latex_directive.dorawtexstuff = True
+ latex_directive.register()
except ImportError:
if settings.DEBUG:
raise HttpResponseServerError(request)
else:
- docutils_settings = getattr(settings, "GITWIKI_REST_SETTINGS", {})
+ docutils_settings = getattr(settings, "GITWIKI_REST_SETTINGS",
+ {'format':'latex'})
parts = publish_parts(source=i.contents, writer_name="latex", settings_overrides=docutils_settings)
hr = HttpResponse(mimetype="text/plain")
hr['Content-Disposition'] = 'filename=%s.tex' % reqslug
@@ -97,16 +104,54 @@ def pdfitem(request, reqslug, blob=None):
i.update()
try:
- from docutils.core import publish_parts
+ from docutils.core import publish_parts,Publisher
+ import latex_directive
+ latex_directive.dorawtexstuff = True
+ latex_directive.register()
+ import tempfile,re,os,shutil
except ImportError:
if settings.DEBUG:
raise HttpResponseServerError(request)
else:
- docutils_settings = getattr(settings, "GITWIKI_REST_SETTINGS", {})
+ docutils_settings = getattr(settings, "GITWIKI_REST_SETTINGS",
+ {'format':'latex'})
parts = publish_parts(source=i.contents, writer_name="latex", settings_overrides=docutils_settings)
- hr = HttpResponse(mimetype="text/plain")
- hr['Content-Disposition'] = 'filename=%s.tex' % reqslug
- hr.write(parts['whole'])
+ tmpdir = tempfile.mkdtemp()
+ pre = i.slug().split('/')
+ for fig in re.findall('\\includegraphics.*\{(.+)\}', parts['whole']):
+ if len(pre) > 1:
+ fig_blob = fromslug("%s/%s" % ('/'.join(pre[:-1])),fig)
+ else:
+ fig_blob = fromslug(fig)
+ # if might have to create subdirectories for figures
+ fig_pre = fig.split('/')
+ if len(fig_pre) > 1:
+ os.mkdir("%s/%s" % (tmpdir,'/'.join(fig_pre[:-1])))
+ fig_file = file(str("%s/%s" % (tmpdir,fig)),'wb')
+ fig_blob.update()
+ fig_file.write(fig_blob.contents)
+ fig_file.close()
+
+ hr = HttpResponse(mimetype="application/pdf")
+ #hr = HttpResponse()
+ hr['Content-Disposition'] = 'filename=%s.pdf' % reqslug
+ write_tex,pdf = os.popen2('rubber-pipe -qqq -d --into %s' % tmpdir)
+ write_tex.write(parts['whole'].replace('{\$}','$'))
+ write_tex.flush()
+ write_tex.close()
+ #hr.write(parts['whole'])
+ #pdf.flush()
+ for l in pdf.readlines():
+ hr.write(l)
+ try:
+ pdff = open("%s/rubtmp0.pdf" % tmpdir,'r')
+ for l in pdff.readlines():
+ hr.write(l)
+ pdff.close()
+ except:
+ pass
+ pdf.close()
+ shutil.rmtree(tmpdir)
return hr
def rawitem(request, reqslug, blob=None):