feat: stopped using markdown
This commit is contained in:
parent
f25febf297
commit
21a0adfa50
@ -1,60 +1,18 @@
|
||||
import pandoc
|
||||
|
||||
"""
|
||||
TODO
|
||||
implement in setup.py a skript to install pandocs
|
||||
https://pandoc.org/installing.html
|
||||
|
||||
!!!!!!!!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!!!
|
||||
"""
|
||||
|
||||
import mistune
|
||||
import html2markdown
|
||||
|
||||
class FormattedText:
|
||||
"""
|
||||
the self.html value should be saved to the database
|
||||
"""
|
||||
|
||||
doc = None
|
||||
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:
|
||||
@ -68,11 +26,12 @@ class FormattedText:
|
||||
|
||||
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 = 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-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",
|
||||
|
Loading…
Reference in New Issue
Block a user