Skip to content

Commit

Permalink
Serializer no longer deletes the document, lol
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Mar 1, 2025
1 parent 4714a16 commit caa6029
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bikeshed/Spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def finish(self, outputFilename: str | None = None, newline: str | None = None)
m.die(f"Something prevented me from saving the output document to {outputFilename}:\n{e}")
else:
if outputFilename == "-":
m.die(f"Can't do multipage output to stdout.")
m.die("Can't do multipage output to stdout.")
return
pages = multipage.serializePages(self, outputFilename)
if pages and not constants.dryRun:
Expand Down
8 changes: 6 additions & 2 deletions bikeshed/h/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ def _writeOpaqueElement(self, tag: str, el: t.ElementT, write: WriterFn, indent:

def _writeInlineElement(self, tag: str, el: Nodes, write: WriterFn, inline: bool) -> None:
self.startTag(tag, el, write)
for node in dom.childNodes(el, mergeText=True):
if isinstance(el, list):
children = el
else:
children = dom.childNodes(el, mergeText=True)
for node in children:
if self.isElement(node):
self._serializeEl(node, write, inline=inline)
else:
Expand All @@ -256,7 +260,7 @@ def _categorizeBlockChildren(self, el: Nodes) -> tuple[str, Nodes | None]:
return "empty", None

# See if there are any block children
children = dom.childNodes(el, clear=True, mergeText=True)
children = list(dom.childNodes(el, mergeText=True))
for child in children:
if self.isElement(child) and self.isBlockElement(child.tag):
return "blocks", self._blocksFromChildren(children)
Expand Down
8 changes: 3 additions & 5 deletions bikeshed/multipage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

def serializePages(doc: t.SpecT, mainFilename: str) -> dict[str, str]:
main = h.find("main", doc)
assert main is not None
pages = collectIntoPages(list(h.childNodes(main, clear=True)), mainFilename)
ret = {}
serializer = h.Serializer(doc.md.opaqueElements, doc.md.blockElements)
for filename, nodes in pages.items():
h.replaceContents(main, nodes)
h.childNodes(main, clear=True)
h.appendChild(main, nodes)
ret[filename] = serializer.serialize(doc.document)
print(filename + " " + str(len(nodes)) + " nodes; " + str(len(ret[filename].split("\n"))) + " lines")
#print(ret[filename][0:80])
return ret


Expand All @@ -29,8 +29,6 @@ def collectIntoPages(nodes: list[t.NodeT], mainFilename: str) -> dict[str, list[
return {}
filename = id + ".html"
pages[filename] = []
#if h.isElement(node):
# print(f"{filename} {h.tagName(node)} {node.get('bs-line-number')}")
pages[filename].append(node)
return pages

Expand Down

0 comments on commit caa6029

Please sign in to comment.