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

Excessive newlines in head block overriden from decorator #92

Closed
Stummi opened this issue Jan 8, 2016 · 3 comments
Closed

Excessive newlines in head block overriden from decorator #92

Stummi opened this issue Jan 8, 2016 · 3 comments
Assignees
Labels

Comments

@Stummi
Copy link

Stummi commented Jan 8, 2016

I noticed that, when using a decorator and overriding the head block to add resources, there are excessive newlines in the result.

I reduced the issue to a minimal example here:

Layout:

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head>
    <title>Layout</title>
</head>
<body></body>
</html>

Template

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
    xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
    layout:decorator="layout">
<head>
    <title>Test</title>
    <link rel="stylesheet" href="/css/foo.css" />
    <link rel="stylesheet" href="/css/bar.css" />
</head>
<body></body>
</html>

Creates the following result:

<!DOCTYPE html>

<html>
<head>
    <title>Test</title>
    <link rel="stylesheet" href="/css/foo.css" />
    <link rel="stylesheet" href="/css/bar.css" />






</head>
<body></body>
</html>

It seems that three empty lines are created for every line added to the head block.

The official example, shows the same issue for me:

<!DOCTYPE html>

<html>
  <head>
    <title>Content page 1</title>
    <script src="common-script.js"></script>
    <script src="content-script.js"></script>




  </head>
  <body>
    <header>
      <h1>My website</h1>
    </header>
    <section>
      <p>This is a paragraph from content page 1</p>
    </section>
    <footer>
      <p>My footer</p>
      <p>This is some footer content from content page 1</p>
    </footer>  
  </body>
</html>

Using thymeleaf 2.1.4.RELEASE and thymeleaf-layout-dialect 1.3.1

@Stummi
Copy link
Author

Stummi commented Jan 8, 2016

Additional note: While playing around with the versions, it seems that this issue was introduced with version 1.2.9

@ultraq ultraq self-assigned this Feb 9, 2016
@ultraq
Copy link
Owner

ultraq commented Feb 17, 2016

Just had a look into this, and I'm seeing a lot of extra whitespace coming from when I copy over whitespace nodes from the content template into the decorator one. This is during the <head> merging process. /~https://github.com/ultraq/thymeleaf-layout-dialect/blob/master/Source/nz/net/ultraq/thymeleaf/decorators/html/HtmlHeadDecorator.groovy#L101-L105

In versions prior to when this is seen, I copied only other elements. But for work done in issue #70 (released in 1.2.9), I relaxed that and copied over everything.

I might need to add some smarts to exclude copying over whitespace into whitespace, because then it just compounds, leading to this issue.

@ultraq
Copy link
Owner

ultraq commented Feb 18, 2016

Compounding whitespace fixed!

This issue affected anybody using the default 'appending' head merging strategy. If you configured Thymeleaf to use the grouping strategy or implemented your own, you'd likely not encounter this issue.

I've released a 1.3.3-SNAPSHOT version with this fix in the interim.

@ultraq ultraq closed this as completed Feb 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants