-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from apiad/develop
v0.3.0
- Loading branch information
Showing
7 changed files
with
195 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# coding: utf8 | ||
|
||
from auditorium import Show | ||
|
||
|
||
class MarkdownLoader: | ||
def __init__(self, path, instance_name='show'): | ||
self.path = path | ||
self.instance_name = instance_name | ||
|
||
def parse(self): | ||
slides = [] | ||
current_slide = [] | ||
|
||
with open(self.path) as fp: | ||
for line in fp: | ||
line = line.strip("\n") | ||
|
||
if line.startswith("## ") and current_slide: | ||
slides.append(current_slide) | ||
current_slide = [] | ||
|
||
current_slide.append(line) | ||
|
||
if current_slide: | ||
slides.append(current_slide) | ||
|
||
show = Show() | ||
|
||
for i, slide in enumerate(slides): | ||
show.slide(func=MarkdownSlide(show, slide), id='slide-%i' % (i+1)) | ||
|
||
return show | ||
|
||
|
||
class MarkdownSlide: | ||
def __init__(self, show: Show, content): | ||
self.show = show | ||
self.content = [] | ||
|
||
state = 'markdown' # or 'code' | ||
split = [] | ||
|
||
for line in content: | ||
if state == 'markdown': | ||
if line.startswith('```python'): | ||
if split: | ||
self.content.append(MarkdownContent(split)) | ||
|
||
split = [] | ||
state = 'code' | ||
else: | ||
split.append(line) | ||
|
||
elif state == 'code': | ||
if line.startswith('```'): | ||
if split: | ||
self.content.append(PythonContent(split)) | ||
|
||
split = [] | ||
state = 'markdown' | ||
else: | ||
split.append(line) | ||
|
||
if split: | ||
if state == 'markdown': | ||
self.content.append(MarkdownContent(split)) | ||
else: | ||
raise ValueError("Didn't closed a Python line...") | ||
|
||
def __call__(self): | ||
for content in self.content: | ||
content(self.show) | ||
|
||
|
||
class MarkdownContent: | ||
def __init__(self, lines): | ||
self.lines = "\n".join(lines) | ||
|
||
def __call__(self, show): | ||
show.markdown(self.lines) | ||
|
||
|
||
class PythonContent: | ||
def __init__(self, lines): | ||
self.lines = "\n".join(lines) | ||
|
||
def __call__(self, show): | ||
exec(self.lines, dict(show=show), dict()) |
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Auditorium | ||
|
||
### A demo for the "pure markdown" mode | ||
|
||
## Static content | ||
|
||
Static content can be added with pure markdown. | ||
|
||
* Some _markdown_ content. | ||
* More **markdown** content. | ||
|
||
## And some Python | ||
|
||
If you need interaction or advanced `auditorium` features, | ||
simply add a code section. | ||
|
||
```python | ||
with show.columns(2) as cl: | ||
text = show.text_input("World") | ||
|
||
cl.tab() | ||
|
||
with show.success("Message"): | ||
show.markdown(f"Hello {text}") | ||
``` | ||
|
||
An instance named `show` will be magically available. |
This file contains 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 file contains 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