TW links in non-Bible modules (rtf format)

Share your favorite tips, workarounds and shortcuts for theWord
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

TW links in non-Bible modules (rtf format)

Post by csterg »

Please, read first the entry for links in Bible modules here: http://forum.theword.gr/viewtopic.php?p=1733#1733

The URL format for non-Bible links is:

Code: Select all

tw://bible|cmt|dct|bk|book|map|media.[module-id]?[parameters]#[anchor]
The [module-id] is the either the name of the filename (without the .twm extension, case ignored) or the value of the ‘id’ config value (in table config) in utf8 format.

The [parameters] use the standard [name=value] format.
Supported parameters:
- t: refers to a topic subject
- tid: refers to the internal topic id (the id in the database of the topics table - you can get this value from within TW).
- [anchor] is an anchor point within the text itself (a bookmark if you like). In RTF, the bookmarks are defined with {\*\bkmkstart [ANCHOR]}{\*\bkmkend [ANCHOR]}. This is similar to html anchor points defined with #. Notice, that the [ANCHOR] should start with # if there is nothing else in the URL (see below examples)

Examples:
- tw://dct.webster?t=Aaron -> links to the Webster dictionary to topic ‘Aaron’. Can be written also as tw://dct.webster.dct?t=Aaron (either webster or webster.dct are OK)
- #bookmark1: in case of anchors, the whole ‘tw://…’ can be ommted and only the name of the anchor bookmark can be given. For compatibility with other readers (MS Word, etc) the bookmark name should start with a letter and contain only letters and digits.
- tw://dct.mydct?tid=1#b3 -> this is a link to a dictionary name ‘mydct’, to the topic id 1 (this is the id of the internal table 'topics') and to the bookmark in document named 'b3'.

Difference between tid and t parameters in URLs
There are 2 ways to define a link to a topic: the tid and the t parameter. Both have advantages and disadvantages.
The t parameter is used with the actual topic subject as it’s value (e.g. t=Aaron). If the topic subject changes (is updated), then the link will no longer be valid. In these cases (especially when the subject is changed from within the program), the id remains the same.
The tid parameter uses the internal id of the actual topic (the one in the 'topics' table). This only change in cases the topic is deleted. This is the safest way to make links, but there is the disadvantage that you need to know this internal id. TW provides a way to find this id from within the program itself.

Here is an example RTF that defines a bookmark (anchor point) within the document in one place, and also defines in another place a link to that bookmark. Clicking on this link will make the document 'jump' to the bookmark position:

Code: Select all

