feat: stopped using markdown

This commit is contained in:
Hazel 2024-04-09 12:21:03 +02:00
parent f25febf297
commit 21a0adfa50
2 changed files with 18 additions and 58 deletions

View File

@ -1,60 +1,18 @@
import pandoc
import mistune
import html2markdown
"""
TODO
implement in setup.py a skript to install pandocs
https://pandoc.org/installing.html
!!!!!!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!!!
"""
class FormattedText:
"""
the self.html value should be saved to the database
"""
doc = None
class FormattedText:
html = ""
def __init__(
self,
plaintext: str = None,
markdown: str = None,
html: str = None
) -> None:
self.set_plaintext(plaintext)
self.set_markdown(markdown)
self.set_html(html)
def set_plaintext(self, plaintext: str):
if plaintext is None:
return
self.doc = pandoc.read(plaintext)
def set_markdown(self, markdown: str):
if markdown is None:
return
self.doc = pandoc.read(markdown, format="markdown")
def set_html(self, html: str):
if html is None:
return
self.doc = pandoc.read(html, format="html")
def get_markdown(self) -> str:
if self.doc is None:
return ""
return pandoc.write(self.doc, format="markdown").strip()
def get_html(self) -> str:
if self.doc is None:
return ""
return pandoc.write(self.doc, format="html").strip()
def get_plaintext(self) -> str:
if self.doc is None:
return ""
return pandoc.write(self.doc, format="plain").strip()
if html is not None:
self.html = html
elif markdown is not None:
self.html = mistune.markdown(markdown)
@property
def is_empty(self) -> bool:
@ -67,12 +25,13 @@ class FormattedText:
return True
return self.doc == other.doc
@property
def markdown(self) -> str:
return html2markdown.convert(self.html)
def __str__(self) -> str:
return self.plaintext
return self.markdown
plaintext = property(fget=get_plaintext, fset=set_plaintext)
markdown = property(fget=get_markdown, fset=set_markdown)
html = property(fget=get_html, fset=set_html)
plaintext = markdown

View File

@ -44,8 +44,9 @@ dependencies = [
"ffmpeg-python~=0.2.0",
"ffmpeg-progress-yield~=0.7.8",
"mutagen~=1.46.0",
"pandoc~=2.3",
"mistune~=3.0.2",
"md-to-html~=0.7.3",
"jellyfish~=0.9.0",
"transliterate~=1.10.2",
"pycountry~=24.0.1",