GithubHelp home page GithubHelp logo

Comments (3)

jaredstehler avatar jaredstehler commented on July 19, 2024 1

Implemented as two new parameters on JinjavaConfig... you can enable like:

JinjavaConfig.newBuilder()
  .withLstripBlocks(true)
  .withTrimBlocks(true)
  .build()

206ca3d

from jinjava.

cosmin avatar cosmin commented on July 19, 2024

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.

jaredstehler avatar jaredstehler commented on July 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.