From d57bf31a356fb0d5e5fba821c8f70e62025de9e6 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Wed, 21 Jan 2026 14:09:16 -0400 Subject: [PATCH] Fix incorrect `template` HTML tag rendering in `src/html` Signed-off-by: Juan Cruz Viotti --- .../html/include/sourcemeta/core/html_elements.h | 13 ++++++++----- test/html/html_encoder_test.cc | 8 ++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/html/include/sourcemeta/core/html_elements.h b/src/core/html/include/sourcemeta/core/html_elements.h index 7eacddfa5..a72182657 100644 --- a/src/core/html/include/sourcemeta/core/html_elements.h +++ b/src/core/html/include/sourcemeta/core/html_elements.h @@ -12,21 +12,23 @@ namespace sourcemeta::core::html { return HTML(#name, std::move(attributes), true); \ } -#define HTML_CONTAINER_ELEMENT(name) \ +#define HTML_CONTAINER_ELEMENT_NAMED(name, tag) \ inline auto name(HTMLAttributes attributes) -> HTML { \ - return HTML(#name, std::move(attributes)); \ + return HTML(#tag, std::move(attributes)); \ } \ template \ inline auto name(HTMLAttributes attributes, Children &&...children) \ -> HTML { \ - return HTML(#name, std::move(attributes), \ + return HTML(#tag, std::move(attributes), \ std::forward(children)...); \ } \ template \ inline auto name(Children &&...children) -> HTML { \ - return HTML(#name, std::forward(children)...); \ + return HTML(#tag, std::forward(children)...); \ } +#define HTML_CONTAINER_ELEMENT(name) HTML_CONTAINER_ELEMENT_NAMED(name, name) + #define HTML_COMPACT_ELEMENT(name) \ inline auto name(HTMLAttributes attributes) -> HTML { \ return HTML(#name, std::move(attributes)); \ @@ -433,11 +435,12 @@ HTML_CONTAINER_ELEMENT(summary) HTML_CONTAINER_ELEMENT(slot) /// @ingroup html -HTML_CONTAINER_ELEMENT(template_) +HTML_CONTAINER_ELEMENT_NAMED(template_, template) #ifndef DOXYGEN #undef HTML_VOID_ELEMENT #undef HTML_CONTAINER_ELEMENT +#undef HTML_CONTAINER_ELEMENT_NAMED #undef HTML_COMPACT_ELEMENT #undef HTML_VOID_ATTR_ELEMENT #endif diff --git a/test/html/html_encoder_test.cc b/test/html/html_encoder_test.cc index 9b88c9e41..d55022a21 100644 --- a/test/html/html_encoder_test.cc +++ b/test/html/html_encoder_test.cc @@ -435,3 +435,11 @@ TEST(HTML_encoder, push_back_return_reference) { EXPECT_EQ(&ref, &element); } + +TEST(HTML_encoder, template_element_tag_name) { + using namespace sourcemeta::core::html; + + EXPECT_EQ(template_("Content").render(), ""); + EXPECT_EQ(template_({{"id", "my-template"}}, "Content").render(), + ""); +}