Hi Armin,
Thank you for the prompt reaction!
> Dropping normalization of newlines altogether however is a bad idea in my
> mind as it causes a lot of troubles when using templates created by
> designers on a windows system on OS X/Linux or the other way round. That was
> the main motivation for the current behavior.
I think you misunderstand me -- the normalization is currently done
twice, which seems unnecessary:
First, different kinds of newlines ('\n', '\r' and '\r\n' in Python)
are replaced by '\n' by
source = '\n'.join(unicode(source).splitlines())
And then again, in _normalize_newlines(), '\n' '\r' and '\r\n' (as
given by newline_re) are replaced with the set newline_sequence.
Dropping the first operation does not change the behaviour except for
preserving the possible final newline (and that is easily added, see
below). Also it probably speeds up and clarifies the parsing a little.
> The reason why it was decided that way is that it does not matter either way
> for most web applications and that most console applications are using the
> print statement for output which appends an trailing newline.
>
> However I would consider a flag that switches that behavior. The following
> modes would make sense:
>
> 1. current behavior. Strip trailing newline
> 2. force final newline
> 3. use newline as specified in the source template.
I guess that dealing with the last newline is not an issue that would
deserve a new flag -- if you ALWAYS strip it and state that in the
docs, that seems like a good solution to me (and is the current
behaviour). Even if you drop the splitlines() line, it can be easily
done in _normalize_newlines(). If somebody (like me ;-) wants
more/less newlines, it is easy to just append them. The current docs
just do not state the current behaviour (nor do they explain how is
newline_sequence used for) and confuse (me) with stating that
whitespace is not touched.
What I would REALLY appreciate would be an option not to touch
whitespace (or other characters) at all. Then it would be easier to
use jinja for non-HTML templates where the newlines and special
characters matter (I frequently use jinja for generating program
code). The flag could be implemented i.e. by allowing newline_sequence
to be None (or '' os some other value) and checking that in
_normalize_newlines() (the variable newline_sequence is not used
anywhere else).
I would gladly provide patches for both the doc, lexer and (possibly)
the preserve-whitespace option.
Best,
Tomas
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.