I wrote a Web page the other day and realized that I wanted footnotes. I wanted to keep the main message in the main text and have annotations for some of the side points. It’s easy enough to do, right? Just put some text in a table at the end, use those cute little sup tags around the footnote numbers, and hack away.
I wrote a Web page the other day and realized that I wanted footnotes. I wanted to keep the main message in the main text and have annotations for some of the side points. It’s easy enough to do, right? Just put some text in a table at the end, use those cute little sup tags around the footnote numbers, and hack away.
Oops…those little numbers! I started to dread getting six footnotes inserted and then having to go back to insert yet another between numbers 2 and 3. It was going to be a maintenance nightmare. Could Perl help? Of course!
Expending about 10 times the amount of labor I would have spent doing this manually, I hacked out the program in Listing One. This obviously wasn’t very efficient, so to make the time that I invested worthwhile, I’ll pass the program along to you. Besides, it illustrates how to create an angly-bracket metalanguage for your HTML and XML processing. Yeah, that justifies it.
The idea is to insert a footnote into the main flow using a made-up tag of foot. The processor pass then takes those out, replacing them with an anchor link and a unique number. Then, at the end of the file, all the footnotes are dumped out. For an example, look at the end of the program. And, I couldn’t stop there, so I decided to allow nested footnotes (like those found on the alt.sysadmin.recovery newsgroup). About half of my coding time…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: