diff --git a/src/odr/internal/html/document.cpp b/src/odr/internal/html/document.cpp
index 26df47f9..d9ff9df8 100644
--- a/src/odr/internal/html/document.cpp
+++ b/src/odr/internal/html/document.cpp
@@ -299,13 +299,13 @@ class TextHtmlFragment final : public HtmlFragmentBase {
const TextRoot element = root.as_text_root();
if (state.config().text_document_margin) {
- auto page_layout = element.page_layout();
- page_layout.height = {};
+ const PageLayout page_layout = element.page_layout();
out.write_element_begin(
- "div", HtmlElementOptions()
- .set_class("odr-page-outer")
- .set_style(translate_outer_page_style(page_layout)));
+ "div",
+ HtmlElementOptions()
+ .set_class("odr-page-outer")
+ .set_style(translate_outer_flowing_page_style(page_layout)));
out.write_element_begin(
"div", HtmlElementOptions()
.set_class("odr-page-inner")
diff --git a/src/odr/internal/html/document_style.cpp b/src/odr/internal/html/document_style.cpp
index 2ead0ef6..fb87a421 100644
--- a/src/odr/internal/html/document_style.cpp
+++ b/src/odr/internal/html/document_style.cpp
@@ -97,6 +97,19 @@ std::string html::translate_outer_page_style(const PageLayout &page_layout) {
return result;
}
+std::string
+html::translate_outer_flowing_page_style(const PageLayout &page_layout) {
+ PageLayout flowing_page_layout = page_layout;
+ flowing_page_layout.height = {};
+
+ std::string result = translate_outer_page_style(flowing_page_layout);
+ if (const std::optional height = page_layout.height;
+ height.has_value()) {
+ result.append("min-height:").append(height->to_string()).append(";");
+ }
+ return result;
+}
+
std::string html::translate_inner_page_style(const PageLayout &page_layout) {
std::string result;
if (const std::optional> margin_right =
diff --git a/src/odr/internal/html/document_style.hpp b/src/odr/internal/html/document_style.hpp
index 29174320..640e6f6a 100644
--- a/src/odr/internal/html/document_style.hpp
+++ b/src/odr/internal/html/document_style.hpp
@@ -35,6 +35,7 @@ const char *translate_font_style(FontStyle font_style);
const char *translate_font_position(FontPosition font_position);
std::string translate_outer_page_style(const PageLayout &page_layout);
+std::string translate_outer_flowing_page_style(const PageLayout &page_layout);
std::string translate_inner_page_style(const PageLayout &page_layout);
std::string translate_text_style(const TextStyle &text_style);
std::string translate_paragraph_style(const ParagraphStyle ¶graph_style);
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8907510f..0ed6e9f9 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -37,6 +37,7 @@ add_executable(odr_test
"src/table_position_test.cpp"
"src/internal/html/common_test.cpp"
+ "src/internal/html/document_style_test.cpp"
"src/internal/html/image_file_test.cpp"
"src/internal/html/media_file_test.cpp"
diff --git a/test/src/internal/html/document_style_test.cpp b/test/src/internal/html/document_style_test.cpp
new file mode 100644
index 00000000..25be0f6a
--- /dev/null
+++ b/test/src/internal/html/document_style_test.cpp
@@ -0,0 +1,37 @@
+#include
+#include
+
+#include
+
+#include
+
+using namespace odr;
+namespace ihtml = odr::internal::html;
+
+namespace {
+
+PageLayout a4_page_layout() {
+ PageLayout page_layout;
+ page_layout.width = Measure("21cm");
+ page_layout.height = Measure("29.7cm");
+ return page_layout;
+}
+
+} // namespace
+
+TEST(html_document_style, outer_page_style_fixes_both_dimensions) {
+ EXPECT_EQ(ihtml::translate_outer_page_style(a4_page_layout()),
+ "width:21cm;height:29.7cm;");
+}
+
+TEST(html_document_style, outer_flowing_page_style_floors_the_height) {
+ EXPECT_EQ(ihtml::translate_outer_flowing_page_style(a4_page_layout()),
+ "width:21cm;min-height:29.7cm;");
+}
+
+TEST(html_document_style, outer_flowing_page_style_without_height) {
+ PageLayout page_layout = a4_page_layout();
+ page_layout.height = {};
+ EXPECT_EQ(ihtml::translate_outer_flowing_page_style(page_layout),
+ "width:21cm;");
+}