Jelajahi Sumber

add pytest and documentation

Falko Schindler 1 tahun lalu
induk
melakukan
bdd94c83bd

+ 2 - 1
nicegui/elements/editor.py

@@ -14,7 +14,8 @@ class Editor(ValueElement, DisableableElement):
                  ) -> None:
                  ) -> None:
         """Editor
         """Editor
 
 
-        A code editor with syntax highlighting, based on `Quasar's QEditor <https://quasar.dev/vue-components/editor>`_.
+        A WYSIWYG editor based on `Quasar's QEditor <https://quasar.dev/vue-components/editor>`_.
+        The value is a string containing the formatted text as HTML code.
 
 
         :param value: initial value
         :param value: initial value
         :param on_change: callback to be invoked when the value changes
         :param on_change: callback to be invoked when the value changes

+ 14 - 0
tests/test_editor.py

@@ -0,0 +1,14 @@
+
+from nicegui import ui
+
+from .screen import Screen
+
+
+def test_editor(screen: Screen):
+    editor = ui.editor(placeholder='Type something here')
+    ui.markdown().bind_content_from(editor, 'value', backward=lambda v: f'HTML code:\n```\n{v}\n```')
+
+    screen.open('/')
+    screen.find_by_class('q-editor__content').click()
+    screen.type('Hello\nworld!')
+    screen.should_contain('Hello<div>world!</div>')

+ 1 - 0
website/documentation.py

@@ -143,6 +143,7 @@ def create_full() -> None:
     load_demo(ui.scene)
     load_demo(ui.scene)
     load_demo(ui.tree)
     load_demo(ui.tree)
     load_demo(ui.log)
     load_demo(ui.log)
+    load_demo(ui.editor)
     load_demo(ui.json_editor)
     load_demo(ui.json_editor)
 
 
     heading('Layout')
     heading('Layout')

+ 7 - 0
website/more_documentation/editor_documentation.py

@@ -0,0 +1,7 @@
+from nicegui import ui
+
+
+def main_demo() -> None:
+    editor = ui.editor(placeholder='Type something here')
+    ui.markdown().bind_content_from(editor, 'value',
+                                    backward=lambda v: f'HTML code:\n```\n{v}\n```')