From cff16401fa5bbc21d6782280061b01d50c4c8fdc Mon Sep 17 00:00:00 2001 From: Jaap Joris Vens Date: Fri, 24 Feb 2023 00:25:59 +0100 Subject: [PATCH 1/3] Relative multi-line HTML elements Reintroduces "relative multi-line" indentation to DjHTML: However, this only happens when the tag name is followed by a newline. Otherwise, "absolute multi-line" indentation will be used: This is a good rule, but also the last rule I'm willing to add regarding multi-line indentation. Our users deserve a stable set of indentation principles, and this is it. No more bikeshedding. --- djhtml/modes.py | 29 +++++++++----- tests/suite/html.html | 63 +++++++++++++++++------------- tests/suite/html.tokens | 85 +++++++++++++++++++++++------------------ 3 files changed, 105 insertions(+), 72 deletions(-) diff --git a/djhtml/modes.py b/djhtml/modes.py index 358618d..6f64179 100644 --- a/djhtml/modes.py +++ b/djhtml/modes.py @@ -287,9 +287,19 @@ def create_token(self, raw_token, src, line): if raw_token == "<": if tag := re.match(r"([\w\-\.:]+)", src): - token, mode = Token.Text(raw_token, mode=DjHTML), InsideHTMLTag( - tag[1], line, self + tagname = tag[1] + absolute = True + token = Token.Text(raw_token, mode=DjHTML) + offsets = dict( + relative=-1 if line.indents else 0, + absolute=len(line) + len(tagname) + 2, ) + if tag := re.match(tagname + r"[ \t]*\n", src): + # Use "relative" multi-line indendation instead + absolute = False + token.indents = True + offsets = dict(relative=0, absolute=0) + mode = InsideHTMLTag(tagname, line, self, absolute, offsets) else: token = Token.Text(raw_token, mode=DjHTML) elif raw_token == " text
text
@@ -227,8 +227,8 @@

Title

text + id="2" href="" + class="button"> text Title text text @@ -306,11 +306,11 @@

Title