HTML Indexing Bundle

Note: This post is over a year old. You may want to check later in this blog to see if there is new information.

Auto Index with Summaries PreviewThe HTML Indexing commands have evolved into a full bundle for TextMate. For those of you who told me the original commands saved you some time on your last project, this should make the next one a breeze. The shot on the left shows a quick preview of the new auto-index with summaries command, which scans for all anchors and pulls the first 10 words following them to create an index using a definition list with even/odd classnames on the lines for styling. Download is at the end of the post. Here’s a rundown from the included help file…

Creating the Anchors

The first step is to create the anchors in the document, or the places where the index links will jump to on the page. These can be headlines, first lines of text, or simply locations with no text. To create an anchor, press ⌃-⇧-R and select “Create Named Anchor” (1) from the menu. If you have text selected, it will offer you a suggested name. This command inserts only a snippet for you to edit.

Manually Creating Anchor Links

You can manually link text to your anchors by selecting the text (or image) to link, pressing ⌃-⇧-R, and selecting “Create Named Anchor Link” (2). It will give you a list of all of the anchors in the current page and selecting one will create the link to the anchor. It will be inserted as a snippet for you to edit as necessary.

Automatic Indexing

There are two indexing commands. From the ⌃-⇧-R menu, selecting “Create Index of Anchors” (3) will create an ordered list (ol) of all of the indexes in the order they appear in the document. The <ol> tag is a stop in the snippet, so it can easily be changed to an unordered list or have a class added or removed from it.

The second choice, “Create Index with Summaries” (4) will create a definition list (dl) with the link text as the definition term (dt) and the first 10 words of the following text as the summary. Truncated text will be followed by an ellipsis (…).

The resulting indexes include classes for easy styling of the indexes. These classes can be removed with some simple editing of the ruby commands, if you know what you’re doing.

Sub-indexing

Running either of the indexing commands while a portion of the document is selected will index only that part of the document and copy the results to the clipboard. There is a 5th command (“Insert Clipboard as Snippet”) in the ⌃-⇧-R menu that allows you to paste the results as a snippet at an appropriate location in the document.

Download: htmlindex_tm.zip

» » » » »
  1. David 07.13.07 / 8am

    Hi. A co-worker sent me this link suggesting that I might be interested. I read the post, but I’m afraid I don’t understand what the purpose of this is. What is the end result, and what do you do with it?

    Thanks! (and sorry for the silly question)

  2. brett 07.13.07 / 11am

    It’s a bundle for TextMate. It allows you to quickly insert <a name="anchorname"></a> tags in your document, and then automatically create indexes with links that jump to those anchors in your document.

  3. Rob 07.16.07 / 7am

    Giving this a shot, but neither of the Create Index commands is working for me. I’m getting “No anchors found… Please create anchors first” error, but I’ve got 3 anchors on the page.

    Thanks! -Rob

  4. brett 07.16.07 / 8am

    What do your anchors look like? It looks for a very specific regex, so if they were created by hand or have class definitions, it might have trouble. Paste them here with code tags and let me see if I can fix it…

  5. Rob 07.16.07 / 8am

    check the spam folder :-/

    They’re empty anchors ([a name=”..”][/a]), so I think that’s what’s doing it. It worked with non-empty ones ([a name=”…”]…[/a]).

    However, the closing [/ol] tag actually was missing the slash.

  6. brett 07.16.07 / 8am

    Yeah, it would be hard to create an index if the anchors didn’t have names ;). You’re correct, I did miss the slash on the closing ol, do you know how to edit it? When I have a sec, I’ll update the bundle.

  7. brett 07.16.07 / 2pm

    You can download a fixed version of the bundle (same link) now. I’ve also updated the help docs to note that naming the anchors is mandatory…

  8. Laurent SJ 10.08.07 / 12pm

    Thanks a lot for another superb useful TM bundle !

    Can’t wait for your upcoming PrinceXML TM Bundle ;)

Have your say

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>




Safari hates me