[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi] Empty paragraphs in HTML-MST
From: |
Greg Chicares |
Subject: |
[lmi] Empty paragraphs in HTML-MST |
Date: |
Thu, 25 Jul 2019 14:52:33 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.1 |
Motivation: MST files often contain blocks like this example:
<p>{{SampleText}}</p>
which does the right thing if 'SampleText' is nonempty. However,
for certain products, 'SampleText' is deliberately empty, in
which case the example above expands to '<p></p>', printing an
empty paragraph that consumes vertical space [0]. We'd like to
suppress that effect.
One option requires defining a new variable 'SampleTextIsEmpty':
{{#SampleTextIsEmpty}}
<p>{{SampleText}}</p>
{{/SampleTextIsEmpty}}
but that's verbose, and variables should not be multiplied
without necessity.
Before attempting to devise a simpler way, I'd like to ask
whether the observed behavior is necessarily correct. HTML4
suggests the desired behavior (no effect):
https://www.w3.org/TR/REC-html40/struct/text.html#edef-P
| We discourage authors from using empty P elements.
| User agents should ignore empty P elements.
The HTML3 specification (upon which wxHTML is based IIRC)
is less clear:
https://www.w3.org/MarkUp/html3/paras.html
| Do not use empty paragraphs to add white space around
| headings, lists or other elements. White space is added
| by the rendering software.
but would it make sense for wxHTML to ignore empty paragraph
elements, as a runtime option?
If not, then is the tidiest solution to add an extra step
equivalent to
s/<p> *<\/p>//g
to lmi's MST processing?
Here's one particular example, in 'ill_reg_column_headings.mst'
(simplified):
{{#SinglePremium}}
<p>
<b>Ultimate Illustrated Crediting Rate:</b>
{{UltCreditingRateFootnote}}
{{/SinglePremium}}
</p>
Today, some products set <UltCreditingRateFootnote> to
"[specimen text]"
and should print
<p><b>Ultimate Illustrated Crediting Rate:</b>[specimen text]</p>
of course. But now a new product that meets the {{#SinglePremium}}
condition has no distinct "ultimate" rate, and shouldn't have this
footnote. If we just change <UltCreditingRateFootnote> to "", we get
<p><b>Ultimate Illustrated Crediting Rate:</b></p>
which is of course wrong. I'd like to bring the (bold) name of the
term into <UltCreditingRateFootnote> in the '.policy' files:
<UltCreditingRateFootnote>
<strong>Ultimate Illustrated Crediting Rate:</strong>[description]
</UltCreditingRateFootnote>
for the original product that has a non-empty description, but
<UltCreditingRateFootnote/>
for the new product that has no "ultimate" rate (and shouldn't have
such a footnote at all--not even a blank space). Then the MST becomes:
<p>{{UltCreditingRateFootnote}}</p>
where we'd want to remove any resulting empty "<p></p>". Alternatively,
the MST might specify merely:
{{UltCreditingRateFootnote}}
which is terser, but moves markup out of the MST file (and it could be
debated whether that markup is "semantic" or "presentational").
I certainly don't want to introduce a new product-database field like
{DB_HasUltCreditingRate
,DB_Topic_WhoEvenKnows
,"HasUltCreditingRate"
,"Print a footnote describing an ultimate rate: 0=no, 1=yes",}
inducing changes in dozens of source files, hundreds of generated
product files, and a thousand regression-test files; or try to
synthesize a new variable in 'pdf_command_wx.cpp' like
add_variable
("HasUltCreditingRate"
,...analyze 'AnnGAIntRate_Current' to see whether it varies
during some period that cannot actually be defined, which
necessarily makes the footnote's conditional dynamic, but
it has to be static, so...that idea is foredoomed
);
The design inherited from XSL-FO has this conditional:
{{#SinglePremium}}
which is set here:
add_variable
("SinglePremium"
, starts_with(policy_name, "Single")
|| starts_with(policy_name, "Modified")
);
and of course that bletchery could be compounded in a way that
might happen to do the right thing for the new product that has
no "ultimate" rate--but that's like defining
bool CarIsAmerican(char* marque)
{return 'F' == marque[0];}
because 'F' is the first letter of "Ford". Oops--"Fiat":
{return 'F' == marque[0] && 'i' != marque[1];}
Then we add another special case for "Ferrari". Years later,
someone points out that "Chevrolet" doesn't start with "F".
All these funky conditionals must die.
Thus, the product --> HTML --> MST chain is excessively complex
in multiple ways, but we can't eradicate the complexity until
we figure out a clean way to suppress empty <p>footnotes</p>.
---------
[0] "an empty paragraph...consumes vertical space"
Proof: insert the following in an '.mst' file, then use it to
print an illustration.
<p>Here follows one empty paragraph...</p>
<p></p>
<p>...and three empty paragraphs...</p>
<p></p> <p></p> <p></p>
<p>...ending here.</p>
- [lmi] Empty paragraphs in HTML-MST,
Greg Chicares <=