LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   How to have "Hypertext" Links in Text Files (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/how-to-have-hypertext-links-in-text-files-882256/)

porphyry5 05-23-2011 08:56 AM

How to have "Hypertext" Links in Text Files
 
3 Attachment(s)
A text file can behave as if it has internal hyperlinks, just like html or pdf; not quite so convenient to use, but much easier to create and maintain. The best way to appreciate it is to try it. Open the attached LinkedText in your favorite text editor. You'll notice that the text begins with a list of single compound words. These are your links. Select one of them, fire up your editor's Find function, and do whatever it takes to find the next instance. So for most gui editors, 2click the link, Ctrl-F, Enter. And there you have it.

Creating such files is a snap with the attached script txtlnk.sh. Save it in your current working directory (CWD). Open any other convenient text file in CWD.

In your terminal,

sh txtlnk.sh

and at the prompt type the name of the file you just opened in your text editor.

In that file, select, by dragging the mouse, any line down to include at least some text on a subsequent line. Repeat that process for as many different link/anchor pairs you wish to create.
NOTE: It only works by dragging the mouse, and, regardless of how many lines are included in any selection, the link/anchor pair will be formed only from the text on the 1st line that is selected. But it is essential to drag beyond the first line part way into a subsequent line of text.

When done, type a couple of digits and select only the digits with the mouse. The anchors are created in place, the links are sorted and placed at the start of the text, and the file is saved. Relax, the original was previously saved as a ~ file.

Unlike html, you can have multiple anchors for the same link with this method. If the first one doesn't suit, just press F3 to get the next one.

Lastly, you might want images with your text. At the appropriate places in your converted text, on their own lines, type something like

path/to/your/image.jpg

Select such paths by dragging with the mouse, again extending the selection into the text on a subsequent line, and run the attached script pixlnk.sh. I prefer starting this script with a hotkey because it terminates as soon as it starts ImageMagick's display portion, and must be re-invoked each time you need it.

NOTE: These scripts require xsel and imagemagick, which may not be included in your distro.
WARNING: These are my 4th and 5th Bash scripts, so no doubt rather amateurish. In particular, my scripts always assume that you have done the right thing, and, as I am the sole user of my system, have no clue as to the exigencies of multi-user systems


All times are GMT -5. The time now is 11:03 AM.