mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
Merge commit '346b60358dd8ec2ca228e6635bff9d7914b398b7'
This commit is contained in:
@@ -6,7 +6,7 @@ _comment: Do not remove front matter.
|
||||
|
||||
{{< new-in 0.125.0 >}}
|
||||
|
||||
The primary use case for `PageInner` is to resolve links and [page resources] relative to an included `Page`. For example, create an "include" shortcode to compose a page from multiple content files, while preserving a global context for footnotes and the table of contents:
|
||||
The primary use case for `PageInner` is to resolve links and [page resources](g) relative to an included `Page`. For example, create an "include" shortcode to compose a page from multiple content files, while preserving a global context for footnotes and the table of contents:
|
||||
|
||||
{{< code file=layouts/shortcodes/include.html >}}
|
||||
{{ with .Get 0 }}
|
||||
@@ -45,4 +45,3 @@ As a practical example, Hugo's embedded link and image render hooks use the `Pag
|
||||
- [Embedded image render hook]({{% eturl render-image %}})
|
||||
|
||||
[`RenderShortcodes`]: /methods/page/rendershortcodes/
|
||||
[page resources]: /getting-started/glossary/#page-resource
|
||||
|
@@ -16,9 +16,7 @@ toc: true
|
||||
|
||||
## Context
|
||||
|
||||
Blockquote render hook templates receive the following [context]:
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
Blockquote render hook templates receive the following [context](g):
|
||||
|
||||
###### AlertType
|
||||
|
||||
|
@@ -54,9 +54,7 @@ Although `style` is a global HTML attribute, when used in an info string it is a
|
||||
|
||||
## Context
|
||||
|
||||
Code block render hook templates receive the following [context]:
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
Code block render hook templates receive the following [context](g):
|
||||
|
||||
###### Attributes
|
||||
|
||||
|
@@ -14,9 +14,7 @@ toc: true
|
||||
|
||||
## Context
|
||||
|
||||
Heading render hook templates receive the following [context]:
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
Heading render hook templates receive the following [context](g):
|
||||
|
||||
###### Anchor
|
||||
|
||||
|
@@ -22,9 +22,7 @@ A Markdown image has three components: the image description, the image destinat
|
||||
description destination title
|
||||
```
|
||||
|
||||
These components are passed into the render hook [context] as shown below.
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
These components are passed into the render hook [context](g) as shown below.
|
||||
|
||||
## Context
|
||||
|
||||
@@ -143,12 +141,9 @@ The embedded image render hook is automatically enabled for multilingual single-
|
||||
[duplication of shared page resources]: /getting-started/configuration-markup/#duplicateresourcefiles
|
||||
{{% /note %}}
|
||||
|
||||
The embedded image render hook resolves internal Markdown destinations by looking for a matching [page resource], falling back to a matching [global resource]. Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination.
|
||||
The embedded image render hook resolves internal Markdown destinations by looking for a matching [page resource](g), falling back to a matching [global resource](g). Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination.
|
||||
|
||||
[page resource]: /getting-started/glossary/#page-resource
|
||||
[global resource]: /getting-started/glossary/#global-resource
|
||||
|
||||
You must place global resources in the assets directory. If you have placed your resources in the static directory, and you are unable or unwilling to move them, you must mount the static directory to the assets directory by including both of these entries in your site configuration:
|
||||
You must place global resources in the `assets` directory. If you have placed your resources in the `static` directory, and you are unable or unwilling to move them, you must mount the `static` directory to the `assets` directory by including both of these entries in your site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[module.mounts]]
|
||||
|
@@ -66,7 +66,7 @@ layouts/
|
||||
└── render-table.html
|
||||
```
|
||||
|
||||
The template lookup order allows you to create different render hooks for each page [type], [kind], language, and [output format]. For example:
|
||||
The template lookup order allows you to create different render hooks for each page [type](g), [kind](g), language, and [output format](g). For example:
|
||||
|
||||
```text
|
||||
layouts/
|
||||
@@ -84,8 +84,4 @@ layouts/
|
||||
└── render-link.rss.xml
|
||||
```
|
||||
|
||||
[kind]: /getting-started/glossary/#page-kind
|
||||
[output format]: /getting-started/glossary/#output-format
|
||||
[type]: /getting-started/glossary/#content-type
|
||||
|
||||
The remaining pages in this section describe each type of render hook, including examples and the context received by each template.
|
||||
|
@@ -22,16 +22,12 @@ A Markdown link has three components: the link text, the link destination, and o
|
||||
text destination title
|
||||
```
|
||||
|
||||
These components are passed into the render hook [context] as shown below.
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
These components are passed into the render hook [context](g) as shown below.
|
||||
|
||||
## Context
|
||||
|
||||
Link render hook templates receive the following context:
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
|
||||
###### Destination
|
||||
|
||||
(`string`) The link destination.
|
||||
@@ -113,12 +109,9 @@ The embedded link render hook is automatically enabled for multilingual single-h
|
||||
[duplication of shared page resources]: /getting-started/configuration-markup/#duplicateresourcefiles
|
||||
{{% /note %}}
|
||||
|
||||
The embedded link render hook resolves internal Markdown destinations by looking for a matching page, falling back to a matching [page resource], then falling back to a matching [global resource]. Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination.
|
||||
The embedded link render hook resolves internal Markdown destinations by looking for a matching page, falling back to a matching [page resource](g), then falling back to a matching [global resource](g). Remote destinations are passed through, and the render hook will not throw an error or warning if unable to resolve a destination.
|
||||
|
||||
[page resource]: /getting-started/glossary/#page-resource
|
||||
[global resource]: /getting-started/glossary/#global-resource
|
||||
|
||||
You must place global resources in the assets directory. If you have placed your resources in the static directory, and you are unable or unwilling to move them, you must mount the static directory to the assets directory by including both of these entries in your site configuration:
|
||||
You must place global resources in the `assets` directory. If you have placed your resources in the `static` directory, and you are unable or unwilling to move them, you must mount the `static` directory to the `assets` directory by including both of these entries in your site configuration:
|
||||
|
||||
{{< code-toggle file=hugo >}}
|
||||
[[module.mounts]]
|
||||
|
@@ -45,19 +45,15 @@ inline = [['\(', '\)']]
|
||||
|
||||
In the example above there are two sets of `block` delimiters. You may use either one in your Markdown.
|
||||
|
||||
The Goldmark passthrough extension is often used in conjunction with the MathJax or KaTeX display engine to render [mathematical expressions] written in [LaTeX] or [Tex].
|
||||
The Goldmark passthrough extension is often used in conjunction with the MathJax or KaTeX display engine to render [mathematical expressions] written in the LaTeX markup language.
|
||||
|
||||
[mathematical expressions]: /content-management/mathematics/
|
||||
[LaTeX]: https://www.latex-project.org/
|
||||
[Tex]: https://en.wikipedia.org/wiki/TeX
|
||||
|
||||
To enable custom rendering of passthrough elements, create a render hook.
|
||||
To enable custom rendering of passthrough elements, create a passthrough render hook.
|
||||
|
||||
## Context
|
||||
|
||||
Passthrough render hook templates receive the following [context]:
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
Passthrough render hook templates receive the following [context](g):
|
||||
|
||||
###### Attributes
|
||||
|
||||
@@ -99,19 +95,35 @@ Hugo populates the `Attributes` map for _block_ passthrough elements. Markdown a
|
||||
|
||||
## Example
|
||||
|
||||
As an alternative to rendering mathematical expressions with the MathJax or KaTeX display engine, create a passthrough render hook which calls the [`transform.ToMath`] function:
|
||||
Instead of client-side JavaScript rendering of mathematical markup using MathJax or KaTeX, create a passthrough render hook which calls the [`transform.ToMath`] function.
|
||||
|
||||
[`transform.ToMath`]: /functions/transform/tomath/
|
||||
|
||||
{{< code file=layouts/_default/_markup/render-passthrough.html copy=true >}}
|
||||
{{ if eq .Type "block" }}
|
||||
{{ $opts := dict "displayMode" true }}
|
||||
{{ transform.ToMath .Inner $opts }}
|
||||
{{ else }}
|
||||
{{ transform.ToMath .Inner }}
|
||||
{{ end }}
|
||||
{{- $opts := dict "output" "htmlAndMathml" "displayMode" (eq .Type "block") }}
|
||||
{{- with try (transform.ToMath .Inner $opts) }}
|
||||
{{- with .Err }}
|
||||
{{ errorf "Unable to render mathematical markup to HTML using the transform.ToMath function. The KaTeX display engine threw the following error: %s: see %s." . $.Position }}
|
||||
{{- else }}
|
||||
{{- .Value }}
|
||||
{{- $.Page.Store.Set "hasMath" true }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{< /code >}}
|
||||
|
||||
Then, in your base template, conditionally include the KaTeX CSS within the head element:
|
||||
|
||||
{{< code file=layouts/_default/baseof.html copy=true >}}
|
||||
<head>
|
||||
{{ $noop := .WordCount }}
|
||||
{{ if .Page.Store.Get "hasMath" }}
|
||||
<link href="https://cdn.jsdelivr.net/npm/katex@0.16.21/dist/katex.min.css" rel="stylesheet">
|
||||
{{ end }}
|
||||
</head>
|
||||
{{< /code >}}
|
||||
|
||||
In the above, note the use of a [noop](g) statement to force content rendering before we check the value of `hasMath` with the `Store.Get` method.
|
||||
|
||||
Although you can use one template with conditional logic as shown above, you can also create separate templates for each [`Type`](#type) of passthrough element:
|
||||
|
||||
```text
|
||||
|
@@ -16,9 +16,7 @@ toc: true
|
||||
|
||||
## Context
|
||||
|
||||
Table render hook templates receive the following [context]:
|
||||
|
||||
[context]: /getting-started/glossary/#context
|
||||
Table render hook templates receive the following [context](g):
|
||||
|
||||
###### Attributes
|
||||
|
||||
|
Reference in New Issue
Block a user