music-kraken-core/music_kraken/objects/formatted_text.py

38 lines
808 B
Python
Raw Normal View History

2024-04-09 10:21:03 +00:00
import mistune
import html2markdown
2023-02-03 14:21:59 +00:00
2024-04-09 10:21:03 +00:00
class FormattedText:
html = ""
2023-02-03 14:21:59 +00:00
def __init__(
self,
markdown: str = None,
html: str = None
) -> None:
2024-04-09 10:21:03 +00:00
if html is not None:
self.html = html
elif markdown is not None:
self.html = mistune.markdown(markdown)
2023-03-13 13:28:28 +00:00
@property
def is_empty(self) -> bool:
return self.doc is None
def __eq__(self, other) -> False:
if type(other) != type(self):
return False
if self.is_empty and other.is_empty:
return True
return self.doc == other.doc
2024-04-09 10:21:03 +00:00
@property
def markdown(self) -> str:
return html2markdown.convert(self.html)
2024-04-09 10:21:03 +00:00
def __str__(self) -> str:
return self.markdown
2024-04-09 10:21:03 +00:00
plaintext = markdown