Commits

Akihiro Uchida committed efeb359

tiny modification

Comments (0)

Files changed (2)

latex_directive.py

 """
 Implement latex directive.
-
 """
 import os
 import shutil
-import sha
+import hashlib
 import tempfile
 import subprocess
 
 from docutils.parsers.rst.directives import register_directive, flag
 from docutils.parsers.rst.roles import register_canonical_role
 
-
 def latex_math(tex):
     """ Process `tex` and produce image nodes. """
     image_names = latex_snippet_to_png(tex)
-
     the_nodes = []
     alt = tex
-    for pageno, name in enumerate(image_names):
-        
+    for name in image_names:
         the_nodes.append(nodes.image(uri=name, alt=alt))
         alt = ''
-                         
     return the_nodes
-    
 
 def latex_directive(name, arguments, options, content, lineno,
                     content_offset, block_text, state, state_machine):
     """ Latex directive. """
     tex = '\n'.join(content)
-
     return latex_math(tex)
 
 latex_directive.content = True
 
-
 def latex_role(role, rawtext, text, lineno, inliner,
                options={}, content=[]):
     """ Latex role. """
-
     i = rawtext.find('`')
     tex = rawtext[i+1:-1]
     return latex_math(tex), []
     register_directive('latex', latex_directive)
     register_canonical_role('latex', latex_role)
 
-    
-
 def call_command_in_dir(app, args, targetdir):
-
     cwd = os.getcwd()
     try:
         os.chdir(targetdir)
         print ' '.join(args)
         p = subprocess.Popen(app + ' ' + ' '.join(args), shell=True)
         sts = os.waitpid(p.pid, 0)
-
         # FIXME -- should we raise an exception of status is non-zero?
-        
     finally:
         # Restore working directory
         os.chdir(cwd)
 def latex_snippet_to_png(inputtex, prologue=''):
     """ Convert a latex snippet into a png. """
     
-    tex = latex_template % { 'raw': inputtex, 'prologue': prologue }
-    namebase = latex_name_template % sha.new(tex).hexdigest()
+    tex = latex_template % {'raw': inputtex, 'prologue': prologue }
+    namebase = latex_name_template % hashlib.sha1(tex).hexdigest()
     dst = namebase + '%d.png'
 
     tmpdir = tempfile.mkdtemp()
         if not res is None:
             # FIXME need to return some sort of error
             return []
-
         page = 1
         pagenames = []
         while os.access("%s/%s%d.png" % (tmpdir, namebase, page), os.R_OK):
     finally:
         # FIXME do some tidy up here
         pass
-
     return pagenames
             
 #!/usr/bin/env python
 
-# Author: John Gill
-# Contact: swfiua@gmail.com
-# Revision: $$
-# Date: $ $
+# Author: Akihiro Uchida
+# Original Author: John Gill
 # Copyright: This module has been placed in the public domain.
 
 """
 from docutils.core import publish_cmdline, Publisher, default_description
 
 import latex_directive
-latex_directive.register()  # Enable the ABC directive
+latex_directive.register()
 
 description = ('Generates (X)HTML documents from standalone reStructuredText '
                'sources.  ' + default_description)