Tags:
create new tag
view all tags
I often want to sort links in alphabetical order based on what will appear in view. A typical situation is with links as separate list items -- bulleted or numbered -- see #Example. (The bulleted list links I'm considering are not the result of an inline search, so any sort capability built into the inline search will not help.)

There are difficulties with achieving this, so I have an RFE and some possibilities for workarounds.

Contents

Difficulties

There are a few difficulties with this:

  • There is no facility within TWiki to help with this. (Something could be added to the JavaScript editor that has been started.)

  • If you copy and paste the links to another application to do the sorting, the double square bracket syntax is inconvenient to sort because the link location (with, for example, the "http://") appears first, and alphabetic ordering by link location usually bears little resemblance to alphabetic ordering by link name.

  • If you have some WikiWord links and some links defined by the double square bracket syntax, all the WikiWord links without the double square brackets will be grouped together after (??) the double square bracket links. A workaround for this problem is to always use the double square bracket syntax, or, as discussed later, develop sort procedures which ignore the double square bracket prefix in programs that can do so.

Note: There are a few extra complications I haven't considered yet:

  • I forget "proper" sort order, but I think that if a link name (a title) begins with a "noise word" like "A", "An", or "The" it should be ignored and the sort order based on the next word. A simple workaround is to rearrange the title so the noise word is at the end, prefixed by a comma, like "Linux Cookbook, The".

  • See "Running Linux" in the following list -- it is not online and thus there is no link for it. If it doesn't include the square bracket prefix, it will be sorted somewhere else, not in the desired sort order. Possible workarounds:
    • write the title with square bracket syntax anyway even though it is not a link ([[http://not_a_link][Running Linux]] displays Running Linux, but it is misleading. [[not_a_link][Running Linux]] displays Running Linux, which might be less misleading. Another alternative is to declare "not_a_link" as a special keyword, such that [[not_a_link][Running Linux]] displays Running Linux.)
    • develop sort procedures (enhancements to #Workaround_Special_Sort_Procedur) that ignore the square bracket prefix

  • I also have to be consistent with quotes, either quote all links or quote none of them, or develop sort procedures that ignore (single or double) quotes.

Example

Desired Sort Order

This is the sequence I'd like to have:

Actual Sort Order

This is the sequence I get if I do a simple-minded sort in something like Word or nedit:

RFE -- Reverse Double Square Bracket Syntax

My RFE, in the "tilting at windmills" category, is to rearrange the double square bracket syntax so that the name of the link appears first, then the actual link.

Another Alternative

I suppose a clever regular expression (or set of regular expressions) could reverse the link location and link name, sort "properly", and then restore the original [[link location][link name]] syntax, or just sort based on the link name despite the [[link location][link name]] syntax.

The Simplest Workaround

For "the next time" -- simply insert each new link in the proper sort order when you first insert it in a list. (And that probably is the simplest thing for me to start doing, but, doesn't that seem like the wrong way around -- the human sorting things for the computer??)

Workaround -- Special Sort Procedures

My workaround is to provide a list of instructions on how to do a more logical sort in other programs that are capable of doing so. (I'm rather certain Word can do better, and I sure hope nedit can.)

Word Sort Procedure

<later>

Nedit Sort Procedure

<later>

-- RandyKramer - 26 Jul 2002

This is probably best handled outside TWiki, on the client, since it is a one-off edit rather than something you would want done dynamically. Using Unix tools (see CygWin if on Windows), you can do something that uses tr to replace the '][' with (say) Ctrl/G, then use sort with Ctrl/G as the field separator character. This is much easier than writing a regex to swap things around (I started trying to write this). If you want, you could probably write a plugin that would do this, but it should not be part of the core TWiki code.

-- RichardDonkin - 27 Jul 2002

Thanks for the response! I agree that it is probably best handled outside of TWiki, at least until we run out of other things to do. wink The substitution of '][' with Ctrl/G is a good idea, and may be the key to doing it in Word and nedit as well as with just some Dos or Linux command line utilities.

-- RandyKramer - 27 Jul 2002

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2002-07-27 - RandyKramer
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.