mermaid.py 888 B

12345678910111213141516171819202122
  1. from .mixins.content_element import ContentElement
  2. class Mermaid(ContentElement,
  3. component='mermaid.js',
  4. exposed_libraries=['lib/mermaid/mermaid.esm.min.mjs'],
  5. extra_libraries=['lib/mermaid/*.js']):
  6. CONTENT_PROP = 'content'
  7. def __init__(self, content: str) -> None:
  8. """Mermaid Diagrams
  9. Renders diagrams and charts written in the Markdown-inspired `Mermaid <https://mermaid.js.org/>`_ language.
  10. The mermaid syntax can also be used inside Markdown elements by providing the extension string 'mermaid' to the ``ui.markdown`` element.
  11. :param content: the Mermaid content to be displayed
  12. """
  13. super().__init__(content=content)
  14. def on_content_change(self, content: str) -> None:
  15. self._props[self.CONTENT_PROP] = content.strip()
  16. self.run_method('update', content.strip())