Permalink
Browse files

Item11389: change named anchor links to target IDs

git-svn-id: http://svn.foswiki.org/trunk@14099 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information...
ArthurClemens ArthurClemens
ArthurClemens authored and ArthurClemens committed Feb 25, 2012
1 parent 37b7093 commit 996714cc3fde3af7851f0fc99dd502fc1e185edb
@@ -10,11 +10,11 @@
| =web="Name"= | Name of web | Current web |
| =depth="2"= | Limit depth of headings shown in TOC | 6 |
| =title="Some text"= | Title to appear at top of TOC | none |
| =id="Some_id"= | Optional ID in case multiple TOCs are on the page and each TOC needs to be addressable with an anchor link. Allowed characters: =a-zA-Z0-9-_=, no spaces. %BR% \
If you don't specify an id, the anchor =foswikiTOC= can be used in a link: =[<nop>[#foswikiTOC][Back to TOC]]= creates [[#foswikiTOC][Back to TOC]]. | "foswikiTOC" |
* Default settings are defined in %SYSTEMWEB%.DefaultPreferences, and can be overridden in %USERSWEB%.SitePreferences
* Examples: <pre class="tml">%<nop>TOC{depth="2"}%
%<nop>TOC{"CompleteDocumentation" web="%<nop>SYSTEMWEB%" title="Contents:"}%</pre>
See also: Foswiki:Support/HowToCreateATableOfContents
<blockquote class="foswikiHelp">%T% TOC will add an HTML anchor called =foswikiTOC= just before the table of contents. This enables adding a link from within a topic back to the table of contents to ease navigation. Example =[<nop>[#foswikiTOC][Back to TOC]]= creates [[#foswikiTOC][Back to TOC]].
<p></p>
%T% If multiple headers have the exact same text, the anchors for the 2nd, 3rd etc will be suffixed by _AN1, _AN2 etc so the anchors become unique.</blockquote>
<blockquote class="foswikiHelp">%T% If multiple headers have the exact same text, the anchors for the 2nd, 3rd etc will be suffixed by _AN1, _AN2 etc so the anchors become unique.</blockquote>
<!--%JQREQUIRE{"chili"}%-->
@@ -12,8 +12,7 @@ Designed by: Crawford Currie
<table><tr><th>Expected</th><th>Actual</th></tr>
<tr valign="top"><td>
<!-- expected expand rex -->
<a name=foswikiTOC />
<div class="foswikiToc">
<div class="foswikiToc" id="foswikiTOC">
<ul>
<li> <a href="%SCRIPTURLPATH{"view"}%/%WEB%/TocFixture?@URLPARAMS#Nonsense">Nonsense</a>
<ul>
@@ -36,8 +35,7 @@ Designed by: Crawford Currie
<!-- /actual -->
</td></tr><tr valign="top"><td>
<!-- expected expand rex wine -->
<a name=foswikiTOC />
<div class="foswikiToc">
<div class="foswikiToc" id="foswikiTOC">
<span class="foswikiTocTitle">The Top</span>
<ul>
<li> <a href="?@URLPARAMS#H1_60_33_45_451_45_45_62">H1 <!--1--></a>
@@ -19,11 +19,10 @@ This heading anchor
<a name="ThatHeading"></a>
That heading anchor
<p />
<h1><a name="ThatHeading_AN2"></a> ThatHeading </h1>
<h1><a name="ThisHeading_AN2"></a> ThisHeading </h1>
<h1 id="ThatHeading_AN2"> ThatHeading </h1>
<h1 id="ThisHeading_AN2"> ThisHeading </h1>
<p />
<a name="foswikiTOC"></a>
<div class="foswikiToc">
<div class="foswikiToc" id="foswikiTOC">
<ul>
<li>
<a href="?@REX(.*)#ThatHeading_AN1"> ThatHeading </a>
@@ -38,6 +38,7 @@ sub TOC {
my $tocTopic = $params->{_DEFAULT};
my $tocWeb = $params->{web};
my $tocId = $params->{id} || 'foswikiTOC';
if ( $tocTopic || $tocWeb ) {
$tocWeb ||= $topicObject->web;
@@ -219,8 +220,7 @@ sub TOC {
}
# add a anchor to be able to jump to the toc and add a outer div
return CGI::a( { name => 'foswikiTOC' }, '' )
. CGI::div( { class => 'foswikiToc' }, "$title$result\n" );
return CGI::div( { -class => 'foswikiToc', -id => $tocId }, "$title$result\n" );
}
else {
@@ -232,7 +232,7 @@ sub TOC {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2009 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
View
@@ -451,8 +451,8 @@ sub _makeAnchorHeading {
my $html =
'<nop><h'
. $level . '>'
. $anchors->makeHTMLTarget($text) . ' '
. $level . ' '
. 'id="' . $anchors->makeHTMLTarget($text) . '"> '
. $text . ' </h'
. $level . '>';
@@ -1239,8 +1239,8 @@ sub getRenderedVersion {
# '#WikiName' anchors. Don't attempt to make these unique; renaming
# user-defined anchors is not sensible.
$text =~ s/^(\#$Foswiki::regex{wikiWordRegex})/
CGI::a({
name => $anchors->add( $1 )
CGI::span({
id => $anchors->add( $1 )
}, '')/geom;
# Headings
@@ -2247,7 +2247,7 @@ sub renderIconImage {
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2011 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
@@ -176,35 +176,35 @@ sub make {
=begin TML
---++ ObjectMethod makeHTMLTarget($name) -> $html
Make an HTML anchor that can be used as the target of links.
---++ ObjectMethod makeHTMLTarget($name) -> $id
Make an id that can be used as the target of links.
=cut
sub makeHTMLTarget {
my ( $this, $text ) = @_;
my $goodAnchor = make($text);
my $html = CGI::a( { name => $this->addUnique( $goodAnchor, 1 ) }, '' );
my ( $this, $name ) = @_;
my $goodAnchor = make($name);
my $id = $this->addUnique( $goodAnchor, 1 );
if ( $Foswiki::cfg{RequireCompatibleAnchors} ) {
# Add in extra anchors compatible with old formats, as required
require Foswiki::Compatibility;
my @extras = Foswiki::Compatibility::makeCompatibleAnchors($text);
my @extras = Foswiki::Compatibility::makeCompatibleAnchors($name);
foreach my $extra (@extras) {
next if ( $extra eq $goodAnchor );
$html .= CGI::a( { name => $this->addUnique( $extra, 1 ), }, '' );
$id = $this->addUnique( $extra, 1 );
}
}
return $html;
return $id;
}
1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
Copyright (C) 2008-2012 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.

0 comments on commit 996714c

Please sign in to comment.