Clarify markdownify behavior (#1999)

Closes #1992
This commit is contained in:
Joe Mooring 2023-03-15 11:17:21 -07:00 committed by GitHub
parent afb582a800
commit d54185beff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,7 @@
---
title: markdownify
linktitle: markdownify
description: Runs the provided string through the Markdown processor.
date: 2017-02-01
publishdate: 2017-02-01
lastmod: 2023-02-09
description: Renders markdown to HTML.
keywords: [markdown,content]
categories: [functions]
menu:
@ -18,12 +15,21 @@ deprecated: false
aliases: []
---
```
{{ .Title | markdownify }}
```
{{< new-in "0.93.0" >}} **Note**: `markdownify` now supports [Render Hooks] just like [`.Page.RenderString`]. However, if you use more complicated [Render Hooks] relying on page context, use [`.Page.RenderString`] instead. See [GitHub issue #9692](https://github.com/gohugoio/hugo/issues/9692) for more details.
If the resulting HTML is a single paragraph, Hugo removes the wrapping `p` tags to produce inline HTML as required per the example above.
To keep the wrapping `p` tags for a single paragraph, use the [`.Page.RenderString`] method, setting the `display` option to `block`.
If the resulting HTML is two or more paragraphs, Hugo leaves the wrapping `p` tags in place.
[Render Hooks]: /templates/render-hooks/
[`.Page.RenderString`]: /functions/renderstring/
{{% note %}}
Although the `markdownify` function honors [markdown render hooks] when rendering markdown to HTML, use the `.Page.RenderString` method instead of `markdownify` if a render hook accesses `.Page` context. See issue [#9692] for details.
[markdown render hooks]: /templates/render-hooks/
[#9692]: https://github.com/gohugoio/hugo/issues/9692
{{% /note %}}