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

Incorrect indentation of {{ '<tag>' if condition }} #75

Closed
globau opened this issue Feb 9, 2023 · 2 comments · Fixed by #77
Closed

Incorrect indentation of {{ '<tag>' if condition }} #75

globau opened this issue Feb 9, 2023 · 2 comments · Fixed by #77
Labels
bug Something isn't working

Comments

@globau
Copy link

globau commented Feb 9, 2023

Input

{{ '<b>' if condition }}
some text
{{ '</b>' if condition }}
more text

Actual

{{ '<b>' if condition }}
    some text
    {{ '</b>' if condition }}
more text

Expected (matches formatting when the conditional string doesn't contain an element)

{{ '<b>' if condition }}
some text
{{ '</b>' if condition }}
more text

or (matches formatting when the elements are not conditional)

{{ '<b>' if condition }}
    some text
{{ '</b>' if condition }}
more text
@JaapJoris
Copy link
Member

Thanks for reporting this bug!

Currently, DjHTML has no notion of {{ and }} and just treats them as text. When it sees the <b> tag it thinks it needs to indent. The solution, therefore, is to introduce a new mode InsideTemplateVariable that ignores everything until the closing }}. I don't think it would be that complicated after reading the source and understanding how the other modes work.

Is anyone willing to pick this up and create a PR?

@JaapJoris JaapJoris added bug Something isn't working good first issue Good for newcomers labels Feb 9, 2023
@JaapJoris JaapJoris self-assigned this Feb 13, 2023
@JaapJoris JaapJoris removed the good first issue Good for newcomers label Feb 13, 2023
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
JaapJoris added a commit that referenced this issue Feb 13, 2023
For this release, a substantial part the codebase has been refactored.
Here is a non-exhaustive summary of all the things that have changed:

- Support for Python 3.6 and 3.7 has been dropped
- A Django middleware class to indent HTML responses has been added
- Ignore both opening and closing comment tags
- New handling off both relative and absolute offsets
- Return correct `repr()` strings with the `--debug` option
- New token class "OpenDouble" and a revised indentation algorithm
- Additional `line` argument to `create_token()` methods
- Changed return value of `create_token()` methods
- Changed constructor arguments of Token and Line classes
- Refactored all `create_token()` methods to get rid of return statements
- Simplified test suite runner that reindents the expected output
- Don't indent the contents of template variables (closes #75)
- Improved handling of Django tags inside HTML elements
- Improved JavaScript `case` indentation (closes #76)
- Improved JavaScript method chaining (closes #59)
- Improved CSS multiline statements (closes #74)
- New multiline HTML element indentation (closes #50)
- New multiline HTML attribute value indentation
- Extensive test coverage with lots of edge cases
@JaapJoris JaapJoris removed their assignment Feb 21, 2023
@JaapJoris
Copy link
Member

Thanks again for contributing this bug. DjHTML 3.0.0 has just been released so it has now officially been fixed. Feel free to report more bugs in the future!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants