home · contact · privacy
Clean up whitespace handling in templates. master
authorChristian Heller <c.heller@plomlompom.de>
Sat, 14 Feb 2026 18:09:39 +0000 (19:09 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 14 Feb 2026 18:09:39 +0000 (19:09 +0100)
src/templates/_macros.tmpl
src/templates/ledger_raw.html
src/templates/ledger_structured.html
src/tests/empty.ledger_raw
src/tests/empty.ledger_structured
src/tests/full.ledger_raw
src/tests/full.ledger_structured

index fc8964fbe3ef9ac12d608197412dbed970e9f92c..ae06af8be87687c7856898735fa49cc3b98c4026 100644 (file)
@@ -82,7 +82,7 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
 
 
 {% macro ledger_block_columns(mode, block) %}
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>{# keeps the background-color alternation in proper order +#}
     <tr id="block_{{  block.id_ }}">
         <td rowspan={{ block.lines | length + 1 }}
             class="block_column{{ ' critical' if block.date_error }}">
index 08003eecbaac1d6701e17bb4154b63e7bc3faaf8..f66de159b248016440119085f3004906e1bf2c54 100644 (file)
@@ -7,6 +7,9 @@
 table {
     font-family: monospace;
 }
+table > tbody > tr > td.line {
+    white-space-collapse: preserve;
+}
 {% endblock %}
 
 
@@ -20,8 +23,8 @@ table {
 {{ macros.ledger_block_columns('raw', block) -}}
 {##}{% for line in block.lines %}
     <tr>{# -#}
-        <td{{ ' class="critical"'|safe if line.errors }}>
-            {{- line.raw }}&nbsp;{# -#}
+        <td class="line{{ ' critical' if line.errors }}">
+            {{- line.raw or " " -}}
         </td>{# -#}
     </tr>
 {##}{% endfor %}
index dae16b0bd9f42370d2c5cee0f3ae02a54c351737..bf3555adc473b69537c6b901978fea734f6b7155 100644 (file)
@@ -5,6 +5,10 @@
 {% block css %}
 {{ macros.css_ledger() }}
 {{ macros.css_tabular_money() }}
+table > tbody > tr > td.comment {
+    font-family: monospace;
+    white-space-collapse: preserve;
+}
 {% endblock %}
 
 
@@ -18,7 +22,7 @@
 {{ macros.ledger_block_columns('structured', block) -}}
 {##}{% for line in block.gap_lines %}
     <tr>
-        <td colspan=4>{{ line.raw }}&nbsp;</td>
+        <td class="comment" colspan=4>{{ line.raw or " " }}</td>
     </tr>
 {##}{% endfor %}
 {##}{% if block.booking %}
@@ -27,7 +31,7 @@
                         if block.booking.intro_line.errors }}>
             {{- block.booking.date }} {{ block.booking.target -}}
         </td>
-        <td>{{ block.booking.intro_line.comment }}</td>
+        <td class="comment">{{ block.booking.intro_line.comment }}</td>
     </tr>
 {####}{% for line in block.booking.body_lines %}
     <tr>
@@ -41,9 +45,9 @@
         <td{{ ' class="critical"'|safe if line.errors }}>
             {{- line.account -}}
         </td>
-        <td>{{ line.comment }}</td>
+        <td class="comment">{{ line.comment }}</td>
 {######}{% else %}
-        <td colspan=4>{{ line.comment }}</td>
+        <td class="comment" colspan=4>{{ line.comment or " " }}</td>
 {######}{% endif %}
     </tr>
 {####}{% endfor %}
index a479a03c0ad0ee6f6cf330c842656088531b9224..b80423342fbccb54fcd7b66453ee916a7185c46d 100644 (file)
@@ -37,6 +37,9 @@ td.block_column {
 table {
     font-family: monospace;
 }
+table > tbody > tr > td.line {
+    white-space-collapse: preserve;
+}
 </style>
 </head>
 <body>
index 86547816ff0d80403f5cb633de54bb0e5a61fd61..f9384bb7c0c3ed90150113c17f791b47b8d5aec1 100644 (file)
@@ -42,6 +42,10 @@ td.currency {
     font-family: monospace;
     font-size: 1.25em;
 }
+table > tbody > tr > td.comment {
+    font-family: monospace;
+    white-space-collapse: preserve;
+}
 </style>
 </head>
 <body>
@@ -58,7 +62,7 @@ td.currency {
 <form action="/ledger_structured" method="POST">
 <table class="alternating">
 <tbody>
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>
     <tr id="block_0">
         <td rowspan="1" class="block_column">
             <input type="submit" name="ledger_moveup_0" value="^" disabled="">
index 8cd3a0e93ad6bbbe5f00ed7609c8d44f2339ba02..ba988cfce2bb9751fc73ee729d99cdd2b6401e20 100644 (file)
@@ -37,6 +37,9 @@ td.block_column {
 table {
     font-family: monospace;
 }
+table > tbody > tr > td.line {
+    white-space-collapse: preserve;
+}
 </style>
 </head>
 <body>
@@ -70,14 +73,14 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
             [<a href="/edit_raw/0">e</a>]
         </td>
     </tr>
-    <tr><td>;#description bar:x bla bla bla&nbsp;</td></tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>2001-01-01 test  ; foo&nbsp;</td></tr>
-    <tr><td>    ; in-body comment 1&nbsp;</td></tr>
-    <tr><td>    foo    10 €&nbsp;</td></tr>
-    <tr><td>    ; in-body comment 2&nbsp;</td></tr>
-    <tr><td>    bar   -10 €&nbsp;</td></tr>
-    <tr><td>    ; in-body comment 3&nbsp;</td></tr>
+    <tr><td class="line">;#description bar:x bla bla bla</td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line">2001-01-01 test  ; foo</td></tr>
+    <tr><td class="line">    ; in-body comment 1</td></tr>
+    <tr><td class="line">    foo    10 €</td></tr>
+    <tr><td class="line">    ; in-body comment 2</td></tr>
+    <tr><td class="line">    bar   -10 €</td></tr>
+    <tr><td class="line">    ; in-body comment 3</td></tr>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_1">
         <td rowspan="5" class="block_column">
@@ -93,10 +96,10 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
             [<a href="/edit_raw/1">e</a>]
         </td>
     </tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>2001-01-02 test test&nbsp;</td></tr>
-    <tr><td>    bar   -10 €  ; bar&nbsp;</td></tr>
-    <tr><td>    baz    10 €&nbsp;</td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line">2001-01-02 test test</td></tr>
+    <tr><td class="line">    bar   -10 €  ; bar</td></tr>
+    <tr><td class="line">    baz    10 €</td></tr>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_2">
         <td rowspan="6" class="block_column">
@@ -112,11 +115,11 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
             [<a href="/edit_raw/2">e</a>]
         </td>
     </tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>2001-01-02 test&nbsp;</td></tr>
-    <tr><td>    bar    20 €&nbsp;</td></tr>
-    <tr><td>    baz   -20 €  ; baz&nbsp;</td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line">2001-01-02 test</td></tr>
+    <tr><td class="line">    bar    20 €</td></tr>
+    <tr><td class="line">    baz   -20 €  ; baz</td></tr>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_3">
         <td rowspan="7" class="block_column">
@@ -132,12 +135,12 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
             [<a href="/edit_raw/3">e</a>]
         </td>
     </tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>2001-01-03 test&nbsp;</td></tr>
-    <tr><td>    foo:x    10 €&nbsp;</td></tr>
-    <tr><td>    foo:x    1 USD&nbsp;</td></tr>
-    <tr><td>    bar:x:y   -10 €&nbsp;</td></tr>
-    <tr><td>    bar:z   -1 USD&nbsp;</td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line">2001-01-03 test</td></tr>
+    <tr><td class="line">    foo:x    10 €</td></tr>
+    <tr><td class="line">    foo:x    1 USD</td></tr>
+    <tr><td class="line">    bar:x:y   -10 €</td></tr>
+    <tr><td class="line">    bar:z   -1 USD</td></tr>
     <tr></tr><!-- keep the background-color alternation in proper order -->
     <tr id="block_4">
         <td rowspan="9" class="block_column">
@@ -153,14 +156,14 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
             [<a href="/edit_raw/4">e</a>]
         </td>
     </tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>;#description bar:x bla foo bla&nbsp;</td></tr>
-    <tr><td>&nbsp;</td></tr>
-    <tr><td>2001-01-03 test&nbsp;</td></tr>
-    <tr><td>    foo:x    10 €&nbsp;</td></tr>
-    <tr><td>    foo:x    3 USD&nbsp;</td></tr>
-    <tr><td>    bar:x:y   -9 €&nbsp;</td></tr>
-    <tr><td>    bar:z   -1 USD&nbsp;</td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line">;#description bar:x bla foo bla</td></tr>
+    <tr><td class="line"> </td></tr>
+    <tr><td class="line">2001-01-03 test</td></tr>
+    <tr><td class="line">    foo:x    10 €</td></tr>
+    <tr><td class="line">    foo:x    3 USD</td></tr>
+    <tr><td class="line">    bar:x:y   -9 €</td></tr>
+    <tr><td class="line">    bar:z   -1 USD</td></tr>
 </tbody>
 </table>
 </form>
index 6e2774f7ae849f9cdada0d1bf29d96e5adb38d83..0620c5444d8161eddeb48593eff63f25e491f0c1 100644 (file)
@@ -42,6 +42,10 @@ td.currency {
     font-family: monospace;
     font-size: 1.25em;
 }
+table > tbody > tr > td.comment {
+    font-family: monospace;
+    white-space-collapse: preserve;
+}
 </style>
 </head>
 <body>
@@ -60,7 +64,7 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
 <hr>
 <table class="alternating">
 <tbody>
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>
     <tr id="block_0">
         <td rowspan="9" class="block_column">
             <input type="submit" name="ledger_moveup_0" value="^" disabled="">
@@ -76,37 +80,37 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
         </td>
     </tr>
     <tr>
-        <td colspan="4">;#description bar:x bla bla bla&nbsp;</td>
+        <td class="comment" colspan="4">;#description bar:x bla bla bla</td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
         <td colspan="3">2001-01-01 test</td>
-        <td>foo</td>
+        <td class="comment">foo</td>
     </tr>
     <tr>
-        <td colspan="4">in-body comment 1</td>
+        <td class="comment" colspan="4">in-body comment 1</td>
     </tr>
     <tr>
         <td class="amount">10.00</td>
         <td class="currency">€</td>
         <td>foo</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
-        <td colspan="4">in-body comment 2</td>
+        <td class="comment" colspan="4">in-body comment 2</td>
     </tr>
     <tr>
         <td class="amount">-10.00</td>
         <td class="currency">€</td>
         <td>bar</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
-        <td colspan="4">in-body comment 3</td>
+        <td class="comment" colspan="4">in-body comment 3</td>
     </tr>
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>
     <tr id="block_1">
         <td rowspan="5" class="block_column">
             <input type="submit" name="ledger_moveup_1" value="^" disabled="">
@@ -122,25 +126,25 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
         </td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
         <td colspan="3">2001-01-02 test test</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">-10.00</td>
         <td class="currency">€</td>
         <td>bar</td>
-        <td>bar</td>
+        <td class="comment">bar</td>
     </tr>
     <tr>
         <td class="amount">10.00</td>
         <td class="currency">€</td>
         <td>baz</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>
     <tr id="block_2">
         <td rowspan="6" class="block_column">
             <input type="submit" name="ledger_moveup_2" value="^">
@@ -156,28 +160,28 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
         </td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
         <td colspan="3">2001-01-02 test</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">20.00</td>
         <td class="currency">€</td>
         <td>bar</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">-20.00</td>
         <td class="currency">€</td>
         <td>baz</td>
-        <td>baz</td>
+        <td class="comment">baz</td>
     </tr>
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>
     <tr id="block_3">
         <td rowspan="7" class="block_column">
             <input type="submit" name="ledger_moveup_3" value="^" disabled="">
@@ -193,37 +197,37 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
         </td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
         <td colspan="3">2001-01-03 test</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">10.00</td>
         <td class="currency">€</td>
         <td>foo:x</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">1.00</td>
         <td class="currency">USD</td>
         <td>foo:x</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">-10.00</td>
         <td class="currency">€</td>
         <td>bar:x:y</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">-1.00</td>
         <td class="currency">USD</td>
         <td>bar:z</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
-    <tr></tr><!-- keep the background-color alternation in proper order -->
+    <tr></tr>
     <tr id="block_4">
         <td rowspan="9" class="block_column">
             <input type="submit" name="ledger_moveup_4" value="^">
@@ -239,41 +243,41 @@ Detected redundant empty lines in gaps, <input type="submit" name="remove_redund
         </td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
-        <td colspan="4">;#description bar:x bla foo bla&nbsp;</td>
+        <td class="comment" colspan="4">;#description bar:x bla foo bla</td>
     </tr>
     <tr>
-        <td colspan="4">&nbsp;</td>
+        <td class="comment" colspan="4"> </td>
     </tr>
     <tr>
         <td colspan="3">2001-01-03 test</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">10.00</td>
         <td class="currency">€</td>
         <td>foo:x</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">3.00</td>
         <td class="currency">USD</td>
         <td>foo:x</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">-9.00</td>
         <td class="currency">€</td>
         <td>bar:x:y</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
     <tr>
         <td class="amount">-1.00</td>
         <td class="currency">USD</td>
         <td>bar:z</td>
-        <td></td>
+        <td class="comment"></td>
     </tr>
 </tbody>
 </table>