Postponed (maintainer needs more info)
Project:
Glossify
Version:
3.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
30 May 2023 at 09:09 UTC
Updated:
19 Dec 2025 at 09:22 UTC
Jump to comment: Most recent

Comments
Comment #2
jacobupal commentedI've deleted the linebreak from my copy of
glossify-link.html.twig/glossify-tooltip.html.twigyet there is still whitespace between the term and any punctuation, is there anything else you did to fix this?Comment #3
jacobupal commentedThis looks promising: Better White Space Control in Twig Templates... but I don't know how that would be implemented.
EDIT:
I think the whitespace is introduced by
Html::serialize($html_dom)on line 199 ofGlossifyBase.phpa process which by default inserts space between the strings being recombined, and if I'm understanding correctly, it's by then just a part of the document, and is the same reason similar whitespace is visible all over the page when you inspect source.The only solution I've got to work is remove the whitespace afterwards with javascript:
To use this I added it to my theme, and adapted the glossify twig template to include the
despace-parentclass.Comment #4
jacobupal commentedOK, my javascript hack above works until... two glossary terms appear next to each-other, in which case the intended whitespace between them is deleted. So annoying... is there any other solution for this?
Comment #5
jacobupal commentedOK it's clearly a hack within a hack but this is my updated script:
It requires that the twig template be something like this:
Your mileage may vary!
Comment #6
jacobupal commentedI haven't tried it yet but it looks like this 'spaceless' option in twig could be a useful alternative that would let me do away with using javascript to do this: https://twig.symfony.com/doc/3.x/filters/spaceless.html
Comment #7
tgoeg commentedI don't think that's correct.
$html_domor even$wordbefore already has that extra space.If you enable twig debugging, that is.
At least that's the problem in my case. Disabling debug mode makes the problem go away.
It is caused by the ending tag
.
And I explicitly added a newline here, before the comment, as that is what Drupal core does as well.
This very newline causes the whitespace to be inserted.
The following patch for Drupal core fixes it for me (as it does in several other cases where debug mode manipulates the DOM in such a way that it causes differences in rendering.
Adding this to #2914733: [META] twig debug can break parts of site as well.
Comment #8
jacobupal commentedGood to hear! This might have changed through updates since I first resorted to javascript, as I am pretty sure the problem was persisting when twig-debug was disabled.
I am looking forward to trying that patch!
Comment #9
anybodyHi and thank you for the report. It's not yet clear to me, what needs to happen here and how to reproduce this. Could you update the issue summary with clear steps please?
So is this similar to: #3251765: Twig debug mode causes parse error in appendXML just with another effect?
Or is an implementation of https://twig.symfony.com/doc/3.x/filters/spaceless.html needed in the twig file?
Happy to review fixes as MR.
Comment #10
tgoeg commentedI don't know if you addressed me, but IMHO the problem lies within core's way of inserting debugging comments itself.
There is an ongoing debate of whether enabling debug mode can be expected to give the same (rendered) results as when disabling it. And some core devs seem to be reluctant to accept any changes regarding the current markup as a site is expected to possibly fail when debugging is enabled.
I'd change core's debugging functionality as I showed above, as it doesn't hurt but fixes a few issues (on my side at least).
Depending on whether this is the way to go there is either nothing to do here or some additional workaround has to be implemented to get rid of those extraneous newlines.
Although I don't see #3251765: Twig debug mode causes parse error in appendXML in my installation, it seems very much related and both ways of fixing it outlined above may be a possible solution for it as well.
Comment #11
tgoeg commentedI found an additional solution in my notes.
However, I cannot tell you how or why this works.
I definitely had a bright moment when implementing this :-)
This is needed additionally to the fix in core mentioned above for this edge case (the very bug OP describes; sorry, we drifted away to more general cases).
The fact that debugging mode does not lead to problems when terms are followed by space characters is caused by the browser reducing multiple space chars to one.
Comment #12
jacobupal commentedI can confirm now that on a clean install of 10.3.x using DrupalPod that toggling twig debugging (through the UI/config) does indeed result in that extra space appearing and disappearing.
So the problem, as it exists now, is not with glossify but with the twig debugging implementation, just as you suggested @tgoeg
Any line-break issues I am able to reproduce now while the twig-debugging is turned off are associated with my custom template, so again, not strictly glossify's problem.
I do think that there were initially factors other than twig-debugging at-play earlier on in the timeline - both because in @mjgruta'a OP we can see their devtools in the screenshot, and there's no debugging markup there, and because they seem to have been saying that when they deleted the empty line (which is part of Drupal's coding standards) the white-space went away, which wouldn't make sense if the cause had always been twig debugging.
Also, that same solution just over 2 months later, presumably with a different drupal version, didn't work for me in 2023.
I have the impression that some thing(s) outside of the module, in twig or in core, have been changed or improved since this issue was created, leading to some of our confusion. And it'd be worth keeping an eye on anything in core which might affect this.
If this does come back again for anybody else who ends up down the same path as me, I can say that the whitespace went away (with debugging off) when I did any of the following:
glossify-link.html.twigglossify-link.html.twigonly contained nested elements.glossify-link.html.twighad a wrapper element with no whitespace between the nested elements.Sadly including the extra comment as suggested by @tgoeg made no difference to the extra whitespace when debugging was turned on.
But if it's all working now, apart from the debugging issue, maybe deserves its own issue in core, and there is little to be done on this issue?
Comment #13
jacobupal commentedComment #14
grevil commentedIs this still an issue on the latest dev release?
Comment #15
tgaugesI created the core issue #3563677: Twig debug can influence rendering visually due to whitespace between tags and implemented a fix similar to #7.