Cannot use Markdown shortcodes in Blogdown's Rmd files

情到浓时终转凉″ 提交于 2020-01-25 01:11:12

问题


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).")`

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

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

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

Problem

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>

What am I doing wrong?


Troubleshooting

Note that specifying .type does not help:

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

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?


回答1:


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

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

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

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

  • 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.



来源:https://stackoverflow.com/questions/55856904/cannot-use-markdown-shortcodes-in-blogdowns-rmd-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!