Debian Codegraph @

docs/content/en/render-hooks/blockquotes.md

raw
1 ---
2 title: Blockquote render hooks
3 linkTitle: Blockquotes
4 description: Create blockquote render hook templates to override the rendering of Markdown blockquotes to HTML.
5 categories: []
6 keywords: []
7 ---
8
9 ## Context
10
11 Blockquote _render hook_ templates receive the following [context](g):
12
13 `AlertType`
14 : (`string`) Applicable when [`Type`](#type) is `alert`, this is the alert type converted to lowercase. See the [alerts](#alerts) section below.
15
16 `AlertTitle`
17 : (`template.HTML`) Applicable when [`Type`](#type) is `alert`, this is the alert title. See the [alerts](#alerts) section below.
18
19 `AlertSign`
20 : (`string`) Applicable when [`Type`](#type) is `alert`, this is the alert sign. Typically used to indicate whether an alert is graphically foldable, this is one of `+`, `-`, or an empty string. See the [alerts](#alerts) section below.
21
22 `Attributes`
23 : (`map`) The [Markdown attributes][], available if you configure your site as follows:
24
25 {{< code-toggle file=hugo >}}
26 [markup.goldmark.parser.attribute]
27 block = true
28 {{< /code-toggle >}}
29
30 `Ordinal`
31 : (`int`) The zero-based ordinal of the blockquote on the page.
32
33 `Page`
34 : (`page`) A reference to the current page.
35
36 `PageInner`
37 : (`page`) A reference to a page nested via the [`RenderShortcodes`][] method. [See details](#pageinner-details).
38
39 `Position`
40 : (`string`) The position of the blockquote within the page content.
41
42 `Text`
43 : (`template.HTML`) The blockquote text, excluding the first line if [`Type`](#type) is `alert`. See the [alerts](#alerts) section below.
44
45 `Type`
46 : (`string`) The blockquote type. Returns `alert` if the blockquote has an alert designator, else `regular`. See the [alerts](#alerts) section below.
47
48 ## Examples
49
50 In its default configuration, Hugo renders Markdown blockquotes according to the [CommonMark][] specification. To create a render hook that does the same thing:
51
52 ```go-html-template {file="layouts/_markup/render-blockquote.html" copy=true}
53 <blockquote>
54 {{ .Text }}
55 </blockquote>
56 ```
57
58 To render a blockquote as an HTML `figure` element with an optional citation and caption:
59
60 ```go-html-template {file="layouts/_markup/render-blockquote.html" copy=true}
61 <figure>
62 <blockquote {{ with .Attributes.cite }}cite="{{ . }}"{{ end }}>
63 {{ .Text }}
64 </blockquote>
65 {{ with .Attributes.caption }}
66 <figcaption class="blockquote-caption">
67 {{ . | safeHTML }}
68 </figcaption>
69 {{ end }}
70 </figure>
71 ```
72
73 Then in your markdown:
74
75 ```md
76 > Some text
77 {cite="https://gohugo.io" caption="Some caption"}
78 ```
79
80 ## Alerts
81
82 Also known as _callouts_ or _admonitions_, alerts are blockquotes used to emphasize critical information.
83
84 ### Basic syntax
85
86 With the basic Markdown syntax, the first line of each alert is an alert designator consisting of an exclamation point followed by the alert type, wrapped within brackets. For example:
87
88 ```md {file="content/example.md"}
89 > [!NOTE]
90 > Useful information that users should know, even when skimming content.
91
92 > [!TIP]
93 > Helpful advice for doing things better or more easily.
94
95 > [!IMPORTANT]
96 > Key information users need to know to achieve their goal.
97
98 > [!WARNING]
99 > Urgent info that needs immediate user attention to avoid problems.
100
101 > [!CAUTION]
102 > Advises about risks or negative outcomes of certain actions.
103 ```
104
105 The basic syntax is compatible with [GitHub][], [Obsidian][], and [Typora][].
106
107 ### Extended syntax
108
109 With the extended Markdown syntax, you may optionally include an alert sign and/or an alert title. The alert sign is one of&nbsp;`+`&nbsp;or&nbsp;`-`, typically used to indicate whether an alert is graphically foldable. For example:
110
111 ```md {file="content/example.md"}
112 > [!WARNING]+ Radiation hazard
113 > Do not approach or handle without protective gear.
114 ```
115
116 The extended syntax is compatible with [Obsidian][].
117
118 > [!NOTE]
119 > The extended syntax is not compatible with GitHub or Typora. If you include an alert sign or an alert title, these applications render the Markdown as a blockquote.
120
121 ### Example
122
123 This blockquote render hook renders a multilingual alert if an alert designator is present, otherwise it renders a blockquote according to the CommonMark specification.
124
125 ```go-html-template {file="layouts/_markup/render-blockquote.html" copy=true}
126 {{ $emojis := dict
127 "caution" ":exclamation:"
128 "important" ":information_source:"
129 "note" ":information_source:"
130 "tip" ":bulb:"
131 "warning" ":information_source:"
132 }}
133
134 {{ if eq .Type "alert" }}
135 <blockquote class="alert alert-{{ .AlertType }}">
136 <p class="alert-heading">
137 {{ transform.Emojify (index $emojis .AlertType) }}
138 {{ with .AlertTitle }}
139 {{ . }}
140 {{ else }}
141 {{ or (i18n .AlertType) (title .AlertType) }}
142 {{ end }}
143 </p>
144 {{ .Text }}
145 </blockquote>
146 {{ else }}
147 <blockquote>
148 {{ .Text }}
149 </blockquote>
150 {{ end }}
151 ```
152
153 To override the label, create these entries in your i18n files:
154
155 {{< code-toggle file=i18n/en.toml >}}
156 caution = 'Caution'
157 important = 'Important'
158 note = 'Note'
159 tip = 'Tip'
160 warning = 'Warning'
161 {{< /code-toggle >}}
162
163 Although you can use one template with conditional logic as shown above, you can also create separate templates for each [`Type`](#type) of blockquote:
164
165 ```tree
166 layouts/
167 └── _markup/
168 ├── render-blockquote-alert.html
169 └── render-blockquote-regular.html
170 ```
171
172 {{% include "/_common/render-hooks/pageinner.md" %}}
173
174 [CommonMark]: https://spec.commonmark.org/current/
175 [GitHub]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
176 [Markdown attributes]: /content-management/markdown-attributes/
177 [Obsidian]: https://help.obsidian.md/Editing+and+formatting/Callouts
178 [Typora]: https://support.typora.io/Markdown-Reference/#callouts--github-style-alerts
179 [`RenderShortcodes`]: /methods/page/rendershortcodes/