Initial commit

This commit is contained in:
Folkert Kevelam 2025-08-18 23:03:11 +02:00
parent 3b57f9457a
commit 0eaacc1a3e

127
Server/pandoc.py Normal file
View File

@ -0,0 +1,127 @@
import subprocess
import json
from pathlib import Path
class Pandoc:
def __init__(self, path=None):
if path:
self.pandoc = path + "/pandoc"
else:
self.pandoc = "pandoc"
def Command(self, From, To, Input):
return subprocess.run(
[self.pandoc, "-f", From, "-t", To],
input=Input,
text=True,
capture_output=True)
def Convert(self, text):
command = self.Command("gfm", "html", text)
return command.stdout
def ConvertToJson(self, text):
command = self.Command("gfm", "json", text)
return json.loads(command.stdout)
def ConvertFromJson(self, text):
command = self.Command("json", "html", json.dumps(text));
return command.stdout
class Attr:
def __init__(self, id, classes=None, keyvalue=None):
self.id = id
if classes is None:
self.classes = []
else:
self.classes = classes
if keyvalue is None:
self.keyvalue = []
else:
self.keyvalue = keyvalue
def toJson(self):
return [
self.id,
self.classes,
self.keyvalue
]
class Div:
def __init__(self, attr, content):
self.attr = attr
self.content = content
def toJson(self):
return {
't' : 'Div',
'c' : [
self.attr.toJson(),
self.content
]
}
class Span:
def __init__(self, attr, content):
self.attr = attr
self.content = content
def toJson(self):
return {
't' : 'Span',
'c' : [
self.attr.toJson(),
self.content
]
}
class Header:
def __init__(self, attr, num, content):
self.attr = attr
self.num = num
self.content = content
def toJson(self):
return {
't' : 'Header',
'c' : [
self.num,
self.attr.toJson(),
self.content
]
}
class Plain:
def __init__(self, content):
self.content = content
def toJson(self):
return {
't' : 'Plain',
'c' : [
self.content
]
}
class Inline:
def __init__(self, t, content):
self.t = t
self.content = content
def toJson(self):
return {
't' : self.t,
'c' : self.content
}
class PString:
def __init__(self, content):
self.content = content
def toJson(self):
return {
't' : 'Str',
'c' : self.content
}