本文整理汇总了Python中plasTeX.Renderers.PageTemplate.Renderer类的典型用法代码示例。如果您正苦于以下问题:Python Renderer类的具体用法?Python Renderer怎么用?Python Renderer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Renderer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
def render(self, document):
templatepaths = [os.path.join(os.path.dirname(__file__), '../templates/html'),
os.path.join(os.path.dirname(__file__), '../../templates/html'),
'/usr/lib/problemtools/templates/html']
templatepath = None
for p in templatepaths:
if os.path.isdir(p):
templatepath = p
break
if templatepath == None:
raise Exception('Could not find templates needed for conversion to HTML')
# Ugly but unfortunately PlasTeX is quite inflexible when it comes to
# configuring where to search for template files
os.environ['ProblemRendererTEMPLATES'] = templatepath
# Gigantic ugliness to cope with PlasTeX problem that prevents
# plastex from resetting list of invalid filenames when doing multiple renderings.
f = Filenames('blah.html', {}, {}, 'html')
f.invalid.clear()
# Setup our own mini-imager which just does copying and converts pdfs to png
self.imager = ImageConverter(document)
Renderer.render(self, document)
示例2: cleanup
def cleanup(self, document, files, postProcess=None):
res = _Renderer.cleanup(self, document, files, postProcess=postProcess)
self.doJavaHelpFiles(document, version='1')
self.doJavaHelpFiles(document, version='2')
self.doEclipseHelpFiles(document)
self.doCHMFiles(document)
return res
示例3: cleanup
def cleanup(self, document, files, postProcess=None):
"""
Cleanup method called at the end of rendering.
Uses the base renderer cleanup but calls packages callbacks before and
after. Callbacks should be listed in
document.userdata['preCleanupCallbacks']
or document.userdata['postCleanupCallbacks']. Each call back should accept the
current document as its only argument. Pre-cleanup call back must return
the list of path of files they created (relative to the output directory).
"""
rendererdata = document.rendererdata.get('html5', dict())
preCleanupCallbacks = rendererdata.get('preCleanupCallbacks', [])
for preCleanupCallback in preCleanupCallbacks:
files += preCleanupCallback(document)
_Renderer.cleanup(self, document, files, postProcess)
示例4: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
# Force XHTML syntax on empty tags
s = re.compile(r"(<(?:hr|br|img|link|meta)\b.*?)\s*/?\s*(>)", re.I | re.S).sub(r"\1 /\2", s)
# Remove empty paragraphs
s = re.compile(r"<p>\s*</p>", re.I).sub(r"", s)
# Add a non-breaking space to empty table cells
s = re.compile(r"(<(td|th)\b[^>]*>)\s*(</\2>)", re.I).sub(r"\1 \3", s)
return s
示例5: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
s = s.strip()
# Force XHTML syntax on empty tags
s = re.sub(r'(<(?:hr|br|img|link|meta|col)\b.*?)\s*/?\s*(>)',
r'\1 /\2',
s,
re.I|re.S)
# replace the document header: this is an awful workaround for
# a problem with simpleTAL where is mangles the mathml part of
# the header (but only on recent versions of Linux
s = re.sub(r'put_mathml_stuff_here', with_mathml, s, count=1)
# replace xml:id with id
s = re.sub(r'xml:id', r'id', s)
# replace the first chapter with a preface
s = re.sub(r'<chapter', r'<preface', s, count=1)
s = re.sub(r'</chapter>', r'</preface>', s, count=1)
# no space before an indexterm
s = re.sub(r' <indexterm', r'<indexterm', s)
s = re.sub(r'indexterm> ', r'indexterm>', s)
# remove newlines in programlistings
s = re.sub(r'\s*(<programlisting>)\n', r'\1', s)
s = re.sub(r'\n(</programlisting>)\s*', r'\1', s)
# remove para around bookinfo
s = re.sub(r'<para>\s*(<bookinfo>)', r'\1', s)
s = re.sub(r'(</bookinfo>)\s*</para>', r'\1', s)
# remove pointless anchors
s = re.sub(r'\s*(<anchor[^>]*>)\s*', r'',s)
# get rid of empty paragraphs
s = re.sub(r'\s*<para>\s*</para>\s*', r'', s)
s = re.sub(r'\s*<para>\s*</para>\s*', r'', s)
s = re.sub(r'\s*<para>\s*</para>\s*', r'', s)
# get rid of empty partintro
s = re.sub(r'\s*<partintro>\s*</partintro>\s*', r'', s)
# get rid of redundant references
s = re.sub(r'\w*.<xref', r'<xref', s)
return s
示例6: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
s = re.compile(r'</partintro>\s*<partintro>',re.I).sub(r'',s)
#
s = re.compile(r'<para>\s*(<articleinfo>)',re.I).sub(r'\1',s)
s = re.compile(r'(</articleinfo>)\s*</para>',re.I).sub(r'\1',s)
#
s = re.compile(r'(<informalfigure>)\s*<para>',re.I).sub(r'\1',s)
s = re.compile(r'</para>\s*(</informalfigure>)',re.I).sub(r'\1',s)
#
s = re.compile(r'(<para>)\s*<para>',re.I).sub(r'\1',s)
s = re.compile(r'</para>\s*(</para>)',re.I).sub(r'\1',s)
#
# s = s.replace('&','&')
#
s = re.compile(r'<para>\s*</para>', re.I).sub(r'', s)
return s
示例7: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
s = re.compile(r"</partintro>\s*<partintro>", re.I).sub(r"", s)
#
s = re.compile(r"<para>\s*(<articleinfo>)", re.I).sub(r"\1", s)
s = re.compile(r"(</articleinfo>)\s*</para>", re.I).sub(r"\1", s)
#
s = re.compile(r"(<informalfigure>)\s*<para>", re.I).sub(r"\1", s)
s = re.compile(r"</para>\s*(</informalfigure>)", re.I).sub(r"\1", s)
#
s = re.compile(r"(<para>)(\s*<para>)+", re.I).sub(r"\1", s)
s = re.compile(r"(</para>\s*)+(</para>)", re.I).sub(r"\2", s)
#
# s = s.replace('&','&')
#
s = re.compile(r"<para>\s*</para>", re.I).sub(r"", s)
return s
示例8: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
if have_lxml:
tree = etree.fromstring(s)
for name in ['itemizedlist', 'table', 'term', 'para']:
tree = clean_para(tree, name)
s = etree.tostring(tree)
else:
s = re.sub(r'</partintro>\s*<partintro>','', s, flags=re.I)
s = re.sub(r'<para>\s*(<articleinfo>)', r'\1', s, flags=re.I)
s = re.sub(r'(</articleinfo>)\s*</para>', r'\1', s, flags=re.I)
s = re.sub(r'<para>\s*</para>', '', s, flags=re.I)
for name in ['itemizedlist', 'term', 'para']:
s = re.sub(r'(<%s>)\s*<para>' % name, r'\1', s, flags=re.I)
s = re.sub(r'</para>\s*(</%s>)' % name, r'\1', s, flags=re.I)
return s
示例9: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
# Fecha as tags solitárias como em <br />
s = re.compile(r'(<(?:hr|br|img|link|meta)\b.*?)\s*/?\s*(>)',
re.I|re.S).sub(r'\1 /\2', s)
# Remove os parágrafos vazios
s = re.compile(r'<p>\s*</p>', re.I).sub(r'', s)
# Espaço nas células vazias das tabelas
s = re.compile(r'(<(td|th)\b[^>]*>)\s*(</\2>)', re.I).sub(r'\1 \3', s)
# Sem ":" nos ids e nos links
# s = re.compile(r'id="(.*?):(.*?)"', re.I).sub(r'id="\1\2"', s)
s = re.compile(r'<(\w+) id="(.*?):(.*?)"(.*?)>', re.I | re.U).sub(r'<\1 id="\2\3"\4>', s)
s = re.compile(r'<a href="((?:http://)?.*?)#(.*?):(.*?)"(.*?)>', re.I | re.U).sub(r'<a href="\1#\2\3"\4>', s)
return s
示例10: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
# Remove empty paragraphs
s = re.compile(r'<p>\s*</p>', re.I).sub(r'', s)
# Add a non-breaking space to empty table cells
s = re.compile(r'(<(td|th)\b[^>]*>)\s*(</\2>)', re.I).sub(r'\1 \3', s)
for fun in document.rendererdata['html5'].get('processFileContents', []):
s = fun(document, s)
filters = document.config['html5']['filters']
for filter_ in filters:
proc = subprocess.Popen(
shlex.split(filter_),
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
output, output_err = proc.communicate(s.encode(encoding="utf-8"))
if not output_err:
s = output.decode(encoding="utf-8")
return s
示例11: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
# Force XHTML syntax on empty tags
s = re.sub(r'(<(?:hr|br|img|link|meta|col)\b.*?)\s*/?\s*(>)',
r'\1 /\2',
s,
re.I|re.S)
s = re.sub(r'xml:id', r'id',s)
# replace the first chapter with a preface
s = re.sub(r'<chapter', r'<preface', s, count=1)
s = re.sub(r'</chapter>', r'</preface>', s, count=1)
# no space before an indexterm
s = re.sub(r' <indexterm', r'<indexterm', s)
s = re.sub(r'indexterm> ', r'indexterm>', s)
# remove newlines in programlistings
s = re.sub(r'\s*(<programlisting>)\n', r'\1', s)
s = re.sub(r'\n(</programlisting>)\s*', r'\1', s)
# remove para around bookinfo
s = re.sub(r'<para>\s*(<bookinfo>)', r'\1', s)
s = re.sub(r'(</bookinfo>)\s*</para>', r'\1', s)
# remove pointless anchors
s = re.sub(r'\s*(<anchor[^>]*>)\s*', r'',s)
# get rid of empty paragraphs
s = re.sub(r'\s*<para>\s*</para>\s*', r'', s)
s = re.sub(r'\s*<para>\s*</para>\s*', r'', s)
s = re.sub(r'\s*<para>\s*</para>\s*', r'', s)
return s
示例12: cleanup
def cleanup(self, document, files, postProcess=None):
res = _Renderer.cleanup(self, document, files, postProcess=postProcess)
return res
示例13: loadTemplates
def loadTemplates(self, document):
"""Load templates as in PageTemplate but also look for packages that
want to override some templates and handles extra css and javascript."""
try:
import jinja2
except ImportError:
log.error('Jinja2 is not available, hence the HTML5 renderer cannot be used.')
_Renderer.loadTemplates(self, document)
rendererdata = document.rendererdata['html5'] = dict()
config = document.config
rendererDir = os.path.dirname(__file__)
themeDir = os.path.join(rendererDir, 'Theme', self.loadedTheme)
srcDir = document.userdata['working-dir']
buildDir = os.getcwd()
# Theme css has already been copied by PageTemplate.loadTemplates,
# provided config['general']['copy-theme-extras'] is true
# Still try to create styles directory is case it's false
try:
os.mkdir('styles')
except OSError:
# This should mean the directory already exists
pass
# Start building the css list for use by the layout template
if config['html5']['use-theme-css'] and config['general']['copy-theme-extras']:
rendererdata['css'] = ['theme-' + config['html5']['theme-css'] + '.css']
else:
rendererdata['css'] = []
# Theme js has already been copied by PageTemplate.loadTemplates,
# provided config['general']['copy-theme-extras'] is true
# Still try to create js directory is case it's false
try:
os.mkdir('js')
except OSError:
pass
# Start building the js list for use by the layout template
if (config['html5']['use-theme-js'] and
config['general']['copy-theme-extras']):
rendererdata['js'] = sorted(
os.listdir(os.path.join(themeDir, 'js')))
else:
rendererdata['js'] = []
for resrc in document.packageResources:
# Next line may load templates or change
# document.rendererdata['html5'] or copy some files to buildDir
resrc.alter(
renderer=self,
rendererName='html5',
document=document,
target=buildDir)
# Last loaded files (hence overriding everything else) come from user
# configuration
cssBuildDir = os.path.join(buildDir, 'styles')
for css in config['html5']['extra-css']:
rendererdata['css'].append(css)
shutil.copy(os.path.join(srcDir, css), cssBuildDir)
jsBuildDir = os.path.join(buildDir, 'js')
for js in config['html5']['extra-js']:
rendererdata['js'].append(js)
shutil.copy(os.path.join(srcDir, js), jsBuildDir)
示例14: cleanup
def cleanup(self, document, files, postProcess=None):
res = _Renderer.cleanup(self, document, files, postProcess=postProcess)
# Define uma lista de arquivos que devem ficar fora de OEBPS/,
# e move os outros arquivos / diretórios, apagando os diretórios
# pré-existentes em OEBPS/
dirNaoMover = ['mimetype', 'OEBPS', 'META-INF', 'Makefile']
moverDirs = list(set(os.listdir('.')) - set(dirNaoMover))
for arq in moverDirs:
if os.path.isdir('OEBPS/%s' % arq):
shutil.rmtree('OEBPS/%s' % arq)
shutil.move(arq, 'OEBPS/%s' % arq)
# Move os arquivos de conteúdo para OEBPS/
# for arq in files:
# os.rename(arq, 'OEBPS/' + arq)
# Mover todos os arquivos e diretórios que não sejam o META-INF/, OEBPS/ e mimetype
latexdoc = document.getElementsByTagName('document')[0]
# Cria uma entrada para o bookid com um UUID aleatório.
latexdoc.setUserData('bookid', 'urn:uuid:%s' % uuid.uuid4())
# Adiciona o mimetype do arquivo ncx
if not mimetypes.types_map.has_key('.ncx'):
mimetypes.add_type('application/x-dtbncx+xml', '.ncx')
# Mimetypes dos arquivos .html, .svg e .otf
mimetypes.add_type('application/xhtml+xml', '.html')
mimetypes.add_type('image/svg+xml', '.svg')
mimetypes.add_type('application/vnd.ms-opentype', '.otf')
# Gera o arquivo ncx
self.doNCXFiles(latexdoc)
listaArquivos = dict() # Lista dos arquivos no manifest
spine = [] # Lista de ids no spine (poderiamos trocar por uma função que verifica quais tipos de seção geram arquivos e incluir no userdata deles).
for root, dirs, arquivos in os.walk('OEBPS/'):
for nomeArquivo in arquivos:
if (nomeArquivo == 'content.opf'):
continue
if re.match('.*~$', nomeArquivo):
continue
href = os.path.join(re.sub('OEBPS/?', '', root), nomeArquivo)
# As / são substituídas por - no id
itemid = re.sub('[/.]', '-', href)
mediaType = mimetypes.guess_type(nomeArquivo)[0]
# Os arquivos html são incluídos no spine
if re.match('.*\.html', nomeArquivo):
spine.append(itemid)
listaArquivos[itemid] = {'href': href, 'mediaType': mediaType}
latexdoc.setUserData('listaArqs', listaArquivos)
# A lista de ids será ordenada para a geração do content.opf
latexdoc.setUserData('spine', sorted(spine))
# Chamadas para geração do arquivo opf
self.doOPFFiles(latexdoc)
return res
示例15: processFileContent
def processFileContent(self, document, s):
s = _Renderer.processFileContent(self, document, s)
return s