lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Empty paragraphs in HTML-MST


From: Vadim Zeitlin
Subject: Re: [lmi] Empty paragraphs in HTML-MST
Date: Fri, 26 Jul 2019 00:22:17 +0200

On Thu, 25 Jul 2019 14:52:33 +0000 Greg Chicares <address@hidden> wrote:

GC> Motivation: MST files often contain blocks like this example:
GC>   <p>{{SampleText}}</p>
GC> which does the right thing if 'SampleText' is nonempty. However,
GC> for certain products, 'SampleText' is deliberately empty, in
GC> which case the example above expands to '<p></p>', printing an
GC> empty paragraph that consumes vertical space [0]. We'd like to
GC> suppress that effect.

 Yes, I remember thinking that it would be nice to have some way of doing
this (and maybe not only for <p> tags) when first working in this code and
deciding that it wasn't critical enough and so could be postponed. I guess
the time has come to finally address this.


GC> Before attempting to devise a simpler way, I'd like to ask
GC> whether the observed behavior is necessarily correct.

 I think it may be considered correct, i.e. it's not clearly incorrect, but
this is not the most salient point. More important, IMO, is that
wxHtmlWindow has always behaved like this, and that changing this by
default would almost certainly break existing applications. I know that
you've suggested an option for ignoring it, but we don't have any such
options now and I'm really not sure we want to start adding them.

GC> If not, then is the tidiest solution to add an extra step
GC> equivalent to
GC>   s/<p> *<\/p>//g
GC> to lmi's MST processing?

 I see 2 ways to do it, globally:

1. Avoid generating <p></p> in the HTML in the first place.
2. Keep generating <p></p> but render it as nothing.

 I haven't tested it yet, but I think (2) should be doable, and purely in
lmi code, i.e. without any wxHTML modifications: we already use a custom
tag handler for <p>, so we could just remember every wxHtmlCell we create
in this handler and then, after finishing generating, go through the list
of all these cells and either remove them entirely or just reset the
margins used around them (which is what, I'm 99% certain, accounts for the
space taken by empty paragraphs).

 However I think (1) would be nicer, both because it seems more elegant and
because it would work for all tags, not just <p>. But implementing this
would be more involved, I think (although I could be wrong if I run into
some trouble with the approach outlined above), as it would require us to
finally add support for some kind of functions/helpers to our MST syntax.
In fact, pure Mustache does support functions using the same syntax we
already use for sections, e.g. we could implement support for something
like

        {{#WrapInP}}{{UltCreditingRateFootnote}}{{/WrapInP}}

where WrapInP() would be mapped to a function defined in C++ code that
would simply return "<p> + input + </p>" if input is non-empty and an empty
string otherwise. But if this looks too heavy, we could implement support
for something like

        {{WrapInP UltCreditingRateFootnote}}

or

        {{UltCreditingRateFootnote|WrapInP}}

instead (both syntaxes are not really standard but used in some templating
system or other, so not totally unfamiliar neither).

 I believe that (2) would make more sense, especially if we want to use
functions in other cases, e.g. for abbreviating the value to some number of
characters. But if you need something immediately right now, (1) might be
faster to put in place.

 Please let me know what do you think,
VZ

Attachment: pgp33nOVyciR9.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]