I wrote a whole entry about my solution to the footnote problems that I’m having since I de-crufted my links. Basically I worked out that it isn’t that hard (or long winded) to use Textile directly to make footnotes instead of using the specific Textile footnote syntax. It was great, a little longer than the simple [1]
type of input you are supposed to use, but it worked… Except it didn’t work1.
Something was mysteriously replacing my relative links with absolute links, absolute links that went to the /index.php page that I want to keep people away from. Argh… So I tested making the link in html directly: <a href="#fn1">1</a>
… Nope, still gets replaced. At first I thought that maybe there was some setting in the Movable Type preferences that automatically turned relative links into absolute links, cleverly outsmarting me in the name of making my links bulletproof. But no, it’s Textile doing it. If I remove Textile as the text formatting option the links stay happily relative.
In spite of the fact that there’s no mention in the documentation, relative links get turned into absolute links unless you preface them with a ./
2. Now that I was on the right track a quick google search set me straight with the ./
behavior.
Actually this explained a lot because I was very puzzled when both the documentation and the perl code of the plugin seemed to me to be saying that the footnotes should generate a link reading: <a href="#fn1">1</a>
. So the answer is that, yes, that is exactly what it does. However later on there’s some code that translates that link into an absolute link like: <a href="http://blog.tapirtype.com/2006/10/a_footnote_solution/index.php#fn1">1</a>
.
Fortunately it’s easy to fix by telling Textile to generate the footnote link as <a href="./#fn1">
. Just search the perl code of the Textile plugin for the text “fntag” and you should see the following bit of code:
# footnotes
if ($text =~ m/[^ ]\[\d+\]/) {
my $fntag = '<sup';
$fntag .= ' class="'.$self->{css}{class_footnote}.'"'
if $self->{css}{class_footnote};
$fntag .= '><a href="#'.($self->{css}{id_footnote_prefix}||'fn');
$text =~ s|([^ ])\[(\d+)\]|$1$fntag$2">$2</a></sup>|g;
}
This is the code responsible for replacing the footnote tag with the anchor. All you have to do to fix it is add a ./
into the anchor so that the line reads:
$fntag .= '><a href="
./#'.($self->{css}{id_footnote_prefix}||'fn');
Problem solved! Textile is now generating footnotes that link correctly! The only problem with this is that the old behavior would save you if you inserted a footnote into the excerpt because it would generate an absolute link to the footnote in the individual entry archive. Now it will try to find the footnote on the index page which probably isn’t what you want. If you want to put a footnote link in the excerpt you could just make it manually like:
<sup class="footnote">
"1":http://blog.tapirtype.com/2006/10/a_footnote_solution/#fn1
</sup>
You don’t have to do anything special to make the footnote itself, just use fn1.
like normal. I’ve demonstrated this with a useless footnote at the end of the excerpt in this entry that I created exactly as I just described.
Update 10/29/06: Want footnotes in the excerpt sometimes (I mean the footnotes themselves, not just a link to a footnote)? I’ve got it all worked out. For the footnote link just write <sup class="footnote">"1":./#fn1-10-29-06-footnote-sln</sup>
. Yeah, it’s kind of awkward, but we’re only doing this occasionally right? The important part is giving it a unique id. For the footnote itself write: p(footnote fn1). <sup id="10-29-06-footnote-sln-fn1">1</sup> footnote text
if it is the first footnote, or just p(footnote#fn1-10-29-06-footnote-sln). <sup>2</sup> footnote text
if it is a lower footnote.
The important thing here is that I was using the id fn1
to put extra spacing above the footnote block. This will get fragged if I make the ids unique. To preserve the spacing I just added a class fn1
to the style sheet doing all the same stuff I had the id fn1
doing before. So for the first footnote, the paragraph as both the class footnote
and the class fn1
and I just put the id for the link target on the <sup>
. Probably all pretty obvious stuff, but hey, I figured it might be useful to someone someday.
Update 10/30/06: I corrected the last update in which I gave the link target id a value that started with a digit which won’t validate. Start with a letter instead.
1 This is a footnote for the sake of demonstrating the manual footnote link from the excerpt.
2 I don’t mean to be hard on Brad Choate or Dean Allen, the authors of the Movable Type plugin and original version of textile respectively. They are both demigods of this stuff who have contributed these really useful tools without asking anything in return. And yes, this was mostly just an excuse to test out a footnote.