Reputation: 9582
knitr
automatically generates links when knitting .Rmd to .html. Very often that's useful, but just now it's not what I want.
Suppose you have this .Rmd file:
---
title: "Doc title"
output: html_document
---
I don't want [email protected], but it comes out that way.
If you wrap it in an R expression `r "[email protected]"`.
Is there some kind of CSS trick I can avail myself of if I wanted <style='nolink'>www.something.com</style> not to be a link?
Knitting like this:
library(knitr)
knit2html('that_file.Rmd', 'that_file.html')
results in all those things being links.
Is there an easy way to generally keep the auto-link generation, but disable it selectively in particular lines? Thanks for any thoughts.
Edit: i guess I should have actually tried the solution below before accepting. This in the .Rmd
I don't want this <!-- breaklink -->@to-be-a-link.com
...doesnt actually parse to an HTML comment, because the -- gets changed to an em dash (by knitr? pandoc?) and then I get:
Upvotes: 10
Views: 3578
Reputation: 22609
The easiest and most localized way to do this is to "backslash-escape" the at sign:
I don't want this\@to-be-a-link.com, and now it isn't.
This also works with weblinks:
Not a link: https\://posit.co
The autolink feature can also be completely disabled by turning off the autolink_bare_uris
extension:
---
title: "Doc title"
output:
html_document:
md_extensions: -autolink_bare_uris
---
I don't want [email protected], and now it isn't.
URLs must then be wrapped in angular brackets to get a link: <https://posit.co>
.
See also the "HTML document" section in the R Markdown Cookbook.
Upvotes: 1
Reputation: 2722
Very late to this party, however there's another way to accomplish this using html entities.
Using an entity rather than the normal charater-mark will essentially escape whatever and when rendered will not become a hyperlink.
For example, if I wanted a url to be in plaintext(meaning i dont want it to look like code
, which for most cases would work just fine), but i had a usecase where I wanted part of the url to be bold, so:
In my .Rmd
file:
Hyperlinked
: https://sub-domain-**env**.domain.com/path/to/collection
Non-Hyperlinked
: https://sub-domain-**env**.domain.com/path/to/collection
Upvotes: 0
Reputation: 193517
Two options that I see are (1) using bare backticks, or (2) "breaking" the link by using an empty HTML comment.
Example:
---
title: "Doc title"
output: html_document
---
I don't want this<!-- -->@to-be-a-link.com, but it comes out that way.
If you wrap it in an R expression `[email protected]`.
Is there some kind of CSS trick I can avail myself of if I wanted
<style='nolink'>http<!-- -->://www.something.com</style> not to
be a link?
Becomes:
Upvotes: 8