Last active
May 11, 2016 18:22
-
-
Save tbnorth/2e263e173438d431e46614347fbd55b3 to your computer and use it in GitHub Desktop.
reveal.js HTML slides markdown importer for Leo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reveal.js markdown uses two blank lines to separate stacked slides | |
# and three to separate side by side slides. This snippet reads | |
# such markdown into the appropriate tree layout in the Leo | |
# editor (http://leoeditor.com/) | |
lines = p.b.strip().split('\n') | |
while lines[0][0] == '@': | |
del lines[0] | |
nd = p.insertAfter() | |
nd.h = "@clean %s" % p.h.split(None, 1)[1] | |
nd.b = "@others" | |
top = nd.copy() | |
blanks = -1 | |
for line in lines: | |
line = line.rstrip() | |
if not line: | |
blanks += 1 | |
continue | |
if blanks == 1: | |
nd.b += '\n' | |
if blanks in (2, -1): | |
if nd == top: | |
nd = top.insertAsLastChild() | |
else: | |
nd = nd.insertAfter() | |
if blanks == -1: # first time exception | |
top = nd.copy() | |
nd.h = line.split(None, 1)[1] | |
if blanks == 3: | |
nd = top.insertAfter() | |
top = nd.copy() | |
nd.h = line.split(None, 1)[1] | |
blanks = 0 | |
nd.b += "%s\n" % line | |
c.redraw() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this does the opposite of read_reveal_md.py, adding two or three | |
# blanks at the end of nodes to reflect slide layout from reveal.js's | |
# point of view | |
while not p.h[:5] in ('@edit', '@clea') and p.parent(): | |
p = p.parent() | |
for nd in p.children_iter(): | |
if nd.hasChildren(): | |
nd.b = nd.b.strip()+'\n\n\n' | |
for child in nd.children(): | |
child.b = child.b.strip()+'\n\n\n' | |
child = nd.lastChild() | |
child.b = child.b.strip()+'\n\n\n\n' | |
else: | |
nd.b = nd.b.strip()+'\n\n\n\n' | |
nd = p.lastChild() | |
nd.b = nd.b.strip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment