Comments (3)
Implemented as two new parameters on JinjavaConfig
... you can enable like:
JinjavaConfig.newBuilder()
.withLstripBlocks(true)
.withTrimBlocks(true)
.build()
from jinjava.
I looked into this a bit more, and I think it's going to be interesting to implement this in this project. Jinja2 itself accomplishes this because it uses regular expressions to parse blocks, and it modifies the regular expression for the start and end of a block based on the values of trim_blocks
and lstrip_blocks
.
Meanwhile jinjava
does this using a scanner, which I think makes this harder to accomplish.
In theory trim_blocks
could be easily supported by continuing to swallow a newline following the end of a block, but even that is tricky, because you only want blocks {% ... %}
to get this behavior, and not expressions {{ .. }}
, so that alone will requires some work.
However lstrip_blocks
becomes more interesting. As far as I can tell, the TextNode will get all of the whitespace prefixing a block, so there is not much we can do during parsing, without having to either look ahead and see if there will be a block starting on this line, or by going back and altering the text node preceding a block.
In either case I think this will require some work to get right. However, it's still a very critical feature when using this project for whitespace sensitive items. For example, Ansible uses Jinja2 to parse its templates, and it has trim_blocks
enabled by default. There is also a feature request to turn on lstrip_blocks
by default because of all of the issues introduced by not having that turned on. So clearly these are important features at least for some use cases, although I can understand that it probably doesn't apply to what HubSpot needs.
from jinjava.
Agreed that this sounds like a tricky one to implement, but we should be able to come up with a comprehensive test suite for it. I should hopefully get a chance to work on it this week.
from jinjava.
Related Issues (20)
- Update dependencies with vulnerabilities
- Dependency org.yaml:snakeyaml, leading to CVE problem
- for else control structure doesn't seem to be supported HOT 1
- Engine performance HOT 2
- render template that it is contains one '\r\n' string will return more than one
- Can Dict key be an integer? HOT 2
- CVEs in current version: 2.7.0
- time for 2.7.1 / 2.8.0 ?
- Unexpected behavior comparing empty strings to 0
- Is the expression interpolation recursive? HOT 1
- Problem with using the function in nested interpretation HOT 2
- SnakeYAML 1.27 vulnerability in Jinjava 2.7.1 HOT 1
- Add {% hubl %} tag
- Maps in string representation in Сontext
- Support for "with" statement
- Resolve function with map like contructs HOT 1
- Mixing include and extends does not work
- Fix CVEs in version 2.7.1
- Inconsistent implementation with jinja2 HOT 1
- trouble with coercision in test
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jinjava.