不能在 Blogdown 的 Rmd 文件中使用 Markdown 短代码 [英] Cannot use Markdown shortcodes in Blogdown's Rmd files

查看:52
本文介绍了不能在 Blogdown 的 Rmd 文件中使用 Markdown 短代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Blogdown.在我的 post.Rmd 文件中,我需要使用一个短代码:

I am using Blogdown. In my post.Rmd file I need to use a shortcode:

This is me calling a **shortcode**:

`r blogdown::shortcode("mysc", .content = "Find **more** about this shortcode in [here](https://www.wikipedia.com).")`

如您所见,.content 是 Markdown,而不是纯文本.简码 mysc.html 是:

As you can see, .content is Markdown, not plain text. Shortcode mysc.html is:

<p class="sc">
  {{ if .Inner }}
    {{ .Inner }}
  {{ end }}
</p>

如您所见,我使用 blogdown::shortcode 因为无法在 Rmd 文件中使用短代码语法.

As you can see, I am using blogdown::shortcode because it is not possible to use shortcode syntax in Rmd files.

但是 .content 中的 Markdown 没有转换成 HTML,我把它作为输出:

However the Markdown in .content is not converted into HTML, I get this as output:

<p>
Find **more** about this shortcode in [here](https://www.wikipedia.com).
</p>

我做错了什么?

请注意,指定 .type 没有帮助:

Note that specifying .type does not help:

`r blogdown::shortcode("mysc", .content = "...", .type = "markdown")`

也没有必要,因为它默认为 "markdown".如果我指定 .type = "html",它仍然呈现完全相同的输出.这到底是怎么回事?

Also it should not be necessary as it defaults to "markdown". And it still renders the same exact output if I specify .type = "html". What the hell is going on here?

推荐答案

正如我在 您引用的 Github 问题,Hugo 更改了 {{% %}} 的行为.个人觉得是破绽.在修复之前,我认为你唯一的选择是

As I mentioned in the Github issue you referenced, Hugo changed the behavior of {{% %}}. Personally I feel it is a breakage. Before it is fixed, I think your only options are

  • 将您的网站项目锁定到较低版本的 Hugo,例如

  • Lock your website project to a lower version of Hugo, e.g.

blogdown::install_hugo('0.54.0', force = TRUE)

如果你之前通过 Homebrew 安装过 Hugo,你最好卸载它:brew remove hugo.

If you installed Hugo via Homebrew previously, you'd better uninstall it: brew remove hugo.

或者在您的短代码中手动将 .Inner 转换为 Markdown:{{ .Inner |markdownify }}.请注意,这种方法存在潜在风险:如果 Hugo 作者决定恢复 {{% %}} 短代码的行为,您将不得不删除 markdownify.

Or manually turn .Inner to Markdown in your shortcode: {{ .Inner | markdownify }}. Please note that this approach has a potential risk: if the Hugo author decides to revert the behavior of {{% %}} shortcodes, you will have to remove markdownify.

这篇关于不能在 Blogdown 的 Rmd 文件中使用 Markdown 短代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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