diff --git a/core/includes/theme.inc b/core/includes/theme.inc index d75fbd7..f2cae6e 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -659,7 +659,7 @@ function _theme_build_registry($theme, $base_theme, $theme_engine) { * their base theme), direct sub-themes of sub-themes, etc. The keys are * the themes' machine names, and the values are the themes' human-readable * names. This element is not set if there are no themes on the system that - * declare this theme as their base theme. + * declare this theme as their base theme. */ function list_themes($refresh = FALSE) { $list = &drupal_static(__FUNCTION__, array()); @@ -2135,6 +2135,8 @@ function theme_feed_icon($variables) { * - meta: To provide meta information, such as a page refresh. * - link: To refer to stylesheets and other contextual information. * - script: To load JavaScript. + * - #newline: TRUE if a newline character should be appended to the end of + * the tag. Defaults to TRUE. * - #attributes: (optional) An array of HTML attributes to apply to the * tag. * - #value: (optional) A string containing tag content, such as inline CSS. @@ -2146,8 +2148,9 @@ function theme_feed_icon($variables) { function theme_html_tag($variables) { $element = $variables['element']; $attributes = isset($element['#attributes']) ? drupal_attributes($element['#attributes']) : ''; + $output = ''; if (!isset($element['#value'])) { - return '<' . $element['#tag'] . $attributes . " />\n"; + $output = '<' . $element['#tag'] . $attributes . ' />'; } else { $output = '<' . $element['#tag'] . $attributes . '>'; @@ -2158,9 +2161,13 @@ function theme_html_tag($variables) { if (isset($element['#value_suffix'])) { $output .= $element['#value_suffix']; } - $output .= '\n"; - return $output; + $output .= ''; + } + $newline = isset($element['#newline']) ? $element['#newline'] : TRUE; + if (!empty($output) && $newline) { + $output .= "\n"; } + return $output; } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/HtmlTagUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/HtmlTagUnitTest.php index d359038..c5fda8a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Theme/HtmlTagUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Theme/HtmlTagUnitTest.php @@ -32,5 +32,9 @@ class HtmlTagUnitTest extends UnitTestBase { // Test title tag generation $tag['element'] = array('#tag' => 'title', '#value' => 'title test'); $this->assertEqual('title test'."\n", theme_html_tag($tag), t('Test title tag generation.')); + + // Test span tag generation without trailing newline. + $tag['element'] = array('#tag' => 'span', '#newline' => FALSE, '#value' => 'span test'); + $this->assertEqual('span test', theme_html_tag($tag), t('Test span tag generation without newline.')); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index a530c30..4fb82a0 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -316,6 +316,7 @@ function system_element_info() { '#pre_render' => array('drupal_pre_render_conditional_comments'), '#attributes' => array(), '#value' => NULL, + '#newline' => TRUE, ); $types['styles'] = array( '#items' => array(),