Download reveal autonomousely

This commit is contained in:
Julien Palard 2020-12-01 15:41:34 +01:00
parent c70fae2457
commit 7f1bb87f34
2 changed files with 22 additions and 4 deletions

View File

@ -1,8 +1,13 @@
import re
import tarfile
import io
from pathlib import Path
import jinja2
import argparse
import jinja2
import requests
TPL = """
<!DOCTYPE html>
<html lang="en">
@ -60,14 +65,25 @@ def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("md", help="Markdown input file")
parser.add_argument("html", help="HTML output file")
parser.add_argument("--revealjs-url", help="Path or URL to revealjs")
return parser.parse_args()
REVEAL_JS_VERSION = "4.1.0"
REVEAL_ARCHIVE = (
f"https://github.com/hakimel/reveal.js/archive/{REVEAL_JS_VERSION}.tar.gz"
)
def main():
args = parse_args()
tpl = jinja2.Template(TPL)
root = Path(args.html).resolve().parent
reveal_path = root / f"reveal.js-{REVEAL_JS_VERSION}"
if not reveal_path.exists():
tarball = io.BytesIO(requests.get(REVEAL_ARCHIVE).content)
tarfile.open(fileobj=tarball, mode="r:gz").extractall(root)
with open(args.md) as f:
md = f.read()
@ -83,7 +99,7 @@ def main():
sections.append(slides)
with open(args.html, "w") as f:
f.write(tpl.render(slides=sections, revealjs_url=args.revealjs_url))
f.write(tpl.render(slides=sections, revealjs_url=reveal_path))
if __name__ == "__main__":

View File

@ -21,7 +21,9 @@ classifiers =
[options]
py_modules = md2reveal
python_requires = >= 3.6
install_requires = jinja2
install_requires =
jinja2
requests
[options.entry_points]
console_scripts = md2reveal=md2reveal:main