- 🇹🇭Thailand Nick Hope
@jwilson3 The issue you added was already 2nd in the list.
- 🇦🇹Austria tgoeg
Chiming in here and adding another case where this causes problems: 🐛 newline on glossify-link.html.twig causes extra space Active .
I also had this in a custom theme when checking whether a field is empty (which it was, but not when the debug code inserts newlines).This does not only cause problems in non-HTML output as the RSS output might imply.
All of my problems got fixed by the following patch and I think it does more good than bad, so I think it could be included in core.
Current firefox and chromium add newlines to comments in developer tools anyway, so this does not really cause any disadvantage for developers, I think, and it really fixes problems on a lot of places (in my case).
Applies against Drupal 10.1
--- /core/themes/engines/twig/twig.engine.org 2024-05-08 16:37:50.990994524 +0000 +++ /core/themes/engines/twig/twig.engine 2024-05-08 16:38:47.900186459 +0000 @@ -63,8 +63,8 @@ throw $e; } if ($twig_service->isDebug()) { - $output['debug_prefix'] .= "\n\n<!-- THEME DEBUG -->"; - $output['debug_prefix'] .= "\n<!-- THEME HOOK: '" . Html::escape($variables['theme_hook_original']) . "' -->"; + $output['debug_prefix'] .= "<!-- THEME DEBUG -->"; + $output['debug_prefix'] .= "<!-- THEME HOOK: '" . Html::escape($variables['theme_hook_original']) . "' -->"; // If there are theme suggestions, reverse the array so more specific // suggestions are shown first. if (!empty($variables['theme_hook_suggestions'])) { @@ -106,17 +106,17 @@ $prefix = ($template == $current_template) ? 'x' : '*'; $suggestion = $prefix . ' ' . $template; } - $output['debug_info'] .= "\n<!-- FILE NAME SUGGESTIONS:\n " . Html::escape(implode("\n ", $suggestions)) . "\n-->"; + $output['debug_info'] .= "<!-- FILE NAME SUGGESTIONS:\n " . Html::escape(implode("\n ", $suggestions)) . "-->"; if (!empty($invalid_suggestions)) { - $output['debug_info'] .= "\n<!-- INVALID FILE NAME SUGGESTIONS:"; - $output['debug_info'] .= "\n See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme_suggestions_alter"; - $output['debug_info'] .= "\n " . Html::escape(implode("\n ", $invalid_suggestions)); - $output['debug_info'] .= "\n-->"; + $output['debug_info'] .= "<!-- INVALID FILE NAME SUGGESTIONS:"; + $output['debug_info'] .= " See https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!theme.api.php/function/hook_theme_suggestions_alter"; + $output['debug_info'] .= " " . Html::escape(implode("\n ", $invalid_suggestions)); + $output['debug_info'] .= "-->"; } } - $output['debug_info'] .= "\n<!-- BEGIN OUTPUT from '" . Html::escape($template_file) . "' -->\n"; - $output['debug_suffix'] .= "\n<!-- END OUTPUT from '" . Html::escape($template_file) . "' -->\n\n"; + $output['debug_info'] .= "<!-- BEGIN OUTPUT from '" . Html::escape($template_file) . "' -->"; + $output['debug_suffix'] .= "<!-- END OUTPUT from '" . Html::escape($template_file) . "' -->"; } // This output has already been rendered and is therefore considered safe. return Markup::create(implode('', $output));