def _render_report(self, file, output=None): """ Parse report document using pweave. Args: file: Path of the file to be parsed. Return: Output file path """ if output is None: report = self._reports.get(file) if report is not None: output = report.render_dir if output is None: name = osp.splitext(osp.basename(file))[0] id_ = to_text_string(uuid.uuid4()) output = osp.join(REPORTS_TEMPDIR, id_, '{}.html'.format(name)) self._reports[file].render_dir = output folder = osp.split(output)[0] self.check_create_tmp_dir(folder) doc = Pweb(file, output=output) # TODO Add more formats support if doc.file_ext == '.mdw': _format = 'md2html' elif doc.file_ext == '.md': _format = 'pandoc2html' else: raise Exception("Format not supported ({})".format(doc.file_ext)) f = CaptureStdOutput(self.sig_render_progress) if pweave_version.startswith('0.3'): with redirect_stdout(f): self.sig_render_progress.emit("Readign") doc.read() self.sig_render_progress.emit("Running") doc.run() self.sig_render_progress.emit("Formating") doc.format(doctype=_format) self.sig_render_progress.emit("Writing") doc.write() return doc.sink else: with redirect_stdout(f): doc.setformat(_format) doc.detect_reader() doc.parse() doc.run() doc.format() doc.write() return doc.sink
super(Formatter, self).__init__(*args, **kwargs) self.formatdict.update({ 'codestart': '~~~%s', 'codeend': '~~~\n{:.text-document title="{{ site.handouts }}"}\n\n', 'termstart': '~~~%s', 'termend': '~~~\n{:.output}\n\n', }) return def make_figure_string(self, *args, **kwargs): f_str = super(Formatter, self).make_figure_string(*args, **kwargs) f_str = f_str.replace('..', '{{ site.baseurl }}') f_str = f_str[:f_str.find('{#')] return f_str with open('docs/_config.yml') as f: config = yaml.load(f) for fname in config['slide_sorter']: doc = Pweb( file='docs/_slides_pmd/{}.pmd'.format(fname), output='docs/_slides/{}.md'.format(fname), figdir='../images', ) doc.setreader('markdown') doc.setformat(Formatter=Formatter) # doc.weave(shell='ipython') ## See https://github.com/mpastell/Pweave/issues/59 doc.weave()
def render_report(self, file): """ Parse report document using pweave. Args: file: Path of the file to be parsed. Return: Output file path """ doc = Pweb(file) # TODO Add more formats support if doc.file_ext == '.mdw': doc.setformat('md2html', theme="skeleton") elif doc.file_ext == '.md': doc.setformat('pandoc2html') else: print("Format not supported ({})".format(doc.file_ext)) return doc.detect_reader() doc.parse() doc.run(shell="ipython") doc.format() doc.write() return doc.sink
def __init__(self, *args, **kwargs): super(Formatter, self).__init__(*args, **kwargs) self.formatdict.update({ 'codestart': '~~~%s', 'codeend': '~~~\n{:.text-document title="{{ site.handouts }}"}\n\n', 'termstart': '~~~%s', 'termend': '~~~\n{:.output}\n\n', }) return def make_figure_string(self, *args, **kwargs): f_str = super(Formatter, self).make_figure_string(*args, **kwargs) f_str = f_str.replace('..', '{{ site.baseurl }}') f_str = f_str[:f_str.find('{#')] return f_str with open('docs/_config.yml') as f: config = yaml.load(f) for fname in config['slide_sorter']: doc = Pweb( file='docs/_slides_pmd/{}.pmd'.format(fname), output='docs/_slides/{}.md'.format(fname), figdir='../images', ) doc.setreader('markdown') doc.setformat(Formatter=Formatter) # doc.weave(shell='ipython') ## See https://github.com/mpastell/Pweave/issues/59 doc.weave()
def render_report(self, file): """ Parse report document using pweave. Args: file: Path of the file to be parsed. Return: Output file path """ doc = Pweb(file) # TODO Add more formats support if doc.file_ext == '.mdw': _format = 'md2html' elif doc.file_ext == '.md': _format = 'pandoc2html' else: print("Format not supported ({})".format(doc.file_ext)) return if pweave_version.startswith('0.3'): doc.read() doc.run() doc.format(doctype=_format) doc.write() return doc.sink else: doc.setformat(_format) doc.detect_reader() doc.parse() doc.run(shell="ipython") doc.format() doc.write() return doc.sink
fname = chunk_dir + "{}_{}.tex".format(source, chunk['number']) with open(fname, "w") as f: if chunk['term']: f.write(chunk['result']) chunk['result'] = r"\lstinputlisting{" + fname + "}" else: f.write(chunk['content']) f.write(chunk['result']) chunk['content'] = r"\lstinputlisting{" + fname + "}" chunk['result'] = "\n\n" return (chunk) for fname in filenames: doc = Pweb(tex_dir + fname + r".tex", format="texpweave", output=chunk_dir + fname + r".tx") doc.setformat(Formatter=ToFile) doc.updateformat({ "outputstart": "\n", "outputend": "\n", "codestart": "\n", "codeend": "\n", "termstart": "\n", "termend": "\n", }) # doc.updateformat({ # "outputstart": r"\begin{lstlisting}", # "outputend": r"\end{lstlisting}", # "codestart": r"\begin{lstlisting}", # "codeend": r"\end{lstlisting}",
f_str = super(Formatter, self).make_figure_string(*args, **kwargs) f_str = f_str.replace('..', '{{ site.baseurl }}') f_str = f_str[:f_str.find('\\')] f_str = f_str.replace( '[]', '[plot of {}]'.format(args[0])) return f_str def preformat_chunk(self, chunk): if chunk['type'] == 'code': if 'title' in chunk: codeend = '~~~\n{{:.text-document title="{}"}}\n\n' chunk['codeend'] = codeend.format(chunk['title']) chunk['result'] = self.out.sub('\n', chunk['result']) return chunk with open('docs/_config.yml') as f: config = yaml.load(f) for fname in config['slide_sorter']: doc = Pweb( file = 'docs/_slides_pmd/{}.md'.format(fname), output = 'docs/_slides/{}.md'.format(fname), figdir = '../images', ) doc.setreader('markdown') doc.setformat(Formatter=Formatter) doc.weave(shell='ipython') ## See https://github.com/mpastell/Pweave/issues/59 # doc.weave()
if chunk['term']: f.write(chunk['result']) chunk['result'] = r"\lstinputlisting{"+fname+"}" else: f.write(chunk['content']) f.write(chunk['result']) chunk['content'] = r"\lstinputlisting{"+fname+"}" chunk['result'] = "\n\n" print(chunk) return(chunk) for fname in filenames: #doc = Pweb(tex_dir + fname+r".tex", format="texpweave", doc = Pweb(tex_dir + fname+r".tex", informat="noweb", doctype="tex", output=chunk_dir+fname+r".tx") # doc.setformat(Formatter=ToFile) # doc.updateformat({ # "outputstart": "\n", # "outputend": "\n", # "codestart": "\n", # "codeend": "\n", # "termstart": "\n", # "termend": "\n", # } # ) doc.updateformat({ "outputstart": r"\begin{lstlisting}", "outputend": r"\end{lstlisting}",
def make_figure_string(self, *args, **kwargs): f_str = super(Formatter, self).make_figure_string(*args, **kwargs) f_str = f_str.replace('..', '{{ site.baseurl }}') f_str = f_str[:f_str.find('\\')] f_str = f_str.replace('[]', '[plot of {}]'.format(args[0])) return f_str def preformat_chunk(self, chunk): if chunk['type'] == 'code': if 'title' in chunk: codeend = '~~~\n{{:.text-document title="{}"}}\n\n' chunk['codeend'] = codeend.format(chunk['title']) return chunk with open('docs/_config.yml') as f: config = yaml.load(f) for fname in config['slide_sorter']: doc = Pweb( file='docs/_slides_pmd/{}.md'.format(fname), output='docs/_slides/{}.md'.format(fname), figdir='../images', ) doc.setreader('markdown') doc.setformat(Formatter=Formatter) doc.weave( shell='ipython') ## See https://github.com/mpastell/Pweave/issues/59 # doc.weave()