Exemplo n.º 1
0
def test_parse_metadata():
    """Test that metadata can be correctly parsed out of a markdown
    presentation
    """
    title = "Presentation Title"
    date = "9999-01-01"
    author = "The Author"

    input_data = f"""
---
title: {title}
date: {date}
author: {author}
---
remaining
    """

    parser = Parser()
    input_data, meta = parser.parse_meta(input_data)
    assert input_data.strip() == "remaining"
    assert meta["title"] == title
    assert meta["date"].year == 9999
    assert meta["date"].month == 1
    assert meta["date"].day == 1
    assert meta["author"] == author
Exemplo n.º 2
0
def test_parse_smart_slides_one_h1():
    """Test that slide smart splitting works correctly
    """
    input_data = r"""
# Heading Title

## Heading 2

some text

## Heading 3

more text

## Heading 4

### Sub heading

#### Sub Heading
    """
    parser = Parser()
    meta = {"title": ""}
    _, slides = parser.parse_slides(meta, input_data)
    assert len(slides) == 4
    assert meta["title"] == "Heading Title"
Exemplo n.º 3
0
def test_parse_slides():
    """Test that slide parsing works correctly
    """
    input_data = r"""
# Slide 1

* list
  * item
  * item
  * item

Hello there this is a paragraph

```python
code block
```

---

# Slide 2

More text
    """
    parser = Parser()
    slides = parser.parse_slides({}, input_data)
    assert len(slides) == 2
Exemplo n.º 4
0
def render_markdown(markdown, height=50, width=200, single_slide=False):
    """Returns the rendered canvas contents of the markdown
    """
    loop = urwid.MainLoop(urwid.ListBox([]))
    renderer = lookatme.tui.SlideRenderer(loop)
    renderer.start()

    parser = Parser(single_slide=single_slide)
    _, slides = parser.parse_slides({"title": ""}, markdown)

    renderer.stop()
    contents = renderer.render_slide(slides[0], force=True)
    renderer.join()

    container = urwid.ListBox([urwid.Text("testing")])
    container.body = contents
    return list(container.render((width, height)).content())
Exemplo n.º 5
0
def render_markdown(markdown, height=50):
    """Returns the rendered canvas contents of the markdown
    """
    loop = urwid.MainLoop(urwid.Pile([]))
    renderer = lookatme.tui.SlideRenderer(loop)
    renderer.start()

    parser = Parser()
    _, slides = parser.parse_slides({"title": ""}, markdown)

    renderer.stop()
    pile_contents = renderer.render_slide(slides[0], force=True)
    renderer.join()

    pile = urwid.Pile([urwid.Text("testing")])
    pile.contents = pile_contents
    return list(pile.render((height, )).content())
Exemplo n.º 6
0
def test_parse_metadata_empty():
    """Test that metadata can be correctly parsed out of a markdown
    presentation
    """
    input_data = f"""
---
---
remaining
    """

    parser = Parser()
    input_data, meta = parser.parse_meta(input_data)
    assert input_data.strip() == "remaining"
    now = datetime.datetime.now()
    assert meta["title"] == ""
    assert meta["date"].year == now.year
    assert meta["date"].month == now.month
    assert meta["date"].day == now.day
    assert meta["author"] == ""
Exemplo n.º 7
0
    def reload(self, data=None):
        """Reload this presentation

        :param str data: The data to render for this slide deck (optional)
        """
        if data is None:
            with open(self.input_filename, "r") as f:
                data = f.read()

        parser = Parser()
        self.meta, self.slides = parser.parse(data)
        lookatme.contrib.load_contribs(self.meta.get("extensions", []))

        self.styles = lookatme.themes.ensure_defaults(self.theme_mod)
        dict_deep_update(self.styles, self.meta.get("styles", {}))

        # now apply any command-line style overrides
        if self.style_override is not None:
            self.styles["style"] = self.style_override

        lookatme.config.STYLE = self.styles
Exemplo n.º 8
0
    def reload(self, data=None):
        """Reload this presentation

        :param str data: The data to render for this slide deck (optional)
        """
        if data is None:
            with open(self.input_filename, "r") as f:
                data = f.read()

        parser = Parser(single_slide=self.single_slide)
        self.meta, self.slides = parser.parse(data)

        # only load extensions once! Live editing does not support
        # auto-extension reloading
        if not self.initial_load_complete:
            safe_exts = set(self.preload_extensions)
            new_exts = set()
            # only load if running with safe=False
            if not self.safe:
                source_exts = set(self.meta.get("extensions", []))
                new_exts = source_exts - safe_exts
                self.warn_exts(new_exts)

            all_exts = safe_exts | new_exts

            lookatme.contrib.load_contribs(
                all_exts,
                safe_exts,
                self.ignore_ext_failure,
            )

        self.styles = lookatme.themes.ensure_defaults(self.theme_mod)
        dict_deep_update(self.styles, self.meta.get("styles", {}))

        # now apply any command-line style overrides
        if self.style_override is not None:
            self.styles["style"] = self.style_override

        lookatme.config.STYLE = self.styles
        self.initial_load_complete = True