-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Remove whitespace #32
Conversation
{{- range .sources }} | ||
<source srcset="{{ .srcset }}" type="{{ .type }}" /> | ||
{{- end }} | ||
<img class="{{ .className }}" src="{{ .src }}" alt="{{ .alt }}"{{ if .lazyLoading }} loading="lazy"{{ end }}{{ with .naturalHeight }} height="{{ . }}"{{ end }}{{ with .naturalWidth }} width="{{ . }}"{{ end }}{{ with .style }}{{ printf ` style="%s"` (delimit . `; `) | safeHTMLAttr }}{{ end }}{{ if and .original .originalSrc }} data-src="{{ .originalSrc }}"{{ end }}{{ if and .original .originalWidth }} data-width="{{ .originalWidth }}"{{ end }}{{ if and .original .originalHeight }} data-height="{{ .originalHeight }}"{{ end }} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this neccessary? If not, please do not inline it, it's hard to read (review) and maintain the code.
Hugo has --minify
flag to minify the HTML codes, we don't need to take care of this manually (extra whitespaces line break etc.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested with this code:
<picture{{ with .wrapperClass }} class="{{ . }}"{{ end }}>
{{- range .sources }}
<source srcset="{{ .srcset }}" type="{{ .type }}" />
{{- end }}
<img class="{{ .className }}"
src="{{ .src }}"
alt="{{ .alt }}"
{{ if .lazyLoading }}loading="lazy"{{ end }}
{{ with .naturalHeight }}height="{{ . }}"{{ end }}
{{ with .naturalWidth }}width="{{ . }}"{{ end }}
{{ with .style }}{{ printf ` style="%s"` (delimit . `; `) | safeHTMLAttr }}{{ end }}
{{ if and .original .originalSrc }}data-src="{{ .originalSrc }}"{{ end }}
{{ if and .original .originalWidth }} data-width="{{ .originalWidth }}"{{ end }}
{{ if and .original .originalHeight }} data-height="{{ .originalHeight }}"{{ end }} />
</picture>
In this code, I only removed HTML tag indentation.
But this will leave />
appear in render result.
I also removed two whitespace
in front of src=
, alt=
etc. but that didn't make any difference.
I think every whitespace and line break must be removed to prevent this kind of problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please share your use case (how do you use it and reproduce), not sure what cause this.
Could you please provide a real example for reproducing the issue? So that I can confirm and test if this PR have side affect. |
I use Save this as
|
Thanks for your example, will check this later. |
Just tested and reproduced this issue, as you said, it was caused by the indentations and empty line break. Though we can fix this this way, it's not recommend to combine RAW HTML shortcode and Markdown content, in this case,
It will produce unexpected similar issues if the Markdown parser doesn't recognize it correctly. Besides, I don't like to use nested shortcodes recently, you'll noticed that the inner shortcode changes won't be hot-reload, you've to restart server and see the changes. |
Alternatively, to avoid similar issues, you can pass the markdown content to
I don't have ideal solution for this, please share if you found one. But sure, we can fix this issue by merging #33 for this case, I'm looking forward your feedback. |
If shortcode contains whitespace in front of the part where be rendered as HTML, it will cause those codes to be rendered as code block, resulting improperly render result.
So I removed all whitespace for those parts.
Unfortunately, this will make code ugly.
Image comparison
Rendered result without this change:
![1](https://private-user-images.githubusercontent.com/37061801/294891997-3292c2f3-7c35-4fb4-a61d-5ac1a4e331b7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMTY3ODAsIm5iZiI6MTcyMjExNjQ4MCwicGF0aCI6Ii8zNzA2MTgwMS8yOTQ4OTE5OTctMzI5MmMyZjMtN2MzNS00ZmI0LWE2MWQtNWFjMWE0ZTMzMWI3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI3VDIxNDEyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM2MDA1M2ZmYTU5YjExYzI2YTk2NDhiOTgyNGJlYzJiYTlkZTlhMDFlOWVkMWJjZjNiOTYzYjliOGQzMzdmZGUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.S6ciCslBTda2Tv25thJ-zcR_QcDS1g6CRj1BT7sNOKA)
Rendered result with this change:
![2](https://private-user-images.githubusercontent.com/37061801/294892117-80e76f10-ceac-4153-aa8a-c9bd3a075ec4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMTY3ODAsIm5iZiI6MTcyMjExNjQ4MCwicGF0aCI6Ii8zNzA2MTgwMS8yOTQ4OTIxMTctODBlNzZmMTAtY2VhYy00MTUzLWFhOGEtYzliZDNhMDc1ZWM0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI3VDIxNDEyMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTgwYzJiYTg2M2I5MTVjODc2YzExZjVlNTYwM2UyZjUzMWY1N2M0MzllYzA5ZmM0NGIzZDNhMzMzOTVjZDc4ZDQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.jODiO40ByhhXi455ydzne3UuPHq7TktnP11Nvei9M9M)
The only difference is
image.html
andpicture.html
.