繁体   English   中英

是否可以在 github markdown 渲染中禁用图像的自动链接?

[英]Is it possible to disable the automatic linking of images in github markdown rendering?

当 github.com 在 readme.md 中渲染图像时,它会自动将图像链接到a标签中。

使用任一

![][http://example.com/path/image]

或者

<img src="http://example.com/path/image" />

实际呈现的内容将显示为

<a href="https://camo.githubusercontent.com/8a545f12e16ff12fd...." target="_blank"><img src="https://camo.githubusercontent.com/8a545f12e16ff12f..." alt="" data-canonical-src="http://example.com/path/image" style="max-width:100%;"></a>

我了解github 图像缓存(在 camo.githubusercontent.com 上),这很好,但我不希望a标签包装我的图像。

我不确定这是 github 风格的自动 URL 链接的一部分,还是某些特定图像。

我可以提供我自己的链接(使用我自己a标签),但我真正想要a是没有链接,没有标签。

这可能吗?

谢谢!

您可以将图像包装在指向#的链接中:

[![](http://example.com/path/image)](#)

<a href="#"><img src="http://example.com/path/image" /></a>

它仍然可以点击,但至少不会打开新页面。

linkImagesToOriginal: false传递给gatsby-remark-images应该能够解决此问题。

 { resolve: 'gatsby-remark-images', options: { linkImagesToOriginal: false, }, }

如果你点击你的徽章,你会认为看到的是一张图片,但它通常是一个带有 html-tags 的 html 页面。 这就是为什么徽章默认链接到不同页面的原因。

@Tamás Sengel 的回答还不错,但看起来像@Igor 提到的视觉故障等副作用。

我通过简单地参考我的github页面解决了这个问题:

[![platform](https://img.shields.io/badge/platform-ubuntu%20%7C%20windows-lightgrey?style=flat-square)](https://github.com/Ismoh/NoitaMP)

平台

这是一个使用shields.io构建的静态徽章,不应链接到source

下面的代码片段正是您“删除”图像的a标签所需要的。 Markdown 将在a周围呈现所有img的标签。 对我来说(使用 Gatsby)选项“linkImagesToOriginal:false”被完美删除,现在所有图像都不可点击。

 { resolve: 'gatsby-remark-images', options: { linkImagesToOriginal: false, }, }

您可以使用<picture>标签来防止 GitHub 自动链接到图像。

<picture>
  <img alt="Image Alt Text" src="http://example.com/path/image">
</picture>

这种方法最适合我:将图像链接到自身

<a id="image1" href="#image1"><img alt="alt text" src="http://example.com/path/image.png" /></a>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM