a49697e53 Add private use subtag requirements to multilingual page a5c6bb4da Add INFINI Pizza search engine 45b732efa Fix template lookup order for AMP pages 30c672d0b netlify: Hugo 0.133.1 7c766e724 Update page resources documentation ca802fbec Document how to enable AsciiDoc syntax highlighting c3350f4cf Update definition of falsy to include zero time.Time values b0e5ab051 Fir typo 60f6cb63b Update migrations.md ec52c7ba1 Improve formatting of example code e5681ad01 Improve formatting of example code bdf3ffc73 Clarify the various next/prev methods b5505d22a Clarify template lookup order for shortcodes cf8dd7034 Improve embedded.md e5dee2651 Update transform.ToMath 4d419a128 Update pagination configuration to use new struct 05d4fd597 Update PrevInSection.md fd33370ed Add new-in 0.133.0 f9062042f Add the new page config section 205645e97 Remove out-dated new-in 3ed3673f7 Fix typo 41df91659 Document the 'else with' construct introduced with Go 1.23 9c4697ab3 netlify: Hugo 0.133.0 62506b052 Merge branch 'temp133' 877e1bfcd Add config options page.nextPrevSortOrder/nextPrevInSectionSortOrder eb159fe62 Update menu.md efa7795a0 Update theme dbe8911ad netlify: Hugo 0.132.2 2f793d328 Document passthrough render hooks a7ce9a5e8 netlify: Hugo 0.132.1 2c137cb48 Update blockquotes.md e0fa2f0d1 Add new-in badge to blockquote render hook page bf42bbe6b Update references to render hooks 85a3d9958 Update theme 2dae72128 Document blockquote render hooks 8f5afb55d Update plainify return type 160f22d0e netlify: Hugo 0.132.0 82b5586fb Document transform.ToMath 1efcbcddb tpl/transform: Make Plainify and ToMath return template.HTML 31727be2e docs: Regen docshelper 88a421426 Merge commit 'a6e635ca7d905d9ec3ffd708db2694f680b03aae' git-subtree-dir: docs git-subtree-split: a49697e536ee0d477ab4e552cfa8dc74debeff27
4.5 KiB
Executable file
title | linkTitle | description | categories | keywords | menu | weight | toc | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Blockquote render hooks | Blockquotes | Create a blockquote render hook to override the rendering of Markdown blockquotes to HTML. |
|
|
30 | true |
{{< new-in 0.132.0 >}}
Context
Blockquote render hook templates receive the following context:
AlertType
(string
) Applicable when Type
is alert
, this is the alert type converted to lowercase. See the alerts section below.
Attributes
(map
) The Markdown attributes, available if you configure your site as follows:
{{< code-toggle file=hugo >}} [markup.goldmark.parser.attribute] block = true {{< /code-toggle >}}
Ordinal
(int
) The zero-based ordinal of the blockquote on the page.
Page
(page
) A reference to the current page.
PageInner
(page
) A reference to a page nested via the RenderShortcodes
method.
Position
(string
) The position of the blockquote within the page content.
Text
(string
) The blockquote text, excluding the alert designator if present. See the alerts section below.
Type
(bool
) The blockquote type. Returns alert
if the blockquote has an alert designator, else regular
. See the alerts section below.
Examples
In its default configuration, Hugo renders Markdown blockquotes according to the CommonMark specification. To create a render hook that does the same thing:
{{< code file=layouts/_default/_markup/render-blockquote.html copy=true >}}
{{ .Text | safeHTML }}{{< /code >}}
To render a blockquote as an HTML figure
element with an optional citation and caption:
{{< code file=layouts/_default/_markup/render-blockquote.html copy=true >}}
{{< /code >}}Then in your markdown:
> Some text
{cite="https://gohugo.io" caption="Some caption"}
Alerts
Also known as callouts or admonitions, alerts are blockquotes used to emphasize critical information. For example:
{{< code file=content/example.md lang=text >}}
Note
Useful information that users should know, even when skimming content.
Tip
Helpful advice for doing things better or more easily.
Important
Key information users need to know to achieve their goal.
Warning
Urgent info that needs immediate user attention to avoid problems.
Caution
Advises about risks or negative outcomes of certain actions. {{< /code >}}
{{% note %}} This syntax is compatible with the GitHub Alert Markdown extension. {{% /note %}}
The first line of each alert is an alert designator consisting of an exclamation point followed by the alert type, wrapped within brackets.
The blockquote render hook below renders a multilingual alert if an alert desginator is present, otherwise it renders a blockquote according to the CommonMark specification.
{{< code file=layouts/_default/_markup/render-blockquote.html copy=true >}} {{ $emojis := dict "caution" "❗" "important" "ℹ️" "note" "ℹ️" "tip" "💡" "warning" "ℹ️" }}
{{ if eq .Type "alert" }}
{{ else }}{{ transform.Emojify (index $emojis .AlertType) }} {{ or (i18n .AlertType) (title .AlertType) }}
{{ .Text | safeHTML }}
{{ .Text | safeHTML }}{{ end }} {{< /code >}}
To override the label, create these entries in your i18n files:
{{< code-toggle file=i18n/en.toml >}} caution = 'Caution' important = 'Important' note = 'Note' tip = 'Tip' warning = 'Warning' {{< /code-toggle >}}
Although you can use one template with conditional logic as shown above, you can also create separate templates for each Type
of blockquote:
layouts/
└── _default/
└── _markup/
├── render-blockquote-alert.html
└── render-blockquote-regular.html