The Nature Of Wiki Links

The number one feature request in Pepys is arbitrary links in content. I've been working on this for a little while and it's made me think quite deeply about the nature of the links in a Wiki.

Currently Pepys highlights WikiNames as you type providing you with the default Wiki linking behaviour. This is equivilent to typing a WikiName in the edit box of a Wiki page and hitting save. The page linked to is calculated from the WikiName itself. Deleting characters from the WikiName changes the page it links to. This is one of the elements of Wiki essence and enables serendipitous linking. The link itself isn't a characteristic of the underlying markup but of the particular pattern match the application applies. Pepys doesn't save these links when it writes out the XHTML but recalculates them each time the page is loaded or whenever the text is edited. This will let me show different types of links depending on whether the page pointed to exists or not.

Adding arbitrary linking introduces new behaviour: the link isn't constructed from a pattern match but from a character range and the link may point to a fixed URI rather than being calculated from the linked text. Traditional wikis require extra syntax to support these types of links. Some let you add square brackets around any piece of text to make it into a WikiName. Others will let you include a URI in the brackets (often something like [<uri> link text]) which becomes the target of the link with the enclosed text becoming the link text. In Pepys, these sorts of links will be added by pressing a key combination, a toolbar button or selecting a menu item.

In Pepys, when you press CTRL + L (or select Insert Link from the menu) the currently highlighted text gets made into a link. The page this link points to is a function of the text you selected (removal of spaces etc) and it will change if you edit the text in the link. However, if you press CTRL + SHIFT + L (or select Insert Extended Link from the menu) a dialog pops up asking you to enter a URI. The highlighted text gets made into a link, the target of which is the URI you entered. If you edit the link text the link target stays the same. Because the user explictly requested a link in the page these have to be saved to the underlying XHTML somehow since their extent can't be calculated at display time.

For Pepys, I'm calling links that calculate the target page from the text that makes up the link dynamic and those that keep the same URI no matter how you edit the text static. Additionally each link can either be persistent or transient depending on whether Pepys writes the link definition out to the XHTML. For persistent, static links Pepys will write out a proper anchor tag with an appropriate href attribute. Persistent, dynamic links are also written as anchor tags but I need a way to distinguish them from static links. The method I've selected is to write out an anchor with no href enclosing the linked text, like this: link text. Now, I'm not sure this is 100% legal, but I'm hoping it is since my only other alternative is to abuse another attribute such as class or rel.

In summary, links can be:

Dynamic and Transient
Traditional WikiWord links. No additional XHTML is written by Pepys. The link highlighting is performed by applying a pattern match to the text when it is displayed. The page being linked to is calculated from the linked text when the user clicks on the link.
Dynamic and Persistent
Equivalent to text being bracketed in a Wiki. Pepys writes link text in the XHTML. The page being linked to is calculated from the linked text when the user clicks on the link.
Static and Persistent
Equivalent to text being bracketed with a URL in a Wiki. Pepys writes <a href="foo.xhtml">link text</a> in the XHTML. The page being linked to is fixed.
Static and Transient
Unknown in the wild, which is unsurprising since the link disappears when the page is saved. Not supported by Pepys.

This is nearly complete in Pepys. The basic functionality is there, I'm now just working through all the interactions between the types of links, such as when the user inserts a persistent link overlapping a transient one. Not hard, but it means I'm making lots of fairly arbitrary decisions about behaviour which I usually try to avoid. When in doubt I invoke the principle of least surprise and take that route.

Permalink: http://blog.iandavis.com/2004/03/the-nature-of-wiki-links/


Other posts tagged as pepys

Earlier Posts