Zim

[Feature Request] Automatic linking by tags/names

Bug #601055 reported by Frank Uebel
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Zim
Incomplete
Undecided
Frank Uebel

Bug Description

This is probably related to #575118 and #528313 (and #426771).

I constantly write transcripts with lots of links to other pages. It is cumbersome to link them all by hand afterwards (same notebook, but different namespaces etc, lots ok clicking and typing). The links sometimes are sometimes called different names even when they link to the same page.
The target is to have pages linked automatically by keywords. A page might be tagged with certain titles/names/keywords and when such keyword is entered on another page, an appropriate [[]] is set automatically.
This should work globally within a notebook and always create links from the top level ":...".

Example:

====== :group1:pageA =====
Here be some text. And some other text.
Followed by even more text.

#NAME["pageA"]
#NAME["stupid"]
===================

====== :group2:pageB =====
This is a second page.
It still has some text in it.

#NAME["example"]
#NAME["codesnipped"]
===================

So, pageA is linked to the keywords "pageA" and "stupid" while being in the group1 leaf, while pageB is known as "example" and "codesnipped" and in the group2 namespace
When page c is create like this:

====== page c (before autoresolution) =====
Oh look at pageA, there is a stupid example of a codesnipped there.
===========================================

it becomes this:
====== page c (after autoresolution) =====
Oh look at [[:group1:pageA|pageA]], there is a [[:group1:pageA|stpudid]] [[:group2:pageB|example]] of a [[:group2:pageB|codesnipped]] there.
==========================================

It doesn't need to be instantaneous, it would be ok if it works after CTRL-R or manually calling the tool.
The benefit for this would be that multiple names might be assigned to a single page and one does not have to add a link and then manually change the name of the link.

The tool/function might first scan all pages in the current notebook and collect all "name"->"page" links (or keeping them in an index). If a name/alias occurs more than once, an error is raised and the tool stops. Otherwise it might scan all pages again and replace all keywords with the [[$pagename|$keyword]] content.

I am not yet sure how to handle updates, if maybe a keyword is moved from one page to another, the existing links to it might need to be updated as well. Not yet decided.

Revision history for this message
Frank Uebel (fuebel) wrote :

Please ignore the typos in the example and in the text, it went through several stages of rewriting before I submitted it....

Revision history for this message
Frank Uebel (fuebel) wrote :

Two comments:

1) This is separate from any tags. It is purely a naming thing

2) The more I think about it, the more I think it should only be done on request. Checking each entered word against multiple possibilities permanently would probably introduce lag. So it should be done like a menu action as "print to browser", only that it rebuilds all pages if it is executed. I'm trying to implement it as a plugin, but since I've never coded in python before, I will probably fail or produce ugly code at best.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Would this be related to page aliases? There is an open request for that if I'm not mistaken.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

After more detailed reading I see 2 separate requests. Please correct me if I misunderstand.

1) Allow multiple names for the same page -> aliasing
2) Automatically turn words that match a page name into a link

1) Request for aliases is in bug #288583

2) This can be done by a plugin that is triggered on the signal for autoformatting. Such a plugin should have an option to either complete only links in current namespace or to complete links to anywhere in the page hierarchy. Advantage of triggering on autoformatting is that the link appears instantaneously and ^Z will undo it allowing you to continue typing.

Since zim already has a page index stored as a database such a plugin can be done quite easily with reasonable performance. See the handling of the "end_of_word" signal in the "insert symbol" plugin for an example how to hook into autoformatting.

Probably would only need to add a method to the Index class to request all pages with a specific basename. This is a simple SQL query to add.

Advanged version of the plugin could popup a menu when multiple candidates for linking are found, but I would leave that out for an initial version.

Revision history for this message
Frank Uebel (fuebel) wrote :

I agree, that this request could be implemented with aliases, like you described. It is not what I originally intended, but it would somewhat work. My intention to have explicit tags within the individual pages was so that a finer control of what is automatically linked is possible. For some pages I would not like to have the page name linked, even if a page with this name exists (page is ognored for autolinking). Some others might contain a lot of aliases.
However, if this plugin ("2)") could be configured to only work on aliases and ignore the "basename" of the pages, then even this would be possible.
As I apparently will not have time to start up my python knowledge, I won't tackle this. Do you think setting up a bounty for this one would be a good idea? Or if somebody could create a very basic version of this (as soon as we have aliasing), I could take it from there.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

