在 reStructuredText 中的新窗口中打开链接 [英] Open a link in a new window in reStructuredText

查看:55
本文介绍了在 reStructuredText 中的新窗口中打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 reStructuredText 在新窗口中打开一个链接.这可能吗?

I want to open a link in a new window using reStucturedText. Is this possible?

这会在同一窗口中打开链接:

This opens link in the same window:

You can `check your location here. <http://geoiptool.com>`_

推荐答案

要在新窗口或标签中打开页面,您可以将属性 target="_blank" 添加到您的超链接,尽管我'我不确定如何向 reStructuredText 中的内联超链接添加属性.但是,从 Docutils 常见问题解答中,可能嵌套内联标记,您可以使用raw 指令将原始 HTML 包含到您的文档中,例如

To open a page in a new window or tag you can add the attribute target="_blank" to your hyperlink although I'm not sure how you can add attributes to inline hyperlinks in reStructuredText. However, from the Docutils FAQ, is nested inline markup possible, you can use the raw directive to include raw HTML into your document, for example

You can |location_link|.

.. |location_link| raw:: html

   <a href="http://geoiptool.com" target="_blank">check your location here</a>

更新以解决评论

我有一个问题为什么 reStructuredText 没有 [插入一些很棒的功能]".

在这种情况下,为什么 reStructuredText 没有办法指定链接的打开方式"——我认为 reStructuredText 没有一个简单的方法来做到这一点,因为点击链接的工作方式并不是真的责任.reStructuredText 转换标记——该标记的最终显示方式不取决于 reStructuredText,而是取决于用户选择使用的浏览器或查看器.

In this case, "why does reStructuredText not have a way to specify how links are opened" — I think reStructuredText doesn't have an easy way of doing this since the behaviour of how clicking a link works isn't really it's responsibility. reStructuredText transforms markup — how that markup is ultimately displayed is not up to reStructuredText, but whatever browser or viewer the user chooses to use.

在 Web 浏览器中打开链接的情况下,良好的可用性实践表明您不应强迫用户在新选项卡中打开链接(这就是添加 target="_blank" 正在做).相反,您应该将如何打开链接的选择权留给用户.如果用户想在新标签页中打开链接,他们可以使用鼠标中键(或任何他们喜欢的快捷键).

In the case of opening a link in a web browser, good useability practice dictates that you should not force a user to open a link in a new tab (which is what adding target="_blank" is doing). Rather, you should leave the choice of how to open the link up to the user. If a user wants to open a link in a new tab, then they can use their middle mouse button (or whatever their favourite shortcut key is).

所以我认为 reStructureText 没有简单的 target="_blank" 功能是完全可以接受的.对于真的想要这样做的人来说,这是可能的,这很好,而这样做有点痛苦,这有助于阻止这种做法.

So I think that it is perfectly acceptable that reStructureText does not have an easy target="_blank" feature. The fact that it is possible is nice for people who really want to do this is good, and the fact that it is a bit of pain to do so is good for discouraging this practice.

这篇关于在 reStructuredText 中的新窗口中打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