// Copyright 2025 The Hugo Authors. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package tplimpl_test import ( "strings" "testing" "github.com/gohugoio/hugo/htesting/hqt" "github.com/gohugoio/hugo/hugolib" ) func TestCommentShortcode(t *testing.T) { t.Parallel() files := ` -- hugo.toml -- disableKinds = ['page','rss','section','sitemap','taxonomy','term'] -- layouts/index.html -- {{ .Content }} -- content/_index.md -- --- title: home --- a{{< comment >}}b{{< /comment >}}c ` b := hugolib.Test(t, files, hugolib.TestOptWarn()) b.AssertFileContent("public/index.html", "
ac
") b.AssertLogContains(`WARN The "comment" shortcode was deprecated in v0.143.0 and will be removed in a future release. Please use HTML comments instead.`) } func TestDetailsShortcode(t *testing.T) { t.Parallel() files := ` -- hugo.toml -- disableKinds = ['page','rss','section','sitemap','taxonomy','term'] -- layouts/index.html -- {{ .Content }} -- content/_index.md -- --- title: home --- {{< details >}} A: An _emphasized_ word. {{< /details >}} {{< details class="my-class" name="my-name" open=true summary="A **bold** word" title="my-title" >}} B: An _emphasized_ word. {{< /details >}} {{< details open=false >}} C: An _emphasized_ word. {{< /details >}} {{< details open="false" >}} D: An _emphasized_ word. {{< /details >}} {{< details open=0 >}} E: An _emphasized_ word. {{< /details >}} ` b := hugolib.Test(t, files) b.AssertFileContent("public/index.html", "A: An emphasized word.
\nB: An emphasized word.
\nC: An emphasized word.
\nD: An emphasized word.
\nD: An emphasized word.
\n` b.AssertFileContent("public/p1/index.html", want) htmlFiles := []string{ b.FileContent("public/p1/index.html"), b.FileContent("public/p2/index.html"), b.FileContent("public/p3/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) // Test x_simple and twitter_simple shortcodes wantSimple := "Owl bet you'll lose this staring contest 🦉 pic.twitter.com/eJh4f2zncC
— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021
\n--" b.AssertFileContent("public/p4/index.html", wantSimple) htmlFiles = []string{ b.FileContent("public/p4/index.html"), b.FileContent("public/p5/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) filesOriginal := files // Test privacy.twitter.simple files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.twitter.simple=true") b = hugolib.Test(t, files) htmlFiles = []string{ b.FileContent("public/p2/index.html"), b.FileContent("public/p3/index.html"), b.FileContent("public/p5/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) // Test privacy.x.simple files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.x.simple=true") b = hugolib.Test(t, files) htmlFiles = []string{ b.FileContent("public/p1/index.html"), b.FileContent("public/p4/index.html"), b.FileContent("public/p4/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) htmlFiles = []string{ b.FileContent("public/p2/index.html"), b.FileContent("public/p3/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) // Test privacy.twitter.disable files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.twitter.disable = true") b = hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "") htmlFiles = []string{ b.FileContent("public/p1/index.html"), b.FileContent("public/p2/index.html"), b.FileContent("public/p3/index.html"), b.FileContent("public/p4/index.html"), b.FileContent("public/p4/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) // Test privacy.x.disable files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.x.disable = true") b = hugolib.Test(t, files) b.AssertFileContent("public/p1/index.html", "") htmlFiles = []string{ b.FileContent("public/p1/index.html"), b.FileContent("public/p4/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) htmlFiles = []string{ b.FileContent("public/p2/index.html"), b.FileContent("public/p3/index.html"), } b.Assert(htmlFiles, hqt.IsAllElementsEqual) // Test warnings files = ` -- hugo.toml -- disableKinds = ['page','rss','section','sitemap','taxonomy','term'] -- content/_index.md -- --- title: home --- {{< x user="__user_does_not_exist__" id="__id_does_not_exist__" >}} {{< x_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}} {{< twitter user="__user_does_not_exist__" id="__id_does_not_exist__" >}} {{< twitter_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}} -- layouts/index.html -- {{ .Content }} ` b = hugolib.Test(t, files, hugolib.TestOptWarn()) b.AssertLogContains( `WARN The "x" shortcode was unable to retrieve the remote data.`, `WARN The "x_simple" shortcode was unable to retrieve the remote data.`, `WARN The "twitter", "tweet", and "twitter_simple" shortcodes were deprecated in v0.142.0 and will be removed in a future release.`, `WARN The "twitter" shortcode was unable to retrieve the remote data.`, `WARN The "twitter_simple" shortcode was unable to retrieve the remote data.`, ) }Owl bet you'll lose this staring contest 🦉 pic.twitter.com/eJh4f2zncC
— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021