Links between documents

Everything related to our flagship word processor.
Post Reply
Nick Sloan
Posts: 22
Joined: 2004-08-01 02:35:18

Links between documents

Post by Nick Sloan »

Am I right or wrong in believing that bookmarks in one Nisus document cannot be referenced by cross-references in another? If this is not currently supported, is it already a feature request?

And another: Nisus Writer Pro works very nicely with Hook —on the document level, i.e. Hook can establish links with Nisus documents but not parts of documents. Is there any possibility, via scripting or whatever, of Hook being able to hook to a URL for a Nisus bookmark? That would greatly increase the potential for using both apps.

(In case readers have not discovered Hook yet, it is well worth a look: https://hookproductivity.com)
Þorvarður
Posts: 410
Joined: 2012-12-19 05:02:52

Re: Links between documents

Post by Þorvarður »

Hi Nick,
[can] bookmarks in one Nisus document […] be referenced by cross-references in another?
Not by cross-references, as far as I know, but it's possible to *link* multiple text locations in a Nisus document to a bookmark in another document with a macro. I know, this is not the same, but it's an easy and decent way to link documents.

You mention "links between documents" and then "cross-referencing." These are two different things. What I mean is, do you just want to jump from a document B to a bookmark in document A ? If yes, then there is a great macro available for that; it will show you all bookmarks in all open documents in a nice, clickable list window, so you can jump from one bookmark/document to another, each time just by one mouse-click.

Code: Select all

#This macro shows all bookmarks from all open documents:
$docMap = Hash.new
ForEach $doc in Document.openDocuments
	$docMap{$doc} = $doc.allBookmarks
End
Show Find Results $docMap, "All Bookmarks"
Source: Macro Language Reference, p. 20

Or do you need the additional text that often goes with cross-references, such as: See bookmarked text on page 5? If yes, then let's assume you have a bookmark in document A and you want to "cross-reference" that bookmark in document B. To do that, the bookmark's name must appear in document B. A macro can then (1) pick up (= copy) the name, (2) switch to document A and (3) select the bookmarked text. I find, this comes pretty close to a real cross-reference.

Example:
Suppose you have a bookmark in document A called "unhinged president." Then the "cross-reference" in document B could look like this:

Text, text, text, text, text, text, text, text, text, text, text, text,
text, text, text, text, text, text, text, text, text, text, text.
See The |unhinged president| in File [fileName]

I marked the bookmark's name with two || just to make it stand out and remind me that the name is "unhinged president" and not "The unhinged president." You are free to change the marker, of course, and modify the macro accordingly.

Code: Select all

# Place the insertion point somewhere between the | | , that is, somewhere in the bookmark's name
Find "|", 'er'
Select End
Find @Text<(?:.|\n|\f)+?(?=\|)>, 'E'
Copy
$bm = Read Clipboard
Window:Next Window
Select Bookmark $bm
Instead of
Window:Next Window
one should use the appropriate filename (and filepath?)
Nick Sloan
Posts: 22
Joined: 2004-08-01 02:35:18

Re: Links between documents

Post by Nick Sloan »

Thanks for opening up a new perspective Þorvarður. Despite being an intensive Nisus user for countless years, I have never explored macros, and I now see how much I have been missing. It has taken me a while to find the time to experiment with your macros, which accounts for the delay in replying. I have still not fully grasped the second one (I'll work it out), but the first works a treat, and you have set me off on a trail that could prove very fruitful.

That said, I still wonder whether the concept of a URL to specific Nisus bookmarks is viable?
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Links between documents

Post by martin »

Þorvarður is right that macros can do a lot of really nice things with bookmarks and might be able to satisfy your workflow, depending on your exact needs. However, you're right that there's no easy built-in feature that allows cross-references target bookmarks in a different document. Currently cross-references must reside in the same document as their targeted bookmarks. But I'll make a note of your desire for this feature, thanks!
Nick Sloan wrote: 2020-04-20 02:36:52Is there any possibility, via scripting or whatever, of Hook being able to hook to a URL for a Nisus bookmark?
Yes, but you might run into trouble. Nisus Writer has code to handle URLs that target content inside a particular file. You can target named bookmarks or specific page numbers using URLs like this:

file:///Users/youruser/Destop/example.rtf#BookmarkName
file:///Users/youruser/Destop/example.rtf?page=19

If Nisus Writer receives a request to open such a URL, it should jump to the desired target. However, I'm having a hard time getting the system to do that; file URLs seem to activate the Finder, not the default assigned app. But maybe you'd have better success in Hook or other apps, depending on how exactly they trigger the URL.
Nick Sloan
Posts: 22
Joined: 2004-08-01 02:35:18

Re: Links between documents

Post by Nick Sloan »

Thanks very much for responding Martin.
If I understand you correctly, the format of the URL should be
file://[Unix file path including leading slash]#[Bookmark Name] or

file://[Unix file path including leading slash]page=[page number]

In both cases, if I invoke this in a Nisus URL link, I get an alert telling me that the file (e.g filename.rtf#Bookmark or filename.rtfpage=2) cannot be found. So the Nisus parser at least is not distinguishing between the actual file name and the bookmark or page suffix. In the case of your bookmark URL, the hash presumably acts as a delimiter but is not recognised as such. In the case of the page number there is no delimiter. If I add another slash it just interprets that as another level of file path and looks for the file page2.

I acknowledge that this may be a hopeless quest, and that macros may be the way to go, but are we certain that there is not something missing from the theoretical URL syntax?
User avatar
phspaelti
Posts: 1313
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Links between documents

Post by phspaelti »

Nick Sloan wrote: 2020-04-27 23:14:09 In the case of the page number there is no delimiter. If I add another slash it just interprets that as another level of file path and looks for the file page2.
Nick, there is supposed to be a delimiter, namely a "?". The "page=XX" is a query in this URL.

Also the "Unix file path including leading slash" language has me worried that you are misunderstanding that part. The "leading slash" means you (need to) use a full path the "leading slash" is the root. Paths which do not have a leading slash are relative paths. But the syntax here does not allow for a relative path.

My apologies if all of this is obvious to you.
philip
Nick Sloan
Posts: 22
Joined: 2004-08-01 02:35:18

Re: Links between documents

Post by Nick Sloan »

No need for apology philip: glad of any advice and corrections.
I unaccountably missed the ? delimiter. But if I add it as part of the URL used for Link destination in a Nisus link, I still get a dialogue asking me to confirm the location of the file, and when I do that it still does not take me to the specified page. Maybe this is merely a repeat of what Martin was saying above, though in my case there does not appear to be any Finder intervention (I use Path Finder and it makes no difference if Finder is quit).

You are right of course about the leading slash. I only specified it in case I was tempted to think that the root designation was pre-empted by the file:// suffix. I may well be misunderstanding things, but I think that was just a miscommunication.

Finally, in answer to Martin, I did try editing a Hook document which is just a link to a Nisus doc: I adding the bookmark/page number specifiers to the end of the URL, but I still ended up at the head of the doc —or rather the last remembered position.

I have the feeling there is a way through all this, but connecting to the Nisus "code to handle URLs that target content" is proving a challenge.
User avatar
martin
Official Nisus Person
Posts: 5227
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Links between documents

Post by martin »

Nick Sloan wrote: 2020-04-28 04:58:27 if I invoke this in a Nisus URL link ... I still get a dialogue asking me to confirm the location of the file, and when I do that it still does not take me to the specified page.
That's expected if you enter the file path into Nisus Writer. Ultimately Nisus Writer stores and processes links to files on disk as bookmarks (née aliases in Classic mac parlance). Ever since Apple introduced sandboxing in order to tighten security, apps must store something called security-scoped bookmark data to persist access to a file. A file path is insufficient.

Nisus Writer is trying to convert your file path to bookmark data. That will discard any special query string arguments or fragments at the end of the URL, like the target bookmark name. This approach is a dead-end from the Nisus Writer side of things, at least right now. We would need to enhance file links to include support for interior targets like bookmarks.
I did try editing a Hook document which is just a link to a Nisus doc: I adding the bookmark/page number specifiers to the end of the URL, but I still ended up at the head of the doc —or rather the last remembered position.
That isn't encouraging for getting this to work from outside of Nisus Writer either. However Hook handles your link, the URL must not have arrived fully intact by the time Nisus Writer can see it. That could be a Hook behavior, but more likely it's an issue with macOS. Here's a Terminal command that tests this:

Code: Select all

open "file:///Users/martin/Desktop/example.rtf#BookmarkName"
I just tries this and by the time the URL goes from Terminal to Nisus Writer the bookmark name is lost. The system only passes Nisus Writer the bare file path. So this is almost certainly a dead-end from outside of Nisus Writer too.

To make this work reliably what we probably need to do is introduce a new custom URL scheme that the system won't bungle. Something like:

Code: Select all

nisus://~/Desktop/example.rtf#BookmarkName
This hypothetical custom scheme would always be handled by Nisus Writer and should avert data loss when processed by the system. The problem with something like this is that it's entirely dependent on Nisus Writer; such link would be useless without Nisus Writer. Of course links that depend on the local file system (eg: your user home folder) are inherently somewhat brittle anyways. Sharing documents with these links means you also need to send along any linked files too (and get them in the right location).
Post Reply