Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-22 14:11:56

JeremyCherfas
Member
Registered: 2012-09-01
Posts: 18

[textile] Footnotes backlink

I finally figured out how to use the various flavours of footnote in Textile, but one thing bothers me. Is there any way to place the backlink after the note, rather than before? To me that seems to much more logical. I saw some comments about editing Textile.php, but I confess that scares me.

What would be nice would be a plugin as simple as one I used to use with WordPress, where you simply inserted the footnote between ((double parentheses)). It is here No idea how hard it is to translate from WP to TextPattern

Jeremy

Offline

#2 2012-09-22 20:12:53

etc
Developer
Registered: 2010-11-11
Posts: 5,186
Website GitHub

Re: [textile] Footnotes backlink

Just moving a link is an easy task, either with jQuery or with etc_query: replace <txp:body /> in article form by

<txp:etc_query data='<txp:body />'
replace="//a[starts-with(@href,'#noteref')]/../..+={*[1]};//a[starts-with(@href,'#noteref')]/../../*[1]" />

You can see the result on this page. This is, however, highly inefficient: we have to modify the body tree on each connection. It would be much better to do it just before article save, but, unless I miss something, there is no callback allowing it. I have asked for such callback some time ago, but it does not seem to gain much support for the moment.

Last edited by etc (2012-09-22 20:37:58)

Offline

#3 2012-09-23 08:33:59

JeremyCherfas
Member
Registered: 2012-09-01
Posts: 18

Re: [textile] Footnotes backlink

That’s very cool, but when you say it is highly inefficient, can you estimate what kind of difference it might make in, say, page load times? Or maybe I should just try it and do a couple of benchmarks.

Jeremy

Offline

#4 2012-09-23 10:54:22

etc
Developer
Registered: 2010-11-11
Posts: 5,186
Website GitHub

Re: [textile] Footnotes backlink

Parsing and rewriting the dom tree will certainly take some time, either server or client-side. The amount depends on the article size/complexity, and the number of footnotes. I have measured something like 0.001s for the example above, but feel free to test, you can pass debug="1" attribute to etc_query to evaluate runtimes. This time will be imperceptible, anyway, and I will yet optimize etc_query code for nodes moving. The inefficiency is rather conceptual: there could be a much better way to do it.

And the best option would be Textile integration, but I can’t help with it.

Offline

#5 2012-09-25 12:46:18

etc
Developer
Registered: 2010-11-11
Posts: 5,186
Website GitHub

Re: [textile] Footnotes backlink

The latest version (1.1) is even simpler and faster:

<txp:etc_query data='<txp:body />'
  replace="//a[starts-with(@href,'#noteref')]/../=.." />

Offline

#6 2012-09-26 17:21:25

JeremyCherfas
Member
Registered: 2012-09-01
Posts: 18

Re: [textile] Footnotes backlink

Beautiful. Thanks.

Offline

Board footer

Powered by FluxBB