소스 검색

fix pipe warning (#467) (#1684)

* fix pipe warning

* linting

* update regex

* fix warning

* Update taipy/gui/_renderers/_markdown/preproc.py

Co-authored-by: Fabien Lelaquais <86590727+FabienLelaquais@users.noreply.github.com>

---------

Co-authored-by: Fabien Lelaquais <86590727+FabienLelaquais@users.noreply.github.com>
Dinh Long Nguyen 9 달 전
부모
커밋
fa70b84f8b
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      taipy/gui/_renderers/_markdown/preproc.py

+ 12 - 1
taipy/gui/_renderers/_markdown/preproc.py

@@ -60,6 +60,9 @@ class _Preprocessor(MdPreprocessor):
     #  Note 2: Space characters after the equal sign are significative
     __PROPERTY_RE = re.compile(r"((?:don'?t|not)\s+)?([a-zA-Z][\.a-zA-Z_$0-9]*(?:\[(?:.*?)\])?)\s*(?:=(.*))?$")
 
+    # Error syntax detection regex
+    __MISSING_LEADING_PIPE_RE = re.compile(r"<[^|](.*?)\|>")
+
     _gui: "Gui"
 
     @staticmethod
@@ -72,10 +75,18 @@ class _Preprocessor(MdPreprocessor):
         # Un-escape pipe character in property value
         return (prop_name, prop_value.replace("\\|", "|"))
 
+    def _validate_line(self, line: str, line_count: int) -> bool:
+        if _Preprocessor.__MISSING_LEADING_PIPE_RE.search(line) is not None:
+            _warn(f"Missing leading pipe '|' in opening tag line {line_count}: '{line}'.")
+            return False
+        return True
+
     def run(self, lines: List[str]) -> List[str]:
         new_lines = []
         tag_stack = []
         for line_count, line in enumerate(lines, start=1):
+            if not self._validate_line(line, line_count):
+                continue
             new_line = ""
             last_index = 0
             # Opening tags
@@ -100,7 +111,7 @@ class _Preprocessor(MdPreprocessor):
                         line += f' {property[0]}="{prop_value}"'
                     line += _MarkdownFactory._TAIPY_END + new_line_delimeter
                 else:
-                    _warn(f"Invalid tag name '{tag}' in line {line_count}.")
+                    _warn(f"Failed to recognized block tag '{tag}' in line {line_count}. Check that you are closing the tag properly with '|>' if it is a control element.")  # noqa: E501
             # Other controls
             for m in _Preprocessor.__CONTROL_RE.finditer(line):
                 control_name, properties = self._process_control(m.group(1), line_count)