Coverage for src/midgy/run.py: 0%

1"""run and import markdown files as python"""

2 from dataclasses import dataclass

3

4 from importnb import Notebook

5

6 from .python import Python

7

8 __all__ = ("Markdown", "run")

9

10

11@dataclass

12 class Markdown(Notebook):

13 """an importnb extension for markdown documents"""

14

15 include_doctest: bool = False

16 extensions = ".py.md", ".md", ".md.ipynb"

17 render_cls = Python

18

19 def __post_init__(self):

20 self.renderer = self.render_cls(include_doctest=self.include_doctest)

21

22 def get_data(self, path):

23 if self.path.endswith(".md"):

24 self.source = self.decode()

25 return self.code(self.source)

26 return super(Notebook, self).get_data(path)

27

28 def code(self, str):

29 return super().code(self.renderer.render("".join(str)))

30

31 get_source = get_data

32

33

34 if __name__ == "__main__":

35 from sys import argv

36

37 Markdown.load_argv(argv[1:])