feat: stopped using markdown
This commit is contained in:
parent
f25febf297
commit
21a0adfa50
@ -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:
|
class FormattedText:
|
||||||
"""
|
html = ""
|
||||||
the self.html value should be saved to the database
|
|
||||||
"""
|
|
||||||
|
|
||||||
doc = None
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
plaintext: str = None,
|
|
||||||
markdown: str = None,
|
markdown: str = None,
|
||||||
html: str = None
|
html: str = None
|
||||||
) -> None:
|
) -> None:
|
||||||
self.set_plaintext(plaintext)
|
if html is not None:
|
||||||
self.set_markdown(markdown)
|
self.html = html
|
||||||
self.set_html(html)
|
elif markdown is not None:
|
||||||
|
self.html = mistune.markdown(markdown)
|
||||||
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()
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_empty(self) -> bool:
|
def is_empty(self) -> bool:
|
||||||
@ -68,11 +26,12 @@ class FormattedText:
|
|||||||
|
|
||||||
return self.doc == other.doc
|
return self.doc == other.doc
|
||||||
|
|
||||||
|
@property
|
||||||
|
def markdown(self) -> str:
|
||||||
|
return html2markdown.convert(self.html)
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.plaintext
|
return self.markdown
|
||||||
|
|
||||||
|
plaintext = 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)
|
|
||||||
|
@ -44,8 +44,9 @@ dependencies = [
|
|||||||
"ffmpeg-python~=0.2.0",
|
"ffmpeg-python~=0.2.0",
|
||||||
"ffmpeg-progress-yield~=0.7.8",
|
"ffmpeg-progress-yield~=0.7.8",
|
||||||
"mutagen~=1.46.0",
|
"mutagen~=1.46.0",
|
||||||
"pandoc~=2.3",
|
|
||||||
|
|
||||||
|
"mistune~=3.0.2",
|
||||||
|
"md-to-html~=0.7.3",
|
||||||
"jellyfish~=0.9.0",
|
"jellyfish~=0.9.0",
|
||||||
"transliterate~=1.10.2",
|
"transliterate~=1.10.2",
|
||||||
"pycountry~=24.0.1",
|
"pycountry~=24.0.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user