Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Use warnings and add italic support #34

Merged
merged 1 commit into from
Aug 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions present/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"white": Screen.COLOUR_WHITE,
}
ATTRS = {
"italic": 5,
"bold": Screen.A_BOLD,
"underline": Screen.A_UNDERLINE,
}
Expand Down
19 changes: 16 additions & 3 deletions present/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import sys
import shutil
import warnings
from dataclasses import dataclass

import yaml
Expand All @@ -13,6 +14,10 @@
from .effects import EFFECTS, COLORMAP


# For future reference
UNSUPPORTED_ELEMENTS = ["block_quote", "codespan", "link", "emphasis", "strong"]


@dataclass
class Heading(object):
type: str = "heading"
Expand Down Expand Up @@ -310,27 +315,35 @@ def parse(self, text):
buffer = []
continue

if obj["type"] == "paragraph":
if obj["type"] == "block_quote":
warnings.warn(
f"(Slide {sliden + 1}) BlockQuote is not supported"
)
elif obj["type"] == "paragraph":
for child in obj["children"]:
try:
if child["type"] == "image" and child["alt"] == "codio":
with open(child["src"], "r") as f:
codio = yaml.load(f, Loader=yaml.Loader)
buffer.append(Codio(obj=codio))
elif child["type"] == "codespan":
pass
elif child["type"] == "link":
pass
else:
element_name = child["type"].title().replace("_", "")
Element = eval(element_name)
buffer.append(Element(obj=child))
except NameError:
raise ValueError(
warnings.warn(
f"(Slide {sliden + 1}) {element_name} is not supported"
)
else:
try:
element_name = obj["type"].title().replace("_", "")
Element = eval(element_name)
except NameError:
raise ValueError(
warnings.warn(
f"(Slide {sliden + 1}) {element_name} is not supported"
)
buffer.append(Element(obj=obj))
Expand Down
10 changes: 9 additions & 1 deletion present/slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from asciimatics.scene import Scene
from asciimatics.effects import Print
from asciimatics.screen import Screen
from asciimatics.event import KeyboardEvent
from asciimatics.screen import Screen, _CursesScreen
from asciimatics.exceptions import ResizeScreenError, StopApplication

from .effects import (
Expand Down Expand Up @@ -88,6 +88,14 @@ def __init__(self, slides):

def __enter__(self):
self.screen = Screen.open()

if isinstance(self.screen, _CursesScreen):
import curses

self.screen.A_ITALIC = 5
self.screen._a_italic = curses.tigetstr("sitm").decode("utf-8")
self.screen._ATTRIBUTES[self.screen.A_ITALIC] = self.screen._a_italic

return self

def __exit__(self, type, value, traceback):
Expand Down