01095: alternative link text in category markup

Summary: alternative link text in category markup
Created: 2009-04-29 22:27
Status: Closed, added for 2.3.0
Category: Feature
From: jr
Assigned:
Priority: 4444433321
Version: 2.2.1
OS: all

Description: The category link markup ! is a shortcut for links to the $CategoryGroup, presented using a $LinkCategoryFmt.

The category markup supports [[!Topic]] and [[!(Some)Topic]] but not variants such as [[!Topic |link text]]. At the moment, this links to a page called Topic in the current group, rather than in the category group: link text. The [[!Topic]]s variant ignores the suffix: Topics.

* [[!Topic]]
* [[!(Some)Topic]]
* [[!Topic |link text]]
* [[!Topic"Subject"|with tooltip]]
* [[!Topic]]Suffix
* [[!Topic|+]]
* [[!Topic|#]]

Unsure why [[!Topic|#]] links to PITS/Topic and not to Category/Topic. It works on my own wiki. --Petko January 01, 2022, at 07:41 PM

Fixed. --Petko January 01, 2022, at 07:44 PM

Several extensions to the category shortcut are possible:

  • [[!Topic |link text]]
  • [[!Topic |+]]
  • [[!Topic |#]]
  • [[!Topic]]Suffix

While these can be added as local customisations if needed, perhaps one or more ought to be supported in the core. The first is the most important, as currently it looks as if it works, but it does not produce the expected result. It uses neither the group nor the link format for category links.


The following markup replaces the current [[!Topic]] markup and solves both that simple case as well as giving the [[!Topic|link text]] case (proposed by jr on the mailing list):

Markup('[[!', '<[[|', "/\\[\\[!([^|\\]]+)(?:\\s*\\|\\s*(.*?)\\s*)?\\]\\]/e",
 "Keep(MakeLink(\$pagename,PSS('$CategoryGroup/$1'),
     ('$2' ? PSS('$2') : NULL), '',\$GLOBALS['LinkCategoryFmt']),'L')");

Another markup which is slightly more general purpose but loses $LinkCategoryFmt:

Markup('[[!','<[[|+','/\\[\\[\\!(.*?)\\]\\]/',"[[$CategoryGroup/$1]]");

The only way this could be used would be to introduce another element into the markup which would indicate which $XyzFmt to use:

[[^1^Topic]] or [[[^1^Category.Topic|link text]] could both use $LinkFmt[1]. This would not necessarily have to be a "visible" markup which authors use since the markup rule above could produce it:

$LinkFmt[1] = $LinkCategoryFmt;
Markup('[[!','<[[|+','/\\[\\[\\!(.*?)\\]\\]/',"[[^1^$CategoryGroup/$1]]");

This would require changing several markup rules to be aware of this new prefix...

It would have the benefit of allowing for other $LinkFmt possibilities in the future...

It *seems* like it would be possible to do something where $LinkFmt['!'] held $LinkCategoryFmt and $LinkGroup['!'] held $CategoryGroup and a single set of markups could handle all of them with flexibility? The extension could be $LinkFmt['~'] would be null and $LinkGroup['~'] would hold 'Profile'... This could be a pretty generic and flexible and standard way of handling links with prefixes without risking some of them not responding to the |text and another not being aware of the |+ title directive and etc...

Peter Bowers April 30, 2009, at 06:39 AM

This is an excellent idea Peter -- I have prototyped something and I'll add it to Subversion right after I release 2.2.14. Then we can test/review/discuss it. --Petko February 26, 2010, at 10:09 PM

I agree with this, especially as it makes markup more consistent. However there is also a deeper problem that should be fixed - PITS:00447

simon December 06, 2009, at 01:55 PM