Keyword URLs - GeSHi/geshi-1.0 GitHub Wiki
As of version 1.0.2, GeSHi allows you to specify a URL for keyword groups. This URL is used by GeSHi to convert the keywords in that group into URLs to appropriate documentation. And using add_keyword_group
you can add functions and classes from your own projects and use the URL functionality to provide a link to your own API documentation.
Setting a URL for a Keyword Group
To set the URL to be used for a keyword group, you use the set_url_for_keyword_group()
method:
$geshi->set_url_for_keyword_group($group, $url);
Where $group
is the keyword group you want to assign the URL for, and $url
is the URL for this group of keywords.
You may be wondering how to make each keyword in the group point to the correct URL. You do this by putting {FNAME}
in the URL at the correct place. For example, PHP makes it easy by linking www.php.net/function-name
to the documentation for that function, so the URL used is http://www.php.net/{FNAME}
.
Of course, when you get to a language like Java, that puts its class documentation in related folders, it gets a little trickier to work out an appropriate URL (see the Java language file!). I hope to provide some kind of redirection service at the GeSHi website in the future.
:point_right: Note:
As of Version 1.0.7.21 there have been added two more symbols you can use to link to functions.
{FNAMEL}
will generate the lowercase version of the keyword,{FNAMEU}
will generate the uppercase version.{FNAME}
will provide the keyword as specified in the language file. Use one of these more specific placeholders if possible, as they result in less overhead while linking for case insensitive languages.
Disabling a URL for a Keyword Group
It’s easy to disable a URL for a keyword group: Simply use the method set_url_for_keyword_group()
to pass an empty string as the URL:
$geshi->set_url_for_keyword_group($group, '');
Disabling all URLs for Keywords
As of GeSHi 1.0.7.18, you can disable all URL linking for keywords:
$geshi->enable_keyword_links(false);
Styling Links
You can also style the function links. You can style their default status, hovered, active and visited status. All of this is controlled by one method, set_link_styles()
:
$geshi->set_link_styles($mode, $styles);
Where $mode
is one of four values:
GESHI_LINK
: The default style of the links.GESHI_HOVER
: The style of the links when they have focus (the mouse is hovering over them).GESHI_ACTIVE
: The style of the links when they are being clicked.GESHI_VISITED
: The style of links that the user has already visited.
And $styles
is the stylesheet declarations to apply to the links.
:point_right: Note:
The names
GESHI_LINK
,GESHI_HOVER
… are constants. Don’t put them in quotes!
Setting the Link Target
Perhaps you want to set the target of link attributes, so the manual pages open in a new window? Use the set_link_target()
method:
$geshi->set_link_target($target, $styles);
Where $target
is any valid (X)HTML target value - _blank
or _top
for example.