【问题标题】:Avoid auto-hyperlink generation with knitr, markdown避免使用 knitr、markdown 生成自动超链接
【发布时间】:2015-01-05 04:01:26
【问题描述】:

knitr 将 .Rmd 编​​织到 .html 时自动生成链接。很多时候这很有用,但现在它不是我想要的。

假设你有这个 .Rmd 文件:

---
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  `r "this@is-still-a-link.com"`.

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?

这样编织:

library(knitr)
knit2html('that_file.Rmd', 'that_file.html')

导致所有这些东西都是链接。

有没有一种简单的方法来保持自动链接生成,但在特定行有选择地禁用它?感谢您的任何想法。

编辑:我想我应该在接受之前尝试过下面的解决方案。这个在.Rmd

I don't want this <!-- breaklink -->@to-be-a-link.com

...实际上并没有解析为 HTML 注释,因为 -- 被更改为 em 破折号(由 knitr?pandoc?)然后我得到:

【问题讨论】:

  • 您只是不希望它显示为链接还是完全删除链接?另外,你为什么要在第二次尝试中使用 R 表达式而不是直接使用反引号?
  • 这看起来很老套,但你可以用像&lt;!-- --&gt; 这样的东西作为 URL 的一部分插入来“破坏”链接......
  • 不想要裸反引号版本,因为我想要纯文本输出。没想到 R 表达式一定会起作用,但只是展示了我尝试/扔在墙上的东西。
  • 我认为这可能是一个 pandoc 问题,真的.... 我发布的答案似乎适用于 HTML 和 DOCX,但不适用于 PDF。

标签: r markdown knitr pandoc


【解决方案1】:

我看到的两个选项是 (1) 使用裸反引号,或 (2) 使用空 HTML 注释“断开”链接。

例子:

---
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 `this@is-still-a-link.com`.

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?

变成:

【讨论】:

  • @arvi1000,嗯,这是一个评论——所以你可以让它变得冗长,比如this&lt;!-- breaklink --&gt;@to-be-a-link.com :-)
猜你喜欢
  • 1970-01-01
  • 2013-12-27
  • 2018-05-17
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
  • 2019-02-04
  • 2016-08-22
  • 1970-01-01
相关资源
最近更新 更多