From 683079f5056c8d573482eedb48079f7546f0e712 Mon Sep 17 00:00:00 2001 From: "matthias@arch" Date: Thu, 23 Nov 2023 22:07:54 +0100 Subject: [PATCH] respect indentation level --- html-preprocessor | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/html-preprocessor b/html-preprocessor index ca3ca55..cf72eae 100755 --- a/html-preprocessor +++ b/html-preprocessor @@ -545,6 +545,17 @@ class HTMLParser(Parser): Sidenav.addEntry(match.groups()[1], f"#{match.groups()[0]}") ptrace("HTMLParser.add_sidenav_headings:", f"Found heading with id:", match.groups()) + def get_leading_whitespaces(self): + """returns the whitespaces at the start of the line""" + # find last newline + line_beg = self.file.rfind("\n", 0, self.i) + if line_beg < 0: line_beg = 0 + else: line_beg += 1 # start after newline + match = re.match(r"^([ \t]*)", self.file[line_beg:self.pos['line_end']]) + if not match: return "" + else: return match.groups()[0] + + # Parsing functions def find_line_end(self): """ @@ -605,7 +616,8 @@ class HTMLParser(Parser): """ # not a multiline comment if self.pos["line_end"] > self.pos["cmt_end"]: return - self.replace(self.pos["cmt_beg"], self.pos["cmt_end"], self.file[self.pos["cmt_beg"]:self.pos["cmt_end"]].replace("\n", "-->\n\n" + indent + "