md converter, somewhat modular
import os
markdown_enabled = False
markdown_install_fail = False
def configure(markdown_status):
global markdown_enabled
if markdown_status.lower() == "yes":
markdown_enabled = True
elif markdown_status.lower() == "no":
markdown_enabled = False
else:
print("Unknown Setting")
markdown_enabled = False
if markdown_enabled:
try:
import markdown
except ImportError:
print("Markdown failed to import.\nAttempting to install it.")
try:
os.system("pip install markdown")
import markdown
except:
print("Error: Could Not install Markdown\nUsing basic built-in interpreting")
markdown_install_fail = True
def basic_markdown_to_html(text):
text = text.replace("**", "<b>").replace("**", "</b>")
text = text.replace("```html", "<pre><code>").replace("```", "</code></pre>")
return text
def convert(text):
if markdown_enabled and not markdown_install_fail:
print("Converting to Markdown...")
print("Using normal markdown processor")
return markdown.markdown(text)
print("Markdown Processed")
else:
print("Using basic Markdown to HTML conversion...")
return basic_markdown_to_html(text)
The md processor is converting internal content of the markdown tag to html, and the page is using it, or at least that's what I think.
The ai processor seems like it outputted html, but im seeing processed content like
content
check the image for more details.
I am trying to make it convert the ais content to html, like chat gpt. It is ouput is html rendered on the page
md converter, somewhat modular
import os
markdown_enabled = False
markdown_install_fail = False
def configure(markdown_status):
global markdown_enabled
if markdown_status.lower() == "yes":
markdown_enabled = True
elif markdown_status.lower() == "no":
markdown_enabled = False
else:
print("Unknown Setting")
markdown_enabled = False
if markdown_enabled:
try:
import markdown
except ImportError:
print("Markdown failed to import.\nAttempting to install it.")
try:
os.system("pip install markdown")
import markdown
except:
print("Error: Could Not install Markdown\nUsing basic built-in interpreting")
markdown_install_fail = True
def basic_markdown_to_html(text):
text = text.replace("**", "<b>").replace("**", "</b>")
text = text.replace("```html", "<pre><code>").replace("```", "</code></pre>")
return text
def convert(text):
if markdown_enabled and not markdown_install_fail:
print("Converting to Markdown...")
print("Using normal markdown processor")
return markdown.markdown(text)
print("Markdown Processed")
else:
print("Using basic Markdown to HTML conversion...")
return basic_markdown_to_html(text)
The md processor is converting internal content of the markdown tag to html, and the page is using it, or at least that's what I think.
The ai processor seems like it outputted html, but im seeing processed content like
content
check the image for more details.
I am trying to make it convert the ais content to html, like chat gpt. It is ouput is html rendered on the page
Would you consider using regular expressions to find Markdown syntax in your text?
I think it will help you to identify pieces of text easier.
For example: bold text is a pattern of: **\w+**
And this will help you avoid replacing irrelevant strings. You need to identify all markdown syntaxes and write similar conversions. I can help you with that too. Let me know if you are happy to utilize regex.