rstudio / blogdown

Create Blogs and Websites with R Markdown
https://pkgs.rstudio.com/blogdown/
1.73k stars 335 forks source link

Feature request: enableing link_attributes extension for .md files by default #441

Closed jooyoungseo closed 4 years ago

jooyoungseo commented 4 years ago

I understand that we can easily make links open in new browser tabs using [link](URL){target="_blank"} syntax as described on Yihui's blog post.

However, the link_attributes extension is only enabled for .Rmd files; we can't employ this method against .md files unless we enable the extension in the call to pandoc with +link_attributes.

I was wondering if we could enable this link_attributes extension globally for both .Rmd and .md files within blogdown package.

I am requesting this because there are some required .md files shipped with hugo themes, which are not working when replaced with .Rmd files.

For example, gcushen/hugo-academic has its own skeleton .md file for users to create their admin profiles including their bios:

"./content/authors/admin/_index.md"

Since my bio included some links that I wanted to open in new tabs, I appended {target="_blank"} to each of the link elements.

I found, however, that blogdown::build_site() did not work when I converted the _index.md file into a .Rmd format, which means I failed to secure a way to employ the link_attributes extension.

Please kindly consider this request.

cderv commented 4 years ago

Hi,

in Blogdown, there are three type of files .Rmd, .Rmarkdown, and .md. See this chapter in blogdown book Those files are not rendered with the same engine. Especially,

A plain Markdown post is rendered to HTML through Blackfriday (a package written in the Go language and adopted by Hugo).

So, [link](URL){target="_blank"} which I guess is a Pandoc related syntex won't work in md file. If you want target="_blank" links you should have a look into blackfriday configuration.

Some related resources on Hugo

However, you can indeed use Rmd. I modified /content/authors/admin/_index.md to /content/authors/admin/_index.Rmd and added

See [Google](http://google.fr){target="_blank"}

when testing with blogdown::serve_site() I correcly got the correct html

<a href="http://google.fr" target="_blank">Google</a>

So it seems to work.

In summary, .md files are not rendered by pandoc so there is no enableing link_attributes to do here. To keep .md look into hugo / blackfriday configuration or use html directly. Otherwise Rmd should work.

Hope it helps.

jooyoungseo commented 4 years ago

Thank you very much for your instrumental and resourceful comments, @cderv!

Yes, I get the picture now.

And, I finally got the _index.Rmd to work as you described, probably there was an issue with my local machine (cache, etc.).

I am closing this issue to not bug anyone else.

Appreciatively,