Spaces:
Running
Running
File size: 2,098 Bytes
9150552 3456a58 9150552 3456a58 9150552 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import utils.markdown as md
class marp:
def __init__(self, path):
self.path = path
self.f = open(path, "w")
self.f.truncate(0) # clear the file
def marp_write(self, text):
self.f.write(text)
def add_header(
self,
theme: str = "default",
_class: str = "lead",
paginate: bool = True,
background: str = "",
backgroundImage: str = None,
extra_styles: str = None,
config: dict = None
):
## write the header
# ---
# theme: gaia
# _class: lead
# paginate: true
# backgroundColor: #fff
# backgroundImage: url('https://marp.app/assets/hero-background.svg')
# ---
if config is not None:
theme = config["theme"]
background = config["background"]
_class = config["class"]
self.marp_write("---\n")
self.marp_write("marp: true\n")
self.marp_write(f"theme: {theme}\n")
self.marp_write(f"class: {_class}\n")
if paginate:
self.marp_write(f"paginate: true\n")
else:
self.marp_write(f"paginate: false\n")
self.marp_write(f"backgroundColor: {background}\n")
self.writeifNotNone(backgroundImage)
self.marp_end()
self.writeifNotNone(extra_styles) # for extra css styles
def writeifNotNone(self, var):
if var is not None:
self.marp_write(var)
def add_page(self,
title=None,
body=None,
directives: str = None
):
self.writeifNotNone(f"<!-- {directives} -->\n")
self.writeifNotNone(title)
self.writeifNotNone(body)
def add_directives(self, directives: str):
self.marp_write(f"<!-- {directives} -->\n")
def add_body(self, body: str):
self.marp_write(body)
def marp_end(self):
self.marp_write("\n\n---\n\n") # page end
def close_file(self):
self.f.close() # close the file and flush the buffer
|