Skip to content

Commit

Permalink
Merge pull request #34 from vinayak-mehta/fix-27
Browse files Browse the repository at this point in the history
[MRG] Use warnings and add italic support
  • Loading branch information
vinayak-mehta authored Aug 29, 2020
2 parents d45bc2f + 7d7c588 commit acf9818
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
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

0 comments on commit acf9818

Please sign in to comment.