For example, see http://groups.drupal.org/node/2618#toc1. Notice how the later TOC boxes all point back to ids belonging to the initial post. No good.

This is a bit tricky to solve. My best attempt is that we need to generate unique links for any piece of content. The way t odo that is to to either md(time(). $content) and then append 1 or 2 or 3. Or we use some microtime() trick. We need to assure that the links on the OL and in the body of the post match up.

Comments

acp’s picture

Hello there,

while I haven't yet started coding, I was thinking of a solution to this particular problem. When you talk about md, it's as in md5 ? The thing I don't like much about this solution is that the anchors will be getting kind of long...

It's been a while I didn't get into drupal, so I'm not positive when saying this, but maybe we could just append the node_id to the anchors. Comments (and forum posts for that matter) have a unique node_id too right ?

moshe weitzman’s picture

you can append that but only during nodeapi(view) and comment(view). you don't know any unique ID during the filter operation. Steven suggested doing a preg_replace() in toc_nodeapi('view') which substitutued out #toc for node-toc-n or similar

acp’s picture

Hi,

I've got another argument against the usage of time. If a link is bookmarked and the node is modified/updated in a way, the bookmark won't be valid anymore. That's not a HUGE problem, but it would be great to avoid too.

Your proposed solution is feasible but isn't this a practice to avoid ? I mean isn't a filter supposed to operate on the text within a _filter hook ? Of course I realize that this might actually be the only appropriate solution, I wanted just to know if it would be against any sort of "programming guidelines", not being a drupal expert...

In the meantime I'll check out the other pending issues.

acp

acp’s picture

Assigned: Unassigned » acp
acp’s picture

Status: Active » Fixed

Fixed by using the second proposition. preg_replace is called to change all references of #tocNUMBER to #toc-nid-NUMBER.

Sorry for the huge delay :S

acp’s picture

Status: Fixed » Closed (fixed)