=cut
-
my($Cachedir);
my($Dircache, $Itemcache);
my @Begin_Stack;
sub emit_item_tag($$$){
my( $otext, $text, $compact ) = @_;
- my $item = fragment_id( $text );
+ my $item = fragment_id( $text , -generate);
$EmittedItem = $item;
### print STDERR "emit_item_tag=$item ($text)\n";
if ($Items_Named{$item}++) {
print HTML process_text( \$otext );
} else {
- my $name = 'item_' . $item;
+ my $name = $item;
$name = anchorify($name);
- print HTML qq{<a name="$name">}, process_text( \$otext ), '</a>';
+ print HTML qq{<a name="$name" class="item">}, process_text( \$otext ), '</a>';
}
print HTML "</strong>\n";
undef( $EmittedItem );
$heading =~ s/\s+\Z//;
$heading =~ s/\A\s+//;
# The hyphen is a disgrace to the English language.
- $heading =~ s/[-"?]//g;
+ # $heading =~ s/[-"?]//g;
+ $heading =~ s/["?]//g;
$heading = lc( $heading );
return $heading;
}
return $res;
}
+{
+ my %seen; # static fragment record hash
+
+sub fragment_id_readable {
+ my $text = shift;
+ my $generate = shift; # optional flag
+
+ my $orig = $text;
+
+ # just clean the punctuation and leave the words for the
+ # fragment identifier.
+ $text =~ s/([[:punct:]\s])+/$1/g;
+ $text =~ s/[[:punct:]\s]+\Z//g;
+
+ # "=item --version", remove leading punctuation.
+ $text =~ s/^[-[:punct:]]//;
+
+ unless ($text)
+ {
+ # Nothing left after removing punctuation, so leave it as is
+ # E.g. if option is named: "=item -#"
+
+ $text = $orig;
+ }
+
+ if ($generate) {
+ if ( exists $seen{$text} ) {
+ # This already exists, make it unique
+ $seen{$text}++;
+ $text = $text . $seen{$text};
+ } else {
+ $seen{$text} = 1; # first time seen this fragment
+ }
+ }
+
+ $text;
+}}
+
+my @HC;
+sub fragment_id_obfusticated { # This was the old "_2d_2d__"
+ my $text = shift;
+ my $generate = shift; # optional flag
+
+ # text? Normalize by obfusticating the fragment id to make it unique
+ $text =~ s/\s+/_/sg;
+
+ $text =~ s{(\W)}{
+ defined( $HC[ord($1)] ) ? $HC[ord($1)]
+ : ( $HC[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
+ $text = substr( $text, 0, 50 );
+
+ $text;
+}
+
#
# fragment_id - construct a fragment identifier from:
# a) =item text
# b) contents of C<...>
#
-my @HC;
+
sub fragment_id {
- my $text = shift();
+ my $text = shift;
+ my $generate = shift; # optional flag
+
$text =~ s/\s+\Z//s;
if( $text ){
# a method or function?
return $1 if $text =~ m{^([a-z\d_]+)(\s+[A-Z,/& ][A-Z\d,/& ]*)?$};
return $1 if $text =~ m{^([a-z\d]+)\s+Module(\s+[A-Z\d,/& ]+)?$};
- # text? normalize!
- $text =~ s/\s+/_/sg;
- $text =~ s{(\W)}{
- defined( $HC[ord($1)] ) ? $HC[ord($1)]
- : ( $HC[ord($1)] = sprintf( "%%%02X", ord($1) ) ) }gxe;
- $text = substr( $text, 0, 50 );
+ fragment_id_readable($text, $generate);
} else {
return undef();
}
<h2><a name="new__"><code>new()</code></a></h2>
<p>Constructor method. Accepts the following config options:</p>
<dl>
-<dt><strong><a name="item_foo">foo</a></strong>
+<dt><strong><a name="foo" class="item">foo</a></strong>
<dd>
<p>The foo item.</p>
</dd>
</li>
-<dt><strong><a name="item_bar">bar</a></strong>
+<dt><strong><a name="bar" class="item">bar</a></strong>
<dd>
<p>The bar item.</p>
<p>The waz item.</p>
</li>
</ul>
-<dt><strong><a name="item_baz">baz</a></strong>
+<dt><strong><a name="baz" class="item">baz</a></strong>
<dd>
<p>The baz item.</p>
</dl>
<p>Title on the same line as the =item + * bullets</p>
<ul>
-<li><strong><a name="item_black_cat"><code>Black</code> Cat</a></strong>
+<li><strong><a name="black_cat" class="item"><code>Black</code> Cat</a></strong>
-<li><strong><a name="item_sat_on_the">Sat <em>on</em> the</a></strong>
+<li><strong><a name="sat_on_the" class="item">Sat <em>on</em> the</a></strong>
-<li><strong><a name="item_mat_3c_21_3e">Mat<!></a></strong>
+<li><strong><a name="mat" class="item">Mat<!></a></strong>
</ul>
<p>Title on the same line as the =item + numerical bullets</p>
<ol>
-<li><strong><a name="item_cat">Cat</a></strong>
+<li><strong><a name="cat" class="item">Cat</a></strong>
-<li><strong><a name="item_sat">Sat</a></strong>
+<li><strong><a name="sat" class="item">Sat</a></strong>
-<li><strong><a name="item_mat">Mat</a></strong>
+<li><strong><a name="mat2" class="item">Mat</a></strong>
</ol>
<p>No bullets, no title</p>