diff --git a/music_kraken/objects/formatted_text.py b/music_kraken/objects/formatted_text.py index 20927a3..7a828fe 100644 --- a/music_kraken/objects/formatted_text.py +++ b/music_kraken/objects/formatted_text.py @@ -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 + diff --git a/pyproject.toml b/pyproject.toml index 88f01ec..db7b228 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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",