2024-08-05 10:51:16 -04:00
// Copyright 2024 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 blockquotes_test
import (
"path/filepath"
"testing"
"github.com/gohugoio/hugo/hugolib"
)
func TestBlockquoteHook ( t * testing . T ) {
t . Parallel ( )
files := `
-- hugo . toml --
[ markup ]
[ markup . goldmark ]
[ markup . goldmark . parser ]
[ markup . goldmark . parser . attribute ]
block = true
title = true
-- layouts / _default / _markup / render - blockquote . html --
2024-08-31 11:25:15 -04:00
Blockquote : | { { . Text } } | { { . Type } } |
2024-08-05 10:51:16 -04:00
-- layouts / _default / _markup / render - blockquote - alert . html --
2024-08-31 11:25:15 -04:00
{ { $ text := . Text } }
2024-08-05 10:51:16 -04:00
Blockquote Alert : | { { $ text } } | { { . Type } } |
Blockquote Alert Attributes : | { { $ text } } | { { . Attributes } } |
Blockquote Alert Page : | { { $ text } } | { { . Page . Title } } | { { . PageInner . Title } } |
{ { if . Attributes . showpos } }
Blockquote Alert Position : | { { $ text } } | { { . Position | safeHTML } } |
{ { end } }
-- layouts / _default / single . html --
Content : { { . Content } }
-- content / p1 . md --
-- -
title : "p1"
-- -
> [ ! NOTE ]
> This is a note with some whitespace after the alert type .
> [ ! TIP ]
> This is a tip .
> [ ! CAUTION ]
> This is a caution with some whitespace before the alert type .
> A regular blockquote .
> [ ! TIP ]
> This is a tip with attributes .
{ class = "foo bar" id = "baz" }
> [ ! NOTE ]
> Note triggering showing the position .
{ showpos = "true" }
2024-08-14 10:57:18 -04:00
> [ ! nOtE ]
> Mixed case alert type .
2024-08-05 10:51:16 -04:00
`
b := hugolib . Test ( t , files )
2024-09-01 12:25:10 -04:00
b . AssertFileContentExact ( "public/p1/index.html" ,
2024-08-05 10:51:16 -04:00
"Blockquote Alert: |<p>This is a note with some whitespace after the alert type.</p>\n|alert|" ,
"Blockquote Alert: |<p>This is a tip.</p>" ,
"Blockquote Alert: |<p>This is a caution with some whitespace before the alert type.</p>\n|alert|" ,
"Blockquote: |<p>A regular blockquote.</p>\n|regular|" ,
"Blockquote Alert Attributes: |<p>This is a tip with attributes.</p>\n|map[class:foo bar id:baz]|" ,
filepath . FromSlash ( "/content/p1.md:20:3" ) ,
"Blockquote Alert Page: |<p>This is a tip with attributes.</p>\n|p1|p1|" ,
2024-08-14 10:57:18 -04:00
// Issue 12767.
"Blockquote Alert: |<p>Mixed case alert type.</p>\n|alert" ,
2024-08-05 10:51:16 -04:00
)
}
2024-08-13 04:58:59 -04:00
func TestBlockquoteEmptyIssue12756 ( t * testing . T ) {
t . Parallel ( )
files := `
-- hugo . toml --
-- content / p1 . md --
-- -
title : "p1"
-- -
>
-- layouts / _default / single . html --
Content : { { . Content } }
`
b := hugolib . Test ( t , files )
2024-09-01 12:25:10 -04:00
b . AssertFileContentExact ( "public/p1/index.html" , "Content: <blockquote>\n</blockquote>\n" )
2024-08-13 04:58:59 -04:00
}
2024-09-01 06:00:13 -04:00
func TestBlockquObsidianWithTitleAndSign ( t * testing . T ) {
t . Parallel ( )
files := `
-- hugo . toml --
-- content / _index . md --
-- -
title : "Home"
-- -
> [ ! danger ]
> Do not approach or handle without protective gear .
> [ ! tip ] Callouts can have custom titles
> Like this one .
> [ ! tip ] Title - only callout
> [ ! faq ] - Foldable negated callout
> Yes ! In a foldable callout , the contents are hidden when the callout is collapsed
> [ ! faq ] + Foldable callout
> Yes ! In a foldable callout , the contents are hidden when the callout is collapsed
2024-09-05 04:46:47 -04:00
> [ ! info ] Can callouts be nested ?
> > [ ! important ] Yes ! , they can .
> > > [ ! tip ] You can even use multiple layers of nesting .
2024-09-01 06:00:13 -04:00
-- layouts / index . html --
{ { . Content } }
-- layouts / _default / _markup / render - blockquote . html --
2024-09-01 12:25:10 -04:00
AlertType : { { . AlertType } } | AlertTitle : { { . AlertTitle } } | AlertSign : { { . AlertSign | safeHTML } } | Text : { { . Text } } |
2024-09-01 06:00:13 -04:00
`
b := hugolib . Test ( t , files )
2024-09-01 12:25:10 -04:00
b . AssertFileContentExact ( "public/index.html" ,
"AlertType: tip|AlertTitle: Callouts can have custom titles|AlertSign: |" ,
2024-09-05 04:46:47 -04:00
"AlertType: tip|AlertTitle: Title-only callout|AlertSign: |" ,
"AlertType: faq|AlertTitle: Foldable negated callout|AlertSign: -|Text: <p>Yes! In a foldable callout, the contents are hidden when the callout is collapsed</p>\n|" ,
"AlertType: faq|AlertTitle: Foldable callout|AlertSign: +|Text: <p>Yes! In a foldable callout, the contents are hidden when the callout is collapsed</p>\n|" ,
2024-09-01 12:25:10 -04:00
"AlertType: danger|AlertTitle: |AlertSign: |Text: <p>Do not approach or handle without protective gear.</p>\n|" ,
2024-09-05 04:46:47 -04:00
"AlertTitle: Can callouts be nested?|" ,
"AlertTitle: You can even use multiple layers of nesting.|" ,
2024-09-01 06:00:13 -04:00
)
}