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)
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)
def render(self, document): # create the tags and labels dictionaries in the document loadTags(document) copyBibliographies(document) # validity check checkLabels(document) # we decorate all DOM elements with labels that appear in the tags file decorateTags(document, document.userdata["labels"]) # create a linearised version of the document containing theorems and proofs in order linearRepresentation(document) tagAttendanceSheet = tagRollCall(document) for tag in filter(lambda t: not tagAttendanceSheet[t], tagAttendanceSheet): log.warning("document does not contain tag %s" % tag) # associate parts to chapters parts = partsList(document) with open("parts.json", "w") as f: json.dump(parts, f) _Renderer.render(self, document) # write footnotes if there are any if "footnotes" in document.userdata: mixin(Node, Gerby.renderableClass) Node.renderer = self for footnote in document.userdata["footnotes"]: with open("{0}.footnote".format(footnote.id), "w") as f: f.write(str(footnote)) del Node.renderer unmix(Node, Gerby.renderableClass) # write meta information, like line count. with open("meta.statistics", "w") as f: json.dump(document.context.meta, f)