def fixcode(block, doctype): # Some HTML preparation block = Detag(block) block = LeftMargin(block) # Pull out title if available re_title = re.compile('^#\-+ (.+) \-+#$', re.M) if_title = re_title.match(block) if if_title: title = if_title.group(1) block = re_title.sub('', block) # take title out of code else: title = '' #block = string.strip(block) # no surrounding whitespace # Process the code block with Py2HTML (if possible and appropriate) if py_formatter and (string.count(title, '.py') or string.count( title, 'Python') or string.count(title, 'python') or string.count(title, 'py_') or doctype == 'PYTHON'): fh = open('tmp', 'w') fh.write(block) fh.close() py2html.main([None, '-format:rawhtml', 'tmp']) block = open('tmp.html').read() block = code_block % (title, block) # elif the-will-and-the-way-is-there-to-format-language-X: # elif the-will-and-the-way-is-there-to-format-language-Y: else: block = code_block % (title, '<pre>' + block + '</pre>') return block
def fixcode(block, doctype): # Some HTML preparation block = Detag(block) block = LeftMargin(block) # Pull out title if available re_title = re.compile('^#\-+ (.+) \-+#$', re.M) if_title = re_title.match(block) if if_title: title = if_title.group(1) block = re_title.sub('', block) # take title out of code else: title = '' #block = string.strip(block) # no surrounding whitespace # Process the code block with Py2HTML (if possible and appropriate) if py_formatter and (string.count(title,'.py') or string.count(title,'Python') or string.count(title,'python') or string.count(title,'py_') or doctype == 'PYTHON'): fh = open('tmp', 'w') fh.write(block) fh.close() py2html.main([None, '-format:rawhtml', 'tmp']) block = open('tmp.html').read() block = code_block % (title, block) # elif the-will-and-the-way-is-there-to-format-language-X: # elif the-will-and-the-way-is-there-to-format-language-Y: else: block = code_block % (title, '<pre>'+block+'</pre>') return block
def cmd_DisplayFile(self,parDict): fileName = parDict['fileName'] if not fileName: print " File name not given " else: import py2html p,fileName = os.path.split(fileName) # take care of malicious user print "<B> File: %s </B> " %fileName py2html.main(['dummy','-stdout',fileName])
def createHighlightedSource(self, filename, dir): import py2html targetName = '%s/%s.html' % (dir, os.path.basename(filename)) self.printMsg(' Creating %s...' % targetName) realout = sys.stdout sys.stdout = StringIO() # py2html.main([None, '-stdout', '-format:rawhtml', '-files', filename]) py2html.main([None, '-stdout', '-files', filename]) result = sys.stdout.getvalue() result = replace(result, '\t', ' ') # 4 spaces per tab open(targetName, 'w').write(result) sys.stdout = realout