diff --git a/bikeshed/Spec.py b/bikeshed/Spec.py index a90ec1fdad..9ac335f85c 100644 --- a/bikeshed/Spec.py +++ b/bikeshed/Spec.py @@ -314,6 +314,7 @@ def serialize(self): ).serialize(self.document) except Exception as e: die("{0}", e) + return rendered = finalHackyCleanup(rendered) return rendered diff --git a/bikeshed/h/dom.py b/bikeshed/h/dom.py index 162c928685..4cf0e8bdc4 100644 --- a/bikeshed/h/dom.py +++ b/bikeshed/h/dom.py @@ -144,16 +144,16 @@ def innerHTML(el): return (el.text or "") + "".join(tostring(x, encoding="unicode") for x in el) -def outerHTML(el, literal=False): +def outerHTML(el, literal=False, with_tail=False): if el is None: return "" if isinstance(el, str): return el if isinstance(el, list): - return "".join(map(outerHTML, el)) + return "".join(outerHTML(x) for x in el) if el.get("bs-autolink-syntax") is not None and not literal: return el.get("bs-autolink-syntax") - return tostring(el, with_tail=False, encoding="unicode") + return tostring(el, with_tail=with_tail, encoding="unicode") def serializeTag(el): @@ -419,7 +419,23 @@ def childNodes(parentEl, clear=False, skipOddNodes=True): if it's false, there might be comments, PIs, etc. """ if isinstance(parentEl, list): - return parentEl + ret = [] + for c in parentEl: + if isinstance(c, str): + ret.append(c) + continue + if skipOddNodes and isOddNode(c): + pass + else: + ret.append(c) + if not emptyText(c.tail, wsAllowed=False): + ret.append(c.tail) + if clear: + c.tail = None + if clear: + parentEl[:] = [] + return ret + ret = [] if not emptyText(parentEl.text, wsAllowed=False): ret.append(parentEl.text) diff --git a/bikeshed/h/serializer.py b/bikeshed/h/serializer.py index 57b96275e3..7ae013d7f1 100644 --- a/bikeshed/h/serializer.py +++ b/bikeshed/h/serializer.py @@ -222,7 +222,7 @@ def _categorizeBlockChildren(self, el): """ if len(el) == 0 and dom.emptyText(el.text): return "empty", None - children = dom.childNodes(el) + children = dom.childNodes(el, clear=True) for child in children: if self.isElement(child) and self.isBlockElement(child.tag): return "blocks", self._blocksFromChildren(children)