Markdown + automated HTML styling API Reference
Example Markdown
- With bold and italics
- With a link
And a subheading
This is a blockquote
This supports inline latex: $e^{\pi i} + 1 = 0$ as well as block latex thanks to Katex.
$$ \frac{1}{2\pi i} \oint_C \frac{f(z)}{z-z_0} dz $$
And even syntax highlighting thanks to Highlight.js! (Just make sure you set highlightjs=True in the headers function)
def add(a, b):
return a + b
def ex_markdown():
md = '''# Example Markdown
+ With **bold** and *italics*
+ With a [link](https://github.com)
### And a subheading
> This is a blockquote
This supports inline latex: $e^{\\pi i} + 1 = 0$ as well as block latex thanks to Katex.
$$
\\frac{1}{2\\pi i} \\oint_C \\frac{f(z)}{z-z_0} dz
$$
And even syntax highlighting thanks to Highlight.js! (Just make sure you set `highlightjs=True` in the headers function)
```python
def add(a, b):
return a + b
```
'''
return render_md(md)
You can overwrite the default styling for markdown rendering with your own css classes with `class_map
With custom bold style
But no extra quote style because class_map overrides all default styled
def ex_markdown2():
md = '''With custom **bold** style\n\n > But no extra quote style because class_map overrides all default styled'''
return render_md(md, class_map={'b': 'text-red-500'})
You can modify the default styling for markdown rendering with your own css classes with `class_map_mods
With custom bold style
But default quote style because class_map_mods replaces sepecified styles and leaves the rest as default
def ex_markdown3():
md = '''With custom **bold** style\n\n > But default quote style because class_map_mods replaces sepecified styles and leaves the rest as default'''
return render_md(md, class_map_mods={'b': 'text-red-500'})
This uses the apply_classes function, which can be used to apply classes to html strings. This is useful for applying styles to any html you get from an external source.
def ex_applyclasses():
return apply_classes('<h1>Hello, World!</h1><p>This is a paragraph</p>')
One common external source is a markdown renderer. MonsterUI uses tailwind css for styling so you don't get any styling without specifying classes, apply_classes can do that for you.
Hi
def ex_applyclasses2():
from mistletoe import markdown, HTMLRenderer
md = markdown('# Hi\n[a link](www.google.com)', renderer=HTMLRenderer)
return Safe(apply_classes(md))
apply_classes
Sourceapply_classes(html_str: str, class_map=None, class_map_mods=None) -> str Apply classes to html string
html_strHtml stringclass_mapClass mapclass_map_modsClass map that will modify the class map map (for small changes to base map)
Returns: Html string with classes applied