markdown_documentation.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from nicegui import ui
  2. from ...model import UiElementDocumentation
  3. class MarkdownDocumentation(UiElementDocumentation, element=ui.markdown):
  4. def main_demo(self) -> None:
  5. ui.markdown('''This is **Markdown**.''')
  6. def more(self) -> None:
  7. @self.demo('Markdown with indentation', '''
  8. Common indentation is automatically stripped from the beginning of each line.
  9. So you can indent markdown elements, and they will still be rendered correctly.
  10. ''')
  11. def markdown_with_indentation():
  12. ui.markdown('''
  13. ### Example
  14. This line is not indented.
  15. This block is indented.
  16. Thus it is rendered as source code.
  17. This is normal text again.
  18. ''')
  19. @self.demo('Markdown with code blocks', '''
  20. You can use code blocks to show code examples.
  21. If you specify the language after the opening triple backticks, the code will be syntax highlighted.
  22. See [the Pygments website](https://pygments.org/languages/) for a list of supported languages.
  23. ''')
  24. def markdown_with_code_blocks():
  25. ui.markdown('''
  26. ```python
  27. from nicegui import ui
  28. ui.label('Hello World!')
  29. ui.run(dark=True)
  30. ```
  31. ''')
  32. @self.demo('Markdown tables', '''
  33. By activating the "tables" extra, you can use Markdown tables.
  34. See the [markdown2 documentation](https://github.com/trentm/python-markdown2/wiki/Extras#implemented-extras) for a list of available extras.
  35. ''')
  36. def markdown_tables():
  37. ui.markdown('''
  38. | First name | Last name |
  39. | ---------- | --------- |
  40. | Max | Planck |
  41. | Marie | Curie |
  42. ''', extras=['tables'])