{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `ui.mermaid`\n", "\n", "Mermaid 图表\n", "\n", "渲染使用受 Markdown 启发的 [Mermaid 语言](https://mermaid.js.org/)编写的图表和图形。通过向 `ui.markdown` 元素提供扩展字符串 `'mermaid'`,也可以在 Markdown 元素中使用 mermaid 语法。\n", "\n", "`content`:要显示的 Mermaid 内容" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.mermaid('''\n", "graph LR;\n", " A --> B;\n", " A --> C;\n", "''')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 处理错误\n", "\n", "您可以通过监听 `error` 事件来处理错误。事件参数包含属性 `hash`、`message`、`str` 以及一个带有额外信息的错误对象。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.mermaid('''\n", "graph LR;\n", " A --> B;\n", " A -> C;\n", "''').on('error', lambda e: print(e.args['message']))\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }