|
| 1 | +# You'll have to install markdownit to run this example |
| 2 | +# pip install markdown-it-py[plugins] |
| 3 | +from dash import Dash, html, dcc |
| 4 | +from html2dash import html2dash |
| 5 | +import dash_mantine_components as dmc |
| 6 | +from markdown_it import MarkdownIt |
| 7 | +from mdit_py_plugins.attrs.index import attrs_block_plugin, attrs_plugin |
| 8 | +from functools import partial |
| 9 | +from dash_iconify import DashIconify |
| 10 | + |
| 11 | +md = MarkdownIt().enable("table").use(attrs_block_plugin).use(attrs_plugin) |
| 12 | +h = md.render( |
| 13 | + """ |
| 14 | +# Hello World |
| 15 | +This is a paragraph. |
| 16 | +
|
| 17 | +{#subtitle} |
| 18 | +## This is a subtitle with an ID |
| 19 | +**Bold text** and *italic text*. |
| 20 | +
|
| 21 | +
|
| 22 | +## This is a table |
| 23 | +
|
| 24 | +{striped=True withBorder=True} |
| 25 | +| Name | Age | |
| 26 | +| ---- | --- | |
| 27 | +| John | 30 | |
| 28 | +| Jane | 28 | |
| 29 | +
|
| 30 | +## This is a list |
| 31 | +- Item 1 |
| 32 | +- Item 2 |
| 33 | +- Item 3 |
| 34 | +
|
| 35 | +## This is a code block |
| 36 | +
|
| 37 | +{language=python withLineNumbers=True} |
| 38 | +```python |
| 39 | +if __name__ == "__main__": |
| 40 | + print("Hello World") |
| 41 | +``` |
| 42 | +
|
| 43 | +## This is a link |
| 44 | +[Click here](https://google.com) |
| 45 | +
|
| 46 | +## This is a blockquote |
| 47 | +> This is a blockquote |
| 48 | +
|
| 49 | +## This is a horizontal rule |
| 50 | +--- |
| 51 | +
|
| 52 | +""" |
| 53 | +) |
| 54 | + |
| 55 | +modules = [dmc, html, dcc] |
| 56 | + |
| 57 | +element_map = { |
| 58 | + "h1": dmc.Title, |
| 59 | + "h2": partial(dmc.Title, order=2), |
| 60 | + "p": partial(dmc.Text, weight=500), |
| 61 | + "img": dmc.Image, |
| 62 | + "ul": partial(dmc.List, icon=dmc.ThemeIcon(DashIconify(icon="mdi:check"))), |
| 63 | + "li": dmc.ListItem, |
| 64 | + "code": dmc.Prism, |
| 65 | +} |
| 66 | + |
| 67 | +app = Dash(__name__) |
| 68 | + |
| 69 | + |
| 70 | +app.layout = html2dash(h, module_list=modules, element_map=element_map) |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + app.run_server(debug=True) |
0 commit comments