Subject: | add hack to create anchors for section headings |
Some wikis, including mediawiki, allow links to individual sections
within wiki pages. This is implemented by means of HTML anchors included
with the section header elements, and by the use of fragment identifiers
in the links.
I wanted to implement this in a creole-based wiki and used a simple
hack. I just shared the variable %chunks, so I can override the filter
element.
- my %chunks = (
+ our %chunks = (
Then elsewhere in my wiki application I can write:
use Text::WikiCreole;
_creole_add_name_filters();
where
sub _creole_add_name_filters {
for (1..6) {
$Text::WikiCreole::chunks{"h$_"}->{filter} = \&_creole_h_filter;
}
}
sub _creole_h_filter {
# arg is text of header element
&Text::WikiCreole::strip_head_eq;
(my $tag = $_[0]) =~ tr/ /_/;
$_[0] = "<a name=\"$tag\"></a>" . $_[0];
}