Initial commit.

This commit is contained in:
Julien Palard 2020-12-01 15:23:52 +01:00
commit c70fae2457
4 changed files with 122 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
__pycache__/
*.egg-info/

90
md2reveal.py Normal file
View File

@ -0,0 +1,90 @@
import re
from pathlib import Path
import jinja2
import argparse
TPL = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Prez</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ revealjs_url }}/dist/reset.css">
<link rel="stylesheet" href="{{ revealjs_url }}/dist/reveal.css">
<link rel="stylesheet" href="{{ revealjs_url }}/dist/theme/simple.css" id="theme">
<link rel="stylesheet" href="{{ revealjs_url }}/plugin/highlight/monokai.css" id="highlight-theme">
</head>
<body>
<div class="reveal">
<div class="slides">
{% for section in slides %}
<section>
{% for slide in section %}
<section data-markdown>
<textarea data-template>
{{ slide }}
</textarea>
</section>
{% endfor%}
</section>
{% endfor %}
</div>
</div>
<script src="{{ revealjs_url }}/dist/reveal.js"></script>
<script src="{{ revealjs_url }}/plugin/zoom/zoom.js"></script>
<script src="{{ revealjs_url }}/plugin/notes/notes.js"></script>
<script src="{{ revealjs_url }}/plugin/search/search.js"></script>
<script src="{{ revealjs_url }}/plugin/markdown/markdown.js"></script>
<script src="{{ revealjs_url }}/plugin/highlight/highlight.js"></script>
<script>
Reveal.initialize({
controls: true,
progress: true,
center: true,
hash: true,
disableLayout: false,
plugins: [ RevealZoom, RevealNotes, RevealSearch, RevealMarkdown, RevealHighlight ]
});
</script>
</body>
</html>
"""
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()
def main():
args = parse_args()
tpl = jinja2.Template(TPL)
with open(args.md) as f:
md = f.read()
sections = []
for section in re.split("^# ", md, flags=re.M):
if not section:
continue
slides = []
for slide in re.split("^## ", section, flags=re.M):
slide = re.sub("^::: notes$", '<aside class="notes">', slide, flags=re.M)
slide = re.sub("^:::$", "</aside>", slide, flags=re.M)
slides.append("## " + slide)
sections.append(slides)
with open(args.html, "w") as f:
f.write(tpl.render(slides=sections, revealjs_url=args.revealjs_url))
if __name__ == "__main__":
main()

27
setup.cfg Normal file
View File

@ -0,0 +1,27 @@
[metadata]
name = md2reveal
version = 0.1
description = Transform a flat markdown to a reveal.js presentation.
long_description = file: README.md
long_description_content_type = text/markdown; charset=UTF-8
author = Julien Palard
author_email = julien@palard.fr
url = https://github.com/JulienPalard/md2reveal
license = MIT License
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Natural Language :: English
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
[options]
py_modules = md2reveal
python_requires = >= 3.6
install_requires = jinja2
[options.entry_points]
console_scripts = md2reveal=md2reveal:main

3
setup.py Normal file
View File

@ -0,0 +1,3 @@
import setuptools
setuptools.setup()