blockquotes_integration_test.go - hugo - [fork] hugo port for 9front
 (HTM) git clone https://git.drkhsh.at/hugo.git
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Submodules
 (DIR) README
 (DIR) LICENSE
       ---
       blockquotes_integration_test.go (6774B)
       ---
            1 // Copyright 2024 The Hugo Authors. All rights reserved.
            2 //
            3 // Licensed under the Apache License, Version 2.0 (the "License");
            4 // you may not use this file except in compliance with the License.
            5 // You may obtain a copy of the License at
            6 // http://www.apache.org/licenses/LICENSE-2.0
            7 //
            8 // Unless required by applicable law or agreed to in writing, software
            9 // distributed under the License is distributed on an "AS IS" BASIS,
           10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           11 // See the License for the specific language governing permissions and
           12 // limitations under the License.
           13 
           14 package blockquotes_test
           15 
           16 import (
           17         "path/filepath"
           18         "testing"
           19 
           20         "github.com/gohugoio/hugo/hugolib"
           21 )
           22 
           23 func TestBlockquoteHook(t *testing.T) {
           24         t.Parallel()
           25 
           26         files := `
           27 -- hugo.toml --
           28 [markup]
           29   [markup.goldmark]
           30     [markup.goldmark.parser]
           31       [markup.goldmark.parser.attribute]
           32         block = true
           33         title = true
           34 -- layouts/_default/_markup/render-blockquote.html --
           35 Blockquote: |{{ .Text }}|{{ .Type }}|
           36 -- layouts/_default/_markup/render-blockquote-alert.html --
           37 {{ $text := .Text }}
           38 Blockquote Alert: |{{ $text }}|{{ .Type }}|
           39 Blockquote Alert Attributes: |{{ $text }}|{{ .Attributes }}|
           40 Blockquote Alert Page: |{{ $text }}|{{ .Page.Title }}|{{ .PageInner.Title }}|
           41 {{ if .Attributes.showpos }}
           42 Blockquote Alert Position: |{{ $text }}|{{ .Position | safeHTML }}|
           43 {{ end }}
           44 -- layouts/_default/single.html --
           45 Content: {{ .Content }}
           46 -- content/p1.md --
           47 ---
           48 title: "p1"
           49 ---
           50 
           51 > [!NOTE]
           52 > This is a note with some whitespace after the alert type.
           53 
           54 > [!TIP]
           55 > This is a tip.
           56 
           57 >   [!CAUTION]
           58 > This is a caution with some whitespace before the alert type.
           59 
           60 > A regular blockquote.
           61 
           62 > [!TIP]
           63 > This is a tip with attributes.
           64 {class="foo bar" id="baz"}
           65 
           66 > [!NOTE]
           67 > Note triggering showing the position.
           68 {showpos="true"}
           69 
           70 > [!nOtE]
           71 > Mixed case alert type.
           72 `
           73 
           74         b := hugolib.Test(t, files)
           75         b.AssertFileContentExact("public/p1/index.html",
           76                 "Blockquote Alert: |<p>This is a note with some whitespace after the alert type.</p>|alert|",
           77                 "Blockquote Alert: |<p>This is a tip.</p>",
           78                 "Blockquote Alert: |<p>This is a caution with some whitespace before the alert type.</p>|alert|",
           79                 "Blockquote: |<p>A regular blockquote.</p>|regular|",
           80                 "Blockquote Alert Attributes: |<p>This is a tip with attributes.</p>|map[class:foo bar id:baz]|",
           81                 filepath.FromSlash("/content/p1.md:19:3"),
           82                 "Blockquote Alert Page: |<p>This is a tip with attributes.</p>|p1|p1|",
           83 
           84                 // Issue 12767.
           85                 "Blockquote Alert: |<p>Mixed case alert type.</p>|alert",
           86         )
           87 }
           88 
           89 func TestBlockquoteEmptyIssue12756(t *testing.T) {
           90         t.Parallel()
           91 
           92         files := `
           93 -- hugo.toml --
           94 -- content/p1.md --
           95 ---
           96 title: "p1"
           97 ---
           98 
           99 >
          100 -- layouts/_default/single.html --
          101 Content: {{ .Content }}
          102 
          103 `
          104 
          105         b := hugolib.Test(t, files)
          106         b.AssertFileContentExact("public/p1/index.html", "Content: <blockquote>\n</blockquote>\n")
          107 }
          108 
          109 func TestBlockquObsidianWithTitleAndSign(t *testing.T) {
          110         t.Parallel()
          111 
          112         files := `
          113 -- hugo.toml --
          114 -- content/_index.md --
          115 ---
          116 title: "Home"
          117 ---
          118 
          119 > [!danger]
          120 > Do not approach or handle without protective gear.
          121 
          122 > [!tip] Callouts can have custom titles
          123 > Like this one.
          124 
          125 > [!tip] Title-only callout
          126 
          127 > [!faq]- Foldable negated callout
          128 > Yes! In a foldable callout, the contents are hidden when the callout is collapsed
          129 
          130 > [!faq]+ Foldable callout
          131 > Yes! In a foldable callout, the contents are hidden when the callout is collapsed
          132 
          133 > [!info] Can callouts be nested?
          134 > > [!important] Yes!, they can.
          135 > > > [!tip] You can even use multiple layers of nesting.
          136 
          137 -- layouts/index.html --
          138 {{ .Content }}
          139 -- layouts/_default/_markup/render-blockquote.html --
          140 AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|AlertSign: {{ .AlertSign | safeHTML }}|Text: {{ .Text }}|
          141 
          142         `
          143 
          144         b := hugolib.Test(t, files)
          145         b.AssertFileContentExact("public/index.html",
          146                 "AlertType: tip|AlertTitle: Callouts can have custom titles|AlertSign: |",
          147                 "AlertType: tip|AlertTitle: Title-only callout|AlertSign: |",
          148                 "AlertType: faq|AlertTitle: Foldable negated callout|AlertSign: -|Text: <p>Yes! In a foldable callout, the contents are hidden when the callout is collapsed</p>|",
          149                 "AlertType: faq|AlertTitle: Foldable callout|AlertSign: +|Text: <p>Yes! In a foldable callout, the contents are hidden when the callout is collapsed</p>|",
          150                 "AlertType: danger|AlertTitle: |AlertSign: |Text: <p>Do not approach or handle without protective gear.</p>|",
          151                 "AlertTitle: Can callouts be nested?|",
          152                 "AlertTitle: You can even use multiple layers of nesting.|",
          153         )
          154 }
          155 
          156 // Issue 12913
          157 // Issue 13119
          158 // Issue 13302
          159 func TestBlockquoteRenderHookTextParsing(t *testing.T) {
          160         t.Parallel()
          161 
          162         files := `
          163 -- hugo.toml --
          164 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
          165 -- layouts/index.html --
          166 {{ .Content }}
          167 -- layouts/_default/_markup/render-blockquote.html --
          168 AlertType: {{ .AlertType }}|AlertTitle: {{ .AlertTitle }}|Text: {{ .Text }}|
          169 -- content/_index.md --
          170 ---
          171 title: home
          172 ---
          173 
          174 > [!one]
          175 
          176 > [!two] title
          177 
          178 > [!three]
          179 > line 1
          180 
          181 > [!four] title
          182 > line 1
          183 
          184 > [!five]
          185 > line 1
          186 > line 2
          187 
          188 > [!six] title
          189 > line 1
          190 > line 2
          191 
          192 > [!seven]
          193 > - list item
          194 
          195 > [!eight] title
          196 > - list item
          197 
          198 > [!nine]
          199 > line 1
          200 > - list item
          201 
          202 > [!ten] title
          203 > line 1
          204 > - list item
          205 
          206 > [!eleven]
          207 > line 1
          208 > - list item
          209 >
          210 > line 2
          211 
          212 > [!twelve] title
          213 > line 1
          214 > - list item
          215 >
          216 > line 2
          217 
          218 > [!thirteen]
          219 > ![alt](a.jpg)
          220 
          221 > [!fourteen] title
          222 > ![alt](a.jpg)
          223 
          224 > [!fifteen] _title_
          225 
          226 > [!sixteen] _title_
          227 > line one
          228 
          229 > seventeen
          230 `
          231 
          232         b := hugolib.Test(t, files)
          233 
          234         b.AssertFileContent("public/index.html",
          235                 "AlertType: one|AlertTitle: |Text: |",
          236                 "AlertType: two|AlertTitle: title|Text: |",
          237                 "AlertType: three|AlertTitle: |Text: <p>line 1</p>|",
          238                 "AlertType: four|AlertTitle: title|Text: <p>line 1</p>|",
          239                 "AlertType: five|AlertTitle: |Text: <p>line 1\nline 2</p>|",
          240                 "AlertType: six|AlertTitle: title|Text: <p>line 1\nline 2</p>|",
          241                 "AlertType: seven|AlertTitle: |Text: <ul>\n<li>list item</li>\n</ul>|",
          242                 "AlertType: eight|AlertTitle: title|Text: <ul>\n<li>list item</li>\n</ul>|",
          243                 "AlertType: nine|AlertTitle: |Text: <p>line 1</p>\n<ul>\n<li>list item</li>\n</ul>|",
          244                 "AlertType: ten|AlertTitle: title|Text: <p>line 1</p>\n<ul>\n<li>list item</li>\n</ul>|",
          245                 "AlertType: eleven|AlertTitle: |Text: <p>line 1</p>\n<ul>\n<li>list item</li>\n</ul>\n<p>line 2</p>|",
          246                 "AlertType: twelve|AlertTitle: title|Text: <p>line 1</p>\n<ul>\n<li>list item</li>\n</ul>\n<p>line 2</p>|",
          247                 "AlertType: thirteen|AlertTitle: |Text: <p><img src=\"a.jpg\" alt=\"alt\"></p>|",
          248                 "AlertType: fourteen|AlertTitle: title|Text: <p><img src=\"a.jpg\" alt=\"alt\"></p>|",
          249                 "AlertType: fifteen|AlertTitle: <em>title</em>|Text: |",
          250                 "AlertType: sixteen|AlertTitle: <em>title</em>|Text: <p>line one</p>|",
          251                 "AlertType: |AlertTitle: |Text: <p>seventeen</p>|",
          252         )
          253 }