work
authorBen Pfaff <blp@cs.stanford.edu>
Thu, 15 May 2025 14:43:35 +0000 (07:43 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Thu, 15 May 2025 14:43:35 +0000 (07:43 -0700)
rust/pspp/src/output/spv.rs

index df39a7126c07a884de0422449a888df24b6c4054..f8b0ff22e39289d25bfc31c1d4969d63bf555d8f 100644 (file)
@@ -427,23 +427,6 @@ impl Heading {
     }
 }
 
-enum Child {
-    Container(Container),
-    Heading(Box<Heading>),
-}
-
-impl Child {
-    fn emit<W>(&self, writer: &mut XmlWriter<W>) -> IoResult<()>
-    where
-        W: Write,
-    {
-        match self {
-            Child::Container(container) => container.emit(writer),
-            Child::Heading(heading) => heading.emit(writer),
-        }
-    }
-}
-
 fn maybe_with_attribute<'a, 'b, W, I>(
     element: ElementWriter<'a, W>,
     attr: Option<I>,
@@ -471,12 +454,19 @@ impl Container {
     where
         W: Write,
     {
-        let mut element = writer
-            .create_element("container")
-            .with_attribute(("visibility", if self.show { "visible" } else { "hidden" }));
-        if self.page_break_before {
-            element = element.with_attribute(("page-break-before", "always"));
-        }
+        let mut element = if !self.content.is_heading() {
+            let mut element = writer
+                .create_element("container")
+                .with_attribute(("visibility", if self.show { "visible" } else { "hidden" }));
+            if self.page_break_before {
+                element = element.with_attribute(("page-break-before", "always"));
+            }
+            element
+        } else {
+            let mut element = writer
+                .create_element("heading")
+                .with_attribute(("visibility", if self.show { "visible" } else { "hidden" }));
+        };
         element.write_inner_content(|writer| {
             self.label.emit(writer)?;
             self.content
@@ -502,6 +492,7 @@ impl Label {
 }
 
 enum Content {
+    Heading(Vec<Box<Container>>),
     Table(Table),
 }
 
@@ -527,6 +518,21 @@ impl Content {
         );
         element
     }
+
+    fn is_heading(&self) -> bool {
+        match self {
+            Content::Heading(_) => true,
+            _ => false,
+        }
+    }
+
+    fn element_name(&self) -> &'static str {
+        if self.is_heading() {
+            "heading"
+        } else {
+            "container"
+        }
+    }
 }
 
 struct Table {