Could you explain a little bit more about the use case for this feature? Seems to me you are trying to solve a fairly specific issue, but I don't see the reason why you would want to link only by "tagged" names but not by real page names. Although such behavior is of course possible, it kind of breaks how zim (or any wiki implementation) works today. So I wonder what issue you have with page names that triggers this request.

Revision history for this message
Frank Uebel (fuebel) wrote :

Hi Jaap, yes, it is indeed a specific problem. I am using zim to keep track of various rpg groups, I write journals and so on and create individual pages for all kinds of events/characters/locations and such. The records tend to be very large, with lots of references to other pages (maybe up to one hundred in one log). Since I had to organize the articles, I have a rather large article tree and linking them manually is alot of work (so I just stopped doing that, which is sad).
I do have pages, that are only there to group subsequent pages. I would not like to automatically link them when running ctrl-R. Other pages exists with the same name in different branches of the tree. For example, different characters might have the same sub-page "appearance" or so.
Maybe I am not using ZIM as it was intended, but it works for me.

Anyhow, I did not want to cause any trouble and therefore close this request. Either I do find the time to do it myself, or I don't. It is not an issue about life and death.

Sorry for the inconvenience, Frank

Revision history for this message
Frank Uebel (fuebel) wrote :

Closed

Changed in zim:
assignee: nobody → Frank Uebel (fuebel)
status: New → Invalid
Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote :

I opened bug #604545 to track the second part of this discussion.

Based on you description I think linking pages on basename as well is not killing for your usage pattern as long is it is easy to undo. Proposed solution based on auto-linking would simply allow ^Z to undo linking.

Btw. I'm quite interested in the use case of using zim for RPG documentation. It is quite different from my standard cases of scientific note taking and probably closer to what is needed for creative writing. I definitely want zim to be generic enough to be useful for such applications. If you have some time maybe you could document your way of using zim in the wiki at http://zim-wiki.org/wiki . Thanks.

Revision history for this message
Frank Uebel (fuebel) wrote :

Finally found some time for this. As this is my first python program ever, I've started from the tasks plugin and went from there. Detecting keywords (via page-indexed, page-deleted) and replacing them via end-of-word and apply_tag works already. However, I can not get a global refresh like in ctrl-R to rescan the whole textbuffer. I see the signal open-page, but can not find the correct hook to scan all words against my replacement table. Can somebody point me into the right direction here? I would have to have something like the end-of-word hook, but for all words in the loaded textbuffer. If that makes sense at all...
Thanks, Frank

Changed in zim:
status: Invalid → Opinion
Revision history for this message
Frank Uebel (fuebel) wrote :

I've tried to put something together with the KEYWORDS inline. I currently do not want to mess with Zims internal structures. The more I work with the code, the more respect I have for Jaaps work...
This is basically a rip-off of Jaaps Tasklist plugin, mixed with a bit of novice python code. It's ugly, missing features and it is slow, but it works for me. autolink.py goes in zim/plugins.

Revision history for this message
Frank Uebel (fuebel) wrote :

Set to incomplete, because, well, it is incomplete ;)

Changed in zim:
status: Opinion → Incomplete
Revision history for this message
Frank Uebel (fuebel) wrote :

And the preliminary documentation goes into data/manual/Plugins...

I don't think it would be fit for a public plugin, but maybe somebody could use it.

Revision history for this message
Jaap Karssenberg (jaap.karssenberg) wrote : Re: [Bug 601055] Re: [Feature Request] Automatic linking by tags/names

Code for this plugin looks quite nice already. And documentation page
helps :) Didn't have time to try it out though.

One suggestion, maybe it is better to talk of "aliases" or something
like that instead of "keywords". Reason is that with the name
"keywords" people will expect that multiple pages can have the same
keyword, like tags. However in this plugin you want unique keys to
identify a page, which sounds more like an alias for the page name to
me. Alternative you could call it a "shortcut" for the page name or
something similar.

Revision history for this message
Frank Uebel (fuebel) wrote :

Thanks for the feedback ;)
There are several problems with this version, like a messed up startup sequence where on first start it tries to access the notebook.index when it is not yet initialized (so it seems). Will look into this.

I don't want to interfere with the alias functions, that are discussed in the other request, but "@SHORTCUTS" sounds about right. Will probably enable both, as it is only a regex.
Biggest missing function is to use this on existing text/articles and properly tap into the rebuilding process. This will be next, together with some bugfixes.

Thanks for your time here and with ZIM in general. Without it, I might have not started some of my own projects.
Regards, Frank

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.