jeffcoughlin.com

How'd he do that? Dynamic Anchor Links using CFMX and jTidy

On a recent site I worked on (www.middlesexhospital.org) one of the requirements was to take the body from dynamic content pages and make an unordered list of anchored links pointing to the <h*> heading tags on the page.

Example body textMost copywriters today write correctly using headings (and nested headings).
(Click on the example image to the left).
<h1 id="Heading-1a">Heading 1a</h1>
<p>Some paragraph text.</p>
<h2 id="Heading-2a">Heading 2a</h2>
<p>Some paragraph text.</p>
<h2 id="Heading-2b">Heading 2b</h2>
<p>Some paragraph text.</p>
<h3 id="Heading-3a">Heading 3a</h3>
<p>Some paragraph text.</p>

Example unordered listReferencing the id attributes for the <h*> heading tags you can now provide anchored bookmark links pointing to them in an unordered list (apply styles as needed).
(Click on the example image to the right)
<ul title="Page navigation tree">
<li><a href="#Heading-1a">Heading 1a
<ul>
<li><a href="#Heading-2a">Heading 2a</a></li>
<li><a href="#Heading-2b">Heading 2b</a>
<ul>
<li><a href="#Heading-3a">Heading 3a</a></li>
</ul>
</li>
</ul>
</li>
</ul>

So given the body, how do we create the unordered list dynamically? Also, I don't want to make my users have to know how to set id attributes in <h*> heading tags (especially if they are using a WYSIWYG editor such as FCKEditor or htmlArea to edit their content).

Read more in this tutorial.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Roger Benningfield's Gravatar I'm glad you finally got it working to your satisfaction... I know the whole thing was a pain in the butt.

Out of curiousity, what bugs were you seeing in the nightly jTidy builds? I've been running r8 for a few months now, and haven't see any problems.
#1 by Roger Benningfield | 4/23/05 4:12 AM
Jeff Coughlin's Gravatar I don't recall what the errors were. Spike was crawling through the java source code and found multiple errors throughout. However when he ran through the latest stable build (from 2001) it was just that... stable.

The only downside was that some of my pages were not validating correctly due to the windows special characters. So I gave him a the list and he wrote a quick custom method.

I wrote the original code for a Farcry installation, but modified it to be usable anywhere (the version you see in the download). The version I have provided can work in Farcry as well (and is the version I am currently using).
#2 by Jeff Coughlin | 4/23/05 2:56 PM
Anuj Gakhar's Gravatar Excellent article on jtidy....thanks a lot...I also liked the way you used Xpath to do starts-with and string-length.....
#3 by Anuj Gakhar | 11/27/07 9:11 AM



BlogCFC 5.9.8.007 by Raymond Camden | RSS | Contact Blog Owner