This is some text. Here follows a link to another part in the document: {\field{\*\fldinst HYPERLINK #b1}{\fldrslt Click me}}.
\par\par\par\par\par\par\par\par\par
This is the target of the above link. Once you click on the 'Click me' link, the viewer will jump to the following line:
{\*\bkmkstart b1}{\*\bkmkend b1}Here is the anchor!
\par
Hope this helps!
Hope this helps,
Costas
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

How to link to a commentary topic from the same module

Post by csterg »

Using the keyword "[self]" instead of the module name in a link

It is often useful to create links from one topic of a module to another topic within the same module. In these cases, instead of using the module name in the link, the keyword "[self]" can be used. Let’s suppose that we have a commentary with an entry in "Matt 10:1-16" and there is also a bookmark defined in that topic named "b1" that is anchored to a point towards the end of the document.

To create a link from another topic of the same commentary to this one, you can have the url:

Code: Select all

tw://[self]?t=40.10.1-16#b1
Notice the following:
1. The module name used is “[self]”. This means that the link is within the current module.
2. Since this is a commentary, the Topic parameter (t) can be any valid topic for which there is an entry (in that case Matt 10:1-16, denoted with t=40.10.1-16)
3. The “#b1” is optional and just denotes a bookmark in the target topic.

Costas
Last edited by csterg on Thu Apr 24, 2008 6:06 pm, edited 1 time in total.
gennesse
Posts: 103
Joined: Tue Jan 22, 2008 4:10 pm
Location: Nederland

Post by gennesse »

I have pasted this link and your ather examples in a new module in The Word (preview version 3) to try it out but it did not work. (I tried to change an existing verse note with SQlite database browser, inserted it in the rtf content and it did not show).

Is it not possible in the preview version?
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Post by csterg »

Yes, it is.
You don't need to edit any the sqlite files...

Do this:
Right click in the Bible view and select: "Hypertext link..."
Enter the text you want in the 'Text' field, and in the 'Target' enter the URL: (e.g. tw://[self]?t=1.1.1)

For a book or dictionary, write: tw://[self]?t=[topic]
where [topic] is your topic subject.

You can also select some text and then right-click and pick the 'Hypertext link' to make this a link,

Tell me if you made it,
Costas
Gert-Jan
Posts: 203
Joined: Tue Apr 03, 2007 9:13 pm
Location: Netherlands

Re: TW links in non-Bible modules (rtf format)

Post by Gert-Jan »

Hi Costas,

I'm preparing RTF files to import, and I want to link to a bookmark (a footnote) within the same topic. So I don't know the topic-id beforehand. I would guess that I can use the bold quoted sentence, isn't it?
csterg wrote:Examples:
- tw://dct.webster?t=Aaron -> links to the Webster dictionary to topic ‘Aaron’. Can be written also as tw://dct.webster.dct?t=Aaron (either webster or webster.dct are OK)
- #bookmark1: in case of anchors, the whole ‘tw://…’ can be ommted and only the name of the anchor bookmark can be given. For compatibility with other readers (MS Word, etc) the bookmark name should start with a letter and contain only letters and digits.
- tw://dct.mydct?tid=1#b3 -> this is a link to a dictionary name ‘mydct’, to the topic id 1 (this is the id of the internal table 'topics') and to the bookmark in document named 'b3'.
So I'm trying to add the target manually, but it seems that I'm doing something wrong. Obviously I cannot use the following:

Code: Select all

tw://[self]?tid=6#bookmark-
as I don't know the tid before importing, and I don't want to use t=...
But shouldn't this work as target?

Code: Select all

#bookmark-
G-J

*Edit*

I now see that I can use:

Code: Select all

#bookmark
(so without dash) to click and jump to the anchor. But how to show the footnote in a popup?
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Re: TW links in non-Bible modules (rtf format)

Post by csterg »

Hm, hard question with no answer.
In v.3.0.8 i have added read-only support for real rtf footnotes (e.g. footnote appears when the mouse goes over the number but you cannot edit them). if you want, do it like that and then i can run a script to convert these to 'tw-like-footnotes'. This is the best i can think of for now,
Costas
Gert-Jan
Posts: 203
Joined: Tue Apr 03, 2007 9:13 pm
Location: Netherlands

Re: TW links in non-Bible modules (rtf format)

Post by Gert-Jan »

Thanks.

Then, is there a way to know beforehand what the tid will be? Does the importer always start from the same number, and in what order are filenames and folders processed? I'm thinking of adding a global counter to each entry, so that I can determine the tid to use in the link (I don't know RTF footnotes :D ).

BTW: I'm already using a 'local' counter (per folder with files) to import the files in the right order. In the Importer I use the regex to sort by number, but I have to remove these numbers from the topic name afterwards in TW.
Could it be possible to add an option (checkbox) to the Importer to sort by a certain regex, but to omit the matched part from the topic name?

Eg number the files like this:

Code: Select all

1_First filename (or folder)
2_Second filename (or folder)
etc
to get these topics

Code: Select all

First filename (or folder)
Second filename (or folder)
etc
So the regex would be (\d+)_ in this case.

G-J
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Re: TW links in non-Bible modules (rtf format)

Post by csterg »

Let me suggest something else:
use a placeholder in place of topic id (e.g. __TOPICID__). After the import, run a simple SQL command in the .twm file to replace the __TOPICID__ with the actual topic id. The sql would look like that:

Code: Select all

update content set data = replace(data, '__TOPICID__', topic_id);
This is the easiest and fastest way to do so
Costas
Gert-Jan
Posts: 203
Joined: Tue Apr 03, 2007 9:13 pm
Location: Netherlands

Re: TW links in non-Bible modules (rtf format)

Post by Gert-Jan »

csterg wrote:This is the easiest and fastest way to do so
Sure, this works very well! Thanks again for your help.

One little thing. My color table looks like:

Code: Select all

{\colortbl\red0\green0\blue0;\red0\green0\blue255;\red255\green0\blue0;}
and the link itself:

Code: Select all

{\cf2\super{\field{\*\fldinst{HYPERLINK "tw://[self]?tid=__TOPICID__#n53-"}}{\fldrslt 53}}}
(before running the SQL).

But the link shows up in blue (while it's -and should be- red in other RTF editors). Any idea? TW default colors?
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Re: TW links in non-Bible modules (rtf format)

Post by csterg »

Send me a sample rtf to check pls.
Here are the default colors when no rtf header is present:

Code: Select all

'{\colortbl ;' +
    '\red0\green0\blue0;' +
    '\red0\green0\blue255;' +
    '\red150\green60\blue100;' + //maroon; 
    '\red0\green255\blue0;' +
    '\red255\green0\blue255;' +
    '\red255\green0\blue0;' +
    '\red255\green255\blue0;' +
    '\red255\green255\blue255;' +
    '\red0\green0\blue128;' +
    '\red0\green128\blue128;' +
    '\red255\green0\blue0;' + //dark green
    '\red128\green0\blue128;' +
    '\red128\green0\blue0;' +
    '\red128\green128\blue0;' +
    '\red128\green128\blue128;' +
    '\red192\green192\blue192;}';
When the rtf header is there, it should be used,
Costas
RubioTerra
Posts: 732
Joined: Wed Sep 23, 2009 5:13 pm
Location: Brasília, Brazil

Re: TW links in non-Bible modules (rtf format)

Post by RubioTerra »

Is there a way to link to the default dictionaries (Strong and Morphology) within non-bible modules?
Rúbio R. C. Terra
Brasília/DF - Brasil
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Re: TW links in non-Bible modules (rtf format)

Post by csterg »

Code: Select all

tw://[strong]?G1
tw://[morph]?XXX
Costas
RubioTerra
Posts: 732
Joined: Wed Sep 23, 2009 5:13 pm
Location: Brasília, Brazil

Re: TW links in non-Bible modules (rtf format)

Post by RubioTerra »

I understand one can group several non-consecutive verses in the same popup in xrefs, is there a way to do the same in TW links? As in "Gn 1:8,13,19,23,31".
Rúbio R. C. Terra
Brasília/DF - Brasil
csterg
Site Admin
Posts: 8627
Joined: Tue Aug 29, 2006 3:09 pm
Location: Corfu, Greece
Contact:

Re: TW links in non-Bible modules (rtf format)

Post by csterg »

Sorry, no;
The actual format is: [ulr1]|[url2]|... (e.g. tw://bible.*?id=1.1.1|tw://bible.*?id=1.1.2), yet this is only supported in the Bible view; i am not sure how useful that would be in the book view
Costas
Jerry20
Posts: 175
Joined: Fri Jul 29, 2011 7:49 pm

Re: TW links in non-Bible modules (rtf format)

Post by Jerry20 »

csterg wrote: Here are the default colors when no rtf header is present:

When the rtf header is there, it should be used,
Costas
Hi Costas,

What about the default font table?

Thanks
Post Reply