Markdown is a very popular markup language, used to create multiple output types, including, PDFs, web pages, ebooks, and more.
Here are some ways you can use Markdown in Python
Print Markdown-formatted text in the Python console
from rich.console import Console
from rich.markdown import Markdown
console = Console()
md = Markdown("# Hello, **PDSR**!")
console.print(md)
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Hello, PDSR! ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Render Markdown in Jupyter Notebook
from IPython.display import display, Markdown
display(Markdown("Hello **PDSR** in [Jupyter](https://jupyter.org/)!"))
Convert Markdown to HTML
This will output HTML which can be used in a web page or other HTML-compatible formats.
import markdown
markdown_string = "# Hello, PDSR"
html_string = markdown.markdown(markdown_string)
print(html_string)
Print Markdown Content to File
from mdprint import mdprint
with open('output.md', 'w') as f:
mdprint('Hello **PDSR**', file=f)