Quote:
Originally Posted by Elvys
I'm new to the forum, so hello everyone!
|
Hey. Welcome.
Quote:
Originally Posted by Elvys
I'm been looking for a way to automatically create links to a glossary, but couldn't find any…
I'm a big fan of fantasy books, which often come with a glossary of terms at the end. I find them very helpful because I'm terrible at remembering names.
With eInk readers it's kind of a pain to go back and forth to check a word out, so I was trying to implement links on every word present on the glossary.
|
You'd probably be able to use Regex to accomplish most of this.
1.
Ctrl+F. This will open the Find panel.
2. Make sure you are on "Mode: Regex".
3. In the Find box, type this:
\b(Alabama|Bengals|Cataclysms|Drinks|Eggnog)\b
and in the Replace box, type this:
<a href="../Text/Glossary.xhtml#\1">\1</a>
* * *
Side Note: You can add a big list of terms in the search, as long as you keep using the | between terms/names.
In plain English, what this Regex says is:
"Look for the word "Alabama" OR "Bengals" OR "Cataclysms" OR [...]"
and Replace says:
"Replace the word above + give it a link to the Glossary file."
* * *
This should take a sentence like this:
Code:
<p>I went to Alabama to drink some Eggnog.</p>
and change it into:
Code:
<p>I went to <a href="../Text/Glossary.xhtml#Alabama">Alabama</a> to drink some <a href="../Text/Glossary.xhtml#Eggnog">Eggnog</a>.</p>
4. Go into your Glossary file, and make sure each of those words has an
id.
So if your glossary had this:
Code:
<p>Alabama: A state in the United States</p>
<p>Bengals: A type of animal.</p>
You'd want to ultimately change it to:
Code:
<p id="Alabama">Alabama: A state in the United States</p>
<p id="Bengals">Bengals: A type of animal.</p>
To accomplish this, do a similar Search/Replace:
Search: <p>([^:]+)
Replace: <p id="\1">\1
That would take whatever's before the colon, and duplicate it into the paragraph's
id.
(This all depends on your book's code though, hopefully each paragraph has a class="glossary" or something easier to make it stand out.)
* * *
Usage Note: DO NOT do this in an ebook for sale in the major retailers. ONLY do this on personal ebook copies.
For more details on the problems/why, read these previous "glossary" topics:
2019: "Backlinks arrrrrrgh!"
2017: "cross links randomly become footnotes"
Especially mine+Hitch's posts. We've discussed this "many-to-one" linking problem many times over the years.
Quote:
Originally Posted by KevinH
In addition I recommend making a Checkpoint of uour epub before running your saved search group in case of mistakes so that a simple restore will allow you to try again.
|
Oh yeah, definitely. Very easy to make major mistakes with huge changes like this.