1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

Squashed 'docs/' changes from 6c2195936..9be494de3

9be494de3 Clean up the markup config
c3e123133 Remove JustComment
bc1b02bc5 Add Smart to Anchor section
49e796409 Added where .RegularPagesRecursive was added
a92296e31 Fixed the new-in shortcode in pages-vs-site-pages
051e1267c Documented .RegularPagesRecursive
5bcec88a3 Fix broken link in RSS templates page
3db79d433 Correct pull request link on migrations.md
55c347168 Release 0.71.1
11a4e36c3 Merge branch 'temp711'
481fc8ed6 releaser: Add release notes to /docs for release of 0.71.1
40ba83c26 Update site.md
382632b58 Use-modules: More help how to get started importing a theme (#1107)
06751d465 Addition of hugefastsearch to search options (#1118)
8346d3b18 Add example of how to set the permalinks option for pages in "root"
ebb3b4f3a Refine highlight shortcode options
1075a172a Update index.md
7cc927ea6 Fix typo in v0.71.0 release notes
4121da273 Pull in latest theme version to get link hooks
4809be651 Document render-heading feature
2078a3bd1 Release 0.71.0
c09f6899e releaser: Add release notes to /docs for release of 0.71.0
90ffe2b50 Merge commit 'c9403cbceaaeff53ff4833561f4eefe1dc1a405e'
bf3dd0837 Add math.Pow

git-subtree-dir: docs
git-subtree-split: 9be494de3ac79081be60e0f002db110cb96ec7a3
This commit is contained in:
Bjørn Erik Pedersen
2020-05-31 12:43:23 +02:00
parent c9403cbcea
commit 9e1dcefc5f
36 changed files with 191 additions and 87 deletions

View File

@@ -85,9 +85,13 @@ ordered
Note that this is only supported with the [Goldmark](#goldmark) renderer.
These Render Hooks allow custom templates to render links and images from markdown.
Render Hooks allow custom templates to override markdown rendering functionality. You can do this by creating templates with base names `render-{feature}` in `layouts/_default/_markup`.
You can do this by creating templates with base names `render-link` and/or `render-image` inside `layouts/_default/_markup`.
The features currently supported are:
* `image`
* `link`
* `heading` {{< new-in "0.71.0" >}}
You can define [Output-Format-](/templates/output-formats) and [language-](/content-management/multilingual/)specific templates if needed.[^hooktemplate] Your `layouts` folder may look like this:
@@ -105,10 +109,11 @@ Some use cases for the above:
* Resolve link references using `.GetPage`. This would make links portable as you could translate `./my-post.md` (and similar constructs that would work on GitHub) into `/blog/2019/01/01/my-post/` etc.
* Add `target=_blank` to external links.
* Resolve and [process](/content-management/image-processing/) images.
* Add [header links](https://remysharp.com/2014/08/08/automatic-permalinks-for-blog-posts).
### Render Hook Templates
Both `render-link` and `render-image` templates will receive this context:
The `render-link` and `render-image` templates will receive this context:
Page
: The [Page](/variables/page/) being rendered.
@@ -125,7 +130,24 @@ Text
PlainText
: The plain variant of the above.
#### Link with title Markdown example :
The `render-heading` template will receive this context:
Page
: The [Page](/variables/page/) being rendered.
Level
: The header level (1--6)
Anchor
: An auto-generated html id unique to the header within the page
Text
: The rendered (HTML) text.
PlainText
: The plain variant of the above.
#### Link with title Markdown example:
```md
[Text](https://www.gohugo.io "Title")
@@ -151,5 +173,24 @@ Here is a code example for how the render-image.html template could look:
</p>
{{< /code >}}
[^hooktemplate]: It's currently only possible to have one set of render hook templates, e.g. not per `Type` or `Section`. We may consider that in a future version.
#### Heading link example
Given this template file
{{< code file="layouts/_default/_markup/render-heading.html" >}}
<h{{ .Level }} id="{{ .Anchor | safeURL }}">{{ .Text | safeHTML }} <a href="#{{ .Anchor | safeURL }}">¶</a></h{{ .Level }}>
{{< /code >}}
And this markdown
```md
### Section A
```
The rendered html will be
```html
<h3 id="section-a">Section A <a href="#section-a"></a></h3>
```
[^hooktemplate]: It's currently only possible to have one set of render hook templates, e.g. not per `Type` or `Section`. We may consider that in a future version.