Formatting EPUB and Kindle Endnotes with Regular Expressions

Last week I described a method of adding note referents to text in OpenOffice and similar programs that allow the use of Regular Expressions in their Find and Replace. I also promised there to provide the code for formatting the notes section in the style of my earlier post on 'EPUB and Kindle Friendly Endnotes'. So here it is for the EPUB version:

Find:

([:digit:]+)(\t)(.*)

Replace:

<li id="note$1">$3 <a href="#ref$1">[back]</a></li>

And here is the KINDLE version:

Find:

([:digit:]+)(\t)(.*)

Replace:

<p class="noind" height="30"><a id="note$1">$1</a> $3 <a href="#noteref$1">[back]</a></p>

Note that the find remains exactly the same in both instances, and in order for this regular expression (regex) Find and Replace to work each note needs to be formatted with a number followed by a Tab followed by the text followed by a return, which is as you would expect and within the capabilities of any copy-editor using Word.

So there it is, replace the automated note referents with [1], [2], [3], etc. (see here) and format the notes as described in this post, then run the regular expressions to save you a whole lot of time writing code.

I hope this helps, and that it encourages you to explore regex even deeper.

Comments