def text_repr_to_docs(self, text_repr): text = ast.literal_eval(text_repr) if not isinstance(text, str): raise TypeError("{0!r} is not a string".format(text)) json_doc = to_json(text) doc = pandoc.read(json_doc) return doc, json_doc
def add_latex_header(doc, latex_src): new_blocks = None if isinstance(latex_src, list): # list of blocks new_blocks = latex_src else: new_blocks = pandoc.read(latex_src)[1] meta, blocks = doc[:] metamap = meta[0] blocks = metamap.setdefault("header-includes", MetaBlocks([]))[0] blocks.extend(new_blocks)
def round_trip_check(self, json_doc): json_doc_2 = None try: doc = pandoc.read(json_doc) json_doc_2 = pandoc.write(doc) except Exception as error: jsond_doc_2 = error if json_doc == json_doc_2 : return True else: return json_doc, json_doc_2
def insert_authors(doc): content = "STEP, MINES ParisTech[^1]\n\n" content += \ r"""[^1]: Ce document est un des produits du projet [$\mbox{\faGithub}$ `boisgera/CDIS`](https://github.com/), initié par la collaboration de [(S)ébastien Boisgérault](mailto:[email protected]) (CAOR), [(T)homas Romary](mailto:[email protected]) et [(E)milie Chautru](mailto:[email protected]) (GEOSCIENCES), [(P)auline Bernard](mailto:[email protected]) (CAS), avec la contribution de [Gabriel Stoltz](mailto:[email protected]) (Ecole des Ponts ParisTech, CERMICS). Il est mis à disposition selon les termes de [la licence Creative Commons "attribution -- pas d’utilisation commerciale -- partage dans les mêmes conditions" 4.0 internationale](http://creativecommons.org/licenses/by-nc-sa/). """ content_inlines = pandoc.read(content)[1][0][0] metamap = doc[0][0] metamap["author"] = MetaList([MetaInlines(content_inlines)])
return transform def to_html(item): if isinstance(item, pandoc.Div): pass else: return item def to_latex(item): if isinstance(item, pandoc.Div): pass else: return item if __name__ == "__main__": input = sys.stdin.read() args = sys.argv if "--latex" in args: f = theorem("latex") elif "--html" in args: f = theorem("html") else: raise ValueError("unspecified mode (--latex or --html)") doc = pandoc.read(input) print pandoc.to_json(pandoc.fold(f, doc))
TEX_options = options.copy() PDF_options = options.copy() # To use package titlesec, see <https://stackoverflow.com/questions/42916124/not-able-to-use-titlesec-with-markdown-and-pandoc> # Update: titlesec is off limit anyway with pandoc, # as it is not compatible with hyperref # PDF_options += ["--variable", "subparagraph"] PDF_PRINT_options = PDF_options.copy() PDF_PRINT_options += ["-Vpapersize=a4", "-Vclassoption=twoside"] ODT_options = options.copy() HTML_options = options.copy() HTML_options += ["--mathjax"] # PDF Output doc = pandoc.read(file=doc_md) doc = transform(doc) # Code and Doctest code = generate_code(doc) if code is not None: #print("code:\n\n", code) with open(doc_py, "w") as py_file: py_file.write(code) python("-m", "doctest", doc_py) try: shutil.rmtree(output / "__pycache__") # otherwise, top build has issues. except: pass
'slides' won't appear in the notebook, but in the slides, and it's also executed 'notebook' is not executed and appears only in the notebook. - exec status: no-exec or no flag (exec by default in slides mode only) NOTA: no-exec never used so far in the slides. """ # Source Document # ------------------------------------------------------------------------------ doc_file = sys.argv[1] doc_name = os.path.splitext(doc_file)[0] doc = pandoc.read(file=doc_file) # TODO: add python writer support in pandoc, add proper pdf quirk mangt # pandoc.write(doc, file="doc.py", format="python") # debug # Code Execution # ------------------------------------------------------------------------------ def make_code_doc(doc): doc = copy.deepcopy(doc) # the transformation is actually in-place, # but the user of this function should not worry about that. root = doc[1] # top-level blocks # print(root)
from ics import * import pandoc # ------------------------------------------------------------------------------ url = "https://calendar.google.com/calendar/ical/o1rahvtc75kj2qcc5tmsrfr6e0%40group.calendar.google.com/public/basic.ics" calendar = Calendar(urlopen(url).read().decode("utf-8")) # assert len(calendar.events) == 60 # relax this; we have more slots with the exam of EC2 now. events = list(calendar.events) events.sort() for i, event in enumerate(events): print(f"{i+1:2d}) {event.name}") assert event.begin.date() == event.end.date() #assert event.duration.seconds == 1.5 * 3600 begin = event.begin.to("Europe/Paris") end = event.end.to("Europe/Paris") print(" " + begin.format("dddd DD MMMM YYYY", locale="fr_FR"), end=", ") print(begin.format("HH:mm") + "-" + end.format("HH:mm") + ".") description = event.description if event.description: doc = pandoc.read(event.description, format="html") print(pandoc.write(doc, format="markdown")) #description = "\n".join([" " + line for line in description.splitlines()]) #description = " " + description.strip() #print(description) print()
def to_html(item): if isinstance(item, pandoc.Div): pass else: return item def to_latex(item): if isinstance(item, pandoc.Div): pass else: return item if __name__ == "__main__": input = sys.stdin.read() args = sys.argv if "--latex" in args: f = theorem("latex") elif "--html" in args: f = theorem("html") else: raise ValueError("unspecified mode (--latex or --html)") doc = pandoc.read(input) print pandoc.to_json(pandoc.fold(f, doc))
"Remove everything before the first real paragraph" blocks = doc[1] for i, block in enumerate(blocks): if isinstance(block, Para): para = block inlines = para[0] if len(inlines) > 0 and isinstance(inlines[0], Str): break doc[1] = blocks[i:] return doc # Simplify # ------------------------------------------------------------------------------ def simplify(doc): doc = unpack_divs(doc) # doc = unpack_divs_2(doc) doc = remove_preamble(doc) return doc # Entry Point # ------------------------------------------------------------------------------ if __name__ == "__main__": url = 'https://pandoc.org/getting-started.html' src = urllib.request.urlopen(url).read() doc = pandoc.read(src, format="html") doc = simplify(doc) print(pandoc.write(doc, format="markdown", options=["-s"]))