-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy pathrender.py
More file actions
40 lines (28 loc) · 1.03 KB
/
render.py
File metadata and controls
40 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import pydocx.export
from mako.lookup import TemplateLookup
from mfr.core import extension
class DocxRenderer(extension.BaseRenderer):
TEMPLATE = TemplateLookup(
directories=[
os.path.join(os.path.dirname(__file__), 'templates')
]).get_template('viewer.mako')
# Workaround to remove default stylesheet and inlined styles
# see: https://github.com/CenterForOpenScience/pydocx/issues/102
class _PyDocXHTMLExporter(pydocx.export.PyDocXHTMLExporter):
def style(self):
return ''
def indent(self, text, *args, **kwargs):
return text
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.metrics.add('pydocx_version', pydocx.__version__)
def render(self):
body = self._PyDocXHTMLExporter(self.file_path).parsed
return self.TEMPLATE.render(base=self.assets_url, body=body)
@property
def file_required(self):
return True
@property
def cache_result(self):
return True