From: Fredrik Tolf Date: Sat, 28 Dec 2013 05:34:32 +0000 (+0100) Subject: Improved indentation a bit. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=7e9080af248b38edec371f117eb4749b09a3caca;p=wrw.git Improved indentation a bit. --- diff --git a/wrw/sp/util.py b/wrw/sp/util.py index deec92d..02f61f0 100644 --- a/wrw/sp/util.py +++ b/wrw/sp/util.py @@ -134,14 +134,7 @@ class formatter(object): def end(self, el): pass - def next(self): - if self.src is None: - raise StopIteration() - try: - ev, el = next(self.src) - except StopIteration: - self.src = None - ev, el = "$", None + def handle(self, ev, el): if ev == ">": self.starttag(el) elif ev == "/": @@ -156,6 +149,16 @@ class formatter(object): self.start(el) elif ev == "$": self.end(el) + + def next(self): + if self.src is None: + raise StopIteration() + try: + ev, el = next(self.src) + except StopIteration: + self.src = None + ev, el = "$", None + self.handle(ev, el) ret = str(self.buf) self.buf[:] = "" return ret @@ -225,6 +228,7 @@ class indenter(formatter): self.atbreak = True self.inline = False self.stack = [] + self.last = None, None def write(self, text): lines = text.split(u"\n") @@ -258,7 +262,10 @@ class indenter(formatter): def starttag(self, el): if not self.inline: - self.br() + if self.last[0] == "<" and self.last[1].name == el.name: + pass + else: + self.br() self.push(el) self.inline = self.inline or self.inlinep(el) self.curind += self.indent @@ -283,6 +290,10 @@ class indenter(formatter): def end(self, el): self.br() + def handle(self, ev, el): + super(indenter, self).handle(ev, el) + self.last = ev, el + class textindenter(indenter): maxcol = 70 diff --git a/wrw/sp/xhtml.py b/wrw/sp/xhtml.py index 48ed41d..a2c1eb1 100644 --- a/wrw/sp/xhtml.py +++ b/wrw/sp/xhtml.py @@ -43,8 +43,8 @@ class htmlformatter(util.formatter): if el.name in self.allowshort: super(htmlformatter, self).shorttag(el) else: - self.starttag(el) - self.endtag(el) + self.handle(">", el) + self.handle("<", el) class htmlindenter(util.textindenter, htmlformatter): pass