Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control of white space - wider problem #69

Open
finanalyst opened this issue Jan 13, 2022 · 3 comments
Open

Control of white space - wider problem #69

finanalyst opened this issue Jan 13, 2022 · 3 comments

Comments

@finanalyst
Copy link

In #68 I wrote specifically about white space after conditionals. The response there is that conditionals are special cased.

But white space control is a bit deeper for templating languages because there are two forms of white space, namely white space in the template (to help understanding the logic of the template), and white space in the rendered code (to help understanding of the rendered code).

Currently, Crotmp seems to preserve the whitespace in the template except for conditionals, in that conditionals generate no EOL if they produce no content. The same does not seem to be true of other tabs.

Perhaps it might be possible to have explicit white space tags, such as <_> for a space <_t> for a tab or 4 spaces and <_n> for a new line. These are rendered as white space.

Whitespace in the template would then ignored. This seems to me to be more Raku-ish, eg whitespace in a regex.

An example to illustrate the current situation is a template that defines a sub at the top of the template, then calls it later.
It is useful to separate the sub declaration from the rest of the template, but this leads to white space in the rendered template at the top of the file.

<:sub dosomething>
<h1>This is a title</h1>
</:>

<html><body><&dosomething>
Blah blah
</body></html>
@jnthn
Copy link
Member

jnthn commented Jan 13, 2022

I know that, HTML aside, this is being used in places to produce plain-text (for emails), and certainly don't want to regress any such usages that have relied on whitespace pass-through. (I've seen a Latex producing template too, even!)

We could perhaps consider that declarative elements like use, sub and macro will eat all empty lines following them. I'm not really sure we can extend that to conditionals and iteration, however, otherwise folks doing plain text templates will lose whitespace they want But maybe it's enough.

@jnthn
Copy link
Member

jnthn commented Jan 13, 2022

One other thought I had: we could perhaps also have different defaults/settings on this depending on the language being produced. For example, if it's plain text or Latex, we'd not want HTML escaping either. Whitespace handling could also then maybe differ between these.

@finanalyst
Copy link
Author

For legacy reasons, the white space rules for a line would be as now, unless explicitly overwritten by a white space tag.
My experience has been that the white space in a template and the white space mostly maps qite well in to the white space needed for the rendered template. At times, especially for complex iterated sections, it would be nice to have a more explicit way to manage the rendered white space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants