From bc091807fb27e4d4fc3cf5cd4f9f4fdd365d4c5f Mon Sep 17 00:00:00 2001 From: Hellow2 Date: Fri, 3 Feb 2023 15:21:59 +0100 Subject: [PATCH] hs --- src/music_kraken/database/objects/notes.py | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 src/music_kraken/database/objects/notes.py diff --git a/src/music_kraken/database/objects/notes.py b/src/music_kraken/database/objects/notes.py new file mode 100644 index 0000000..5f101a6 --- /dev/null +++ b/src/music_kraken/database/objects/notes.py @@ -0,0 +1,117 @@ +# https://github.com/Alir3z4/html2text +import html2text + +import pandoc + +""" +>>> import html2text +>>> +>>> h = html2text.HTML2Text() +>>> # Ignore converting links from HTML +>>> h.ignore_links = True +>>> print h.handle("

Hello, world!") +Hello, world! + +>>> print(h.handle("

Hello, world!")) + +Hello, world! + +>>> # Don't Ignore links anymore, I like links +>>> h.ignore_links = False +>>> print(h.handle("

Hello, world!")) +Hello, [world](https://www.google.com/earth/)! +""" + + +class FormattedText: + _plaintext: str + _markdown: str + _html: str + + doc = None + + def __new__(cls, **kwargs): + self = object.__new__(cls) + + self._plaintext = "" + self._markdown = "" + self._html = "" + + return self + + 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._plaintext = plaintext + + def set_markdown(self, markdown: str): + if markdown is None: + return + + self._markdown = 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 None + return pandoc.write(self.doc, format="markdown").strip() + + def get_html(self) -> str: + if self.doc is None: + return None + return pandoc.write(self.doc, format="html").strip() + + +class NotesAttributes: + def __init__(self) -> None: + pass + +if __name__ == "__main__": + markdown = """ +# World of Work + +1. The right to help out society, and being paied for it +2. **The right to get paied, so you can get along well.** +3. The right for every individual to sell their products to provide for themselfes or for others +4. The right of fair competitions, meaning eg. no monopoles. +5. **The right for a home.** +6. **The right to good healthcare** +7. The right of protections against tragedies, be it personal ones, or global ones. +8. The right to be educated in a way that enables you to work. + +## 3 most important ones + +1. The right to get paied, so you can get along well. +2. The right for a home. +3. The right for a good healthcare. + """ + html = """ +Contact: ghostbath@live.com
+
+Although the band originally claimed that they were from Chongqing, China, it has been revealed in a 2015 interview with Noisey that they're an American band based in Minot, North Dakota.
+
+According to the band, "Ghost Bath" refers to "the act of committing suicide by submerging in a body of water."
+
+Compilation appearance(s):
+- "Luminescence" on Jericho Vol.36 - Nyctophobia (2018) [] + """ + + notes = FormattedText(html=html) + print(notes.get_html()) + print("-"*30) + print(notes.get_markdown()) \ No newline at end of file