src/html.cpp

changeset 52
e9edc3bd0301
parent 50
1ebab6df60c2
child 54
586dcd606e47
--- a/src/html.cpp	Mon May 19 15:34:30 2025 +0200
+++ b/src/html.cpp	Mon May 19 16:05:58 2025 +0200
@@ -25,6 +25,7 @@
 #include "html.h"
 
 #include <cstdio>
+#include <cassert>
 
 using namespace std::chrono;
 
@@ -32,9 +33,11 @@
     static constexpr const char* weekdays[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
 
     static unsigned indentation;
-    static const char *tabs = "                                ";
+    static const char *tabs = "                                                                ";
     static void indent(int change = 0) {
         indentation += change;
+        assert(indentation >= 0);
+        assert(indentation <= max_indentation);
         fwrite(tabs, 4, indentation, stdout);
     }
 
@@ -67,10 +70,11 @@
     }
 }
 
-void html::open(bool fragment) {
+void html::open(bool fragment, unsigned char fragment_indent) {
     if (fragment) {
+        indent(fragment_indent);
         puts("<div class=\"heatmap-content\">");
-        indentation = 1;
+        indentation++;
     } else {
         puts(R"(<!DOCTYPE html>
 <html>
@@ -128,6 +132,7 @@
 
 void html::close(bool fragment) {
     if (fragment) {
+        indent(-1);
         puts("</div>");
     } else {
         puts("        </div>\n    </body>\n</html>");

mercurial