Browse Source

code review

Falko Schindler 2 years ago
parent
commit
00ca49c482
3 changed files with 14 additions and 7 deletions
  1. 5 2
      nicegui/elements/link.py
  2. 7 3
      website/demo.py
  3. 2 2
      website/more_documentation/link_documentation.py

+ 5 - 2
nicegui/elements/link.py

@@ -10,8 +10,11 @@ register_component('link', __file__, 'link.js')
 
 
 class Link(TextElement):
 class Link(TextElement):
 
 
-    def __init__(self, text: str = '', target: Union[Callable[..., Any],
-                                                     str, Element] = '#', new_tab: bool = False) -> None:
+    def __init__(self,
+                 text: str = '',
+                 target: Union[Callable[..., Any], str, Element] = '#',
+                 new_tab: bool = False,
+                 ) -> None:
         """Link
         """Link
 
 
         Create a hyperlink.
         Create a hyperlink.

+ 7 - 3
website/demo.py

@@ -1,4 +1,5 @@
 import inspect
 import inspect
+import re
 from typing import Callable, Optional, Union
 from typing import Callable, Optional, Union
 
 
 import isort
 import isort
@@ -15,9 +16,12 @@ BROWSER_BGCOLOR = '#00000010'
 BROWSER_COLOR = '#ffffff'
 BROWSER_COLOR = '#ffffff'
 
 
 
 
-def remove_comment(text: str) -> str:
+uncomment_pattern = re.compile(r'^(\s*)# ?')
+
+
+def uncomment(text: str) -> str:
     """non-executed lines should be shown in the code examples"""
     """non-executed lines should be shown in the code examples"""
-    return text.replace('# ', '')
+    return uncomment_pattern.sub(r'\1', text)
 
 
 
 
 def demo(f: Callable) -> Callable:
 def demo(f: Callable) -> Callable:
@@ -33,7 +37,7 @@ def demo(f: Callable) -> Callable:
             del code[0]
             del code[0]
         indentation = len(code[0]) - len(code[0].lstrip())
         indentation = len(code[0]) - len(code[0].lstrip())
         code = [line[indentation:] for line in code]
         code = [line[indentation:] for line in code]
-        code = ['from nicegui import ui'] + [remove_comment(line) for line in code]
+        code = ['from nicegui import ui'] + [uncomment(line) for line in code]
         code = ['' if line == '#' else line for line in code]
         code = ['' if line == '#' else line for line in code]
         if not code[-1].startswith('ui.run('):
         if not code[-1].startswith('ui.run('):
             code.append('')
             code.append('')

+ 2 - 2
website/more_documentation/link_documentation.py

@@ -23,8 +23,8 @@ def more() -> None:
         )
         )
         link_target('target_B', '70px')  # HIDE
         link_target('target_B', '70px')  # HIDE
         label_B = ui.label(
         label_B = ui.label(
-            'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
-            'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'
+            'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. '
+            'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. '
             'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
             'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'
         )
         )
         with navigation:
         with navigation: