Sylvain Brunerie wrote:
Hi,
Is there a way to insert into a page real HTML comments ? I mean, HTML-style
comments like <!-- ... --> are stripped on rendering the page. I'd like to
insert comments staying as comments in the source code of the generated
page.
The main reason why comments are completely removed, rather than replaced
with a marker and later re-inserted, is that in various contexts, users
expect comments to have no syntactical impact whatsoever, and a strip
marker would interfere with this, without invasive changes to many points
of the parser. For instance:
{{ #if: <!-- param empty? --> {{{param|}} | yes | no }}
The comment is removed, which means that the parameter interacts with the
#if in an intuitive way.
This behaviour provides a challenge for the pre-save transform (PST),
where templates are required to be expanded, and comments are re-inserted
unchanged. The current situation with the PST is that comments are
completely removed in certain safe special cases, with bugs exposed in the
remaining cases.
There's no reason why an extension couldn't add an xmlish tag, like
<htmlcomment>, which inserts an HTML comment and protects against IE
conditional comments and similar constructs as appropriate. But unless
someone can come up with an important application, I don't think it needs
to be in the core.
-- Tim Starling