From 7e5008943343a88be933431a6e6ccc02ce9a1884 Mon Sep 17 00:00:00 2001 From: Torsten Will Date: Thu, 3 Aug 2023 17:09:37 +0200 Subject: [PATCH] fix(37): protect against empty lines removeLeadingWhitespaces() to return the input string if it only contains whitespaces. added try-except around dedent for better error messages --- pandoc_include/main.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pandoc_include/main.py b/pandoc_include/main.py index ccc0cc6..98e7882 100644 --- a/pandoc_include/main.py +++ b/pandoc_include/main.py @@ -75,6 +75,8 @@ def skipWhitespaces(content): return pos def removeLeadingWhitespaces(s, num): + if not s.strip(): + return s regex = re.compile(r"[^\s]") m = regex.search(s) if m == None: @@ -155,9 +157,14 @@ def read_file(filename, config: dict): snippets.append(content[start:subEnd]) start = end content = "\n".join(snippets) - - if "dedent" in config: - content = "\n".join(dedent(content, config["dedent"])) + + try: + if "dedent" in config: + content = "\n".join(dedent(content, config["dedent"])) + except Exception as e: + import sys + print(f"Filename {filename} config {config}", file=sys.stderr) + raise e return content