Hugo 简码忽略了“省略原始 HTML"的说法 [英] Hugo shortcode ignored saying "raw HTML omitted"

查看:31
本文介绍了Hugo 简码忽略了“省略原始 HTML"的说法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个短代码来创建一个引导程序可关闭的警告框.下面是我的短代码,称为 layouts/shortcodes/message.html.

 

{{.内}}<按钮类型=按钮"类=关闭"数据解除=警报"aria-label=关闭"><span aria-hidden="true">&times;</span>

这是我从内容降价文件中调用的方式:

{{% message warning%}}这可能会导致构建错误{{%/信息 %}}

但是,在输出 HTML 中,会生成以下代码:

<p>这会导致构建错误</p><!-- 省略原始 HTML -->

我不明白这里有什么问题.我已经创建了其他短代码(虽然不使用 .Inner,但这是我的第一次尝试)并且它们工作正常,例如我为像 pinterest 这样的图像网格创建了一个短代码,它最多接受 10 个图像 URL 并输出 HTML.不知道为什么这个特定的 .Inner 短代码失败.请帮忙.我的 Hugo 版本是 v0.74.3/extended darwin/amd64.

编辑

当我使用标签 {{<>}} 而不是 {{% %}} 那么它就可以工作了.但是我可能会在内部文本中进行一些降价,因此我想使用 {{% %}}.

如果我理解正确,使用 {{% %}} 将首先处理内部文本中的降价,然后将其作为 .Inner 传递给短代码.

解决方案

这是 最新 'hugo' Questions 中最常见的问题- 过去 5 天内堆栈溢出!¹

在您的 Hugo 配置文件中,您需要告诉默认的 Markdown 渲染器(即 Goldmark)来渲染原始 HTML.如果您使用 config.yaml,请使用:

标记:金标:渲染器:不安全:真实

如果您使用 config.toml,请使用:

[标记][markup.goldmark][markup.goldmark.renderer]不安全 = 真

我在我的网站 http://www.ii.com 上写了这个/hugo-tips-fragments/#_markup.

¹ 这是我在 5 天内第三次回答这个常见问题.其他 2 次是在 Hugo 在帖子中使用内联 javascript将 iframe Amazon Associate 链接嵌入到 .md 文件 R.>

I have written a shortcode to create a bootstrap dismissable alert box. Below is my shortcode called as layouts/shortcodes/message.html.

   <div class="alert alert-{{.Get 0}} alert-dismissible fade show" role="alert">
       {{.Inner}}
     <button type="button" class="close" data-dismiss="alert" aria-label="Close">
       <span aria-hidden="true">&times;</span>
     </button>
   </div>

This is how I am calling from my content markdown file:

{{% message warning%}}
This can cause build errors
{{% /message %}}

However, in the output HTML, below code is generated :

<!-- raw HTML omitted -->
<p>This can cause build errors</p>
<!-- raw HTML omitted -->

I don't understand what's wrong here. I have created other shortcodes (not using .Inner though, this is my first attempt) and they work fine e.g. I created a shortcode for a image grid like pinterest that accepts upto 10 image URLs and spits out HTML. Not sure why this specific .Inner shortcode fails. Please help. My Hugo version is v0.74.3/extended darwin/amd64.

EDIT

When I use the tags {{< >}} instead of {{% %}} then it works. But I may put some markdown in Inner Text and hence would like to use {{% %}}.

If I understand correctly, using {{% %}} will first process the markdown inside the Inner Text and then will pass that to the shortcode as .Inner.

解决方案

This is the most frequently asked question in Newest 'hugo' Questions - Stack Overflow within the last 5 days!¹

In your Hugo config file, you need to tell the default Markdown renderer, which is Goldmark, to render raw HTML. If you use a config.yaml, use this:

markup:
  goldmark:
    renderer:
      unsafe: true

If you use a config.toml, use this:

[markup]
  [markup.goldmark]
    [markup.goldmark.renderer]
      unsafe = true

I wrote about this on my website in http://www.ii.com/hugo-tips-fragments/#_markup.

¹ This is the 3rd time I'm answering this faq within 5 days. The 2 other times were in Hugo use inline javascript within posts and Embed iframe Amazon Associate Link into .md file R.

这篇关于Hugo 简码忽略了“省略原始 HTML"的说法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