I came here with similar questions and was very grateful for usr2564301's answer, since it shed much light on the nature of hyperlinks in InDesign. But after some things in my own script didn't work as expected, I explored some more and discovered that the answer isn't completely accurate.
To test the relationships between hyperlink
, hyperlinkTextSource
and hyperlinkURLDestination
, I wrote a script that removed just one of the three objects, and I tested it with both shared and non-shared hyperlinks. Here's what I found:
With non-shared hyperlink destinations:
Remove hyperlink:
Hyperlink removed?: YES
Source removed?: NO
Destination removed?: YES
Remove source:
Hyperlink removed?: YES
Source removed?: YES
Destination removed?: YES
Remove destination:
Hyperlink removed?: NO
Source removed?: NO
Destination removed?: YES
With shared hyperlink destinations:
Remove hyperlink:
Hyperlink removed?: YES
Source removed?: NO
Destination removed?: NO
Remove source:
Hyperlink removed?: YES
Source removed?: YES
Destination removed?: NO
Remove destination:
Hyperlink removed?: NO
Source removed?: NO
Destination removed?: YES
Removing a destination does exactly what you might expect—it just deletes the destination and leaves the hyperlink and source in place. It's like having an empty destination field in your hyperlink.
The result of removing the containing hyperlink is a little less intuitive, as you discovered. You might expect that it would delete everything, but it only deletes the destination (if it's non-shared).
The real surprise for me was that removing the source alone is enough to delete everything (for non-shared destinations). I suppose this sort of makes sense—a hyperlink without a source is kind of meaningless.
所以你去。在我的脚本中,我需要删除单个超链接,这种行为实际上简化了事情。删除该hyperlinkTextSource
工作,而不必担心它是否是共享目标(可能被其他超链接使用)。