我使用Hugo部署静态web,使用Markdown,我想解决的问题很简单.
< rawhtml >}}<a href="https://en.wikipedia.org/wiki/Rasmus_Lerdorf" target="blank">Rasmus Lerdorf</a></br>{{< /rawhtml >
[link with title](http://nodeca.github.io/pica/demo/ "target="blank")
第一种方法有效,但第二种方法无效.
我使用Hugo部署静态web,使用Markdown,我想解决的问题很简单.
< rawhtml >}}<a href="https://en.wikipedia.org/wiki/Rasmus_Lerdorf" target="blank">Rasmus Lerdorf</a></br>{{< /rawhtml >
[link with title](http://nodeca.github.io/pica/demo/ "target="blank")
第一种方法有效,但第二种方法无效.
你需要在/layouts/_default/_markup/
创建一个名为render-link.html
的新文件.
在该文件中,您可以将其自定义为以下内容:
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }} target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
以下是将会发生的情况:
[link1](../something/ title="title")
=>;<a href="../something/" title="title">link1</a>
[link2](https://example.com)
=>;<a href="https://example.com">link2</a>
它只会将其添加到带有"http"和"https"的URL中.
渲染挂钩的文档可以在这里找到:https://gohugo.io/templates/render-hooks/.