在 NSTextView 中创建指向某些文本的超链接
我可以使用“链接面板”在 NSTextView 中创建指向某些 url 的超链接。或者我可以使用 NSAttributedString 的 NSLinkAttributeName 属性手动添加链接。
我不想创建指向某些外部 url 的超链接,但我希望能够创建指向 NSTextView 中某些文本的超链接。您知道如何在 Pages 中将某些文本设置为书签,然后可以创建指向该书签的超链接吗?有什么想法或例子可以说明如何做到这一点吗?
I can create a hyperlink to some url in an NSTextView using the "Link Panel". Or I can add a link manually using the NSLinkAttributeName attribute of NSAttributedString.
I don't want to make a hyperlink to some external url though, I want to be able to create a hyperlink to some text within the NSTextView. Do you know how in Pages you can set some text as a Bookmark, and then you can make a hyperlink to that bookmark? Any ideas or examples of how to go about that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经有一段时间没有这样做了,所以对此持保留态度,但它是这样的:
Info.plist
文件中,在CFBundleURLTypes
键下添加协议。openURL
。这意味着应用程序必须了解如何将 URL 样式路径转换到其文档之一中的特定位置。我认为处理 URL 路径的最佳方法是为每个文档分配一个 UUID,然后为段落和句子分配一个数字方案。 URL 最终看起来像:
myApplicationName://UUID/paragraphNumber/sentenceNumber/wordNumber
。或者,您可以插入隐藏文本来定义锚点,然后只搜索该锚点。I haven't done this in a while so take this with a grain of salt but it goes something like:
Info.plist
file add the protocol underCFBundleURLTypes
key.openURL
from NSWorkspace. This means the app will have to understand how to convert a URL style path to a specific location in one of its documents.I think the best method for handling the URL path is to assign a UUID to each document and then a numeric scheme to the paragraph and sentences. The URL ends up looking like:
myApplicationName://UUID/paragraphNumber/sentenceNumber/wordNumber
. Alternatively you can insert hidden text to define an anchor and just search for that anchor.