Loading...
 

Tables of Contents (maketoc) can be broken when headings call plugins (such as ANAME and FOOTNOTE)

Status
Open
Subject
Tables of Contents (maketoc) can be broken when headings call plugins (such as ANAME and FOOTNOTE)
Version
6.x
12.x
14.x
15.x
18.x
Category
  • Conflict of two features (each works well independently)
Feature
Wiki Plugin (extends basic syntax)
Wiki Syntax (text area, parser, external wiki, etc)
Resolution status
Confirmed
Submitted by
EmmArrBee
Lastmod by
Philippe Cloutier
Rating
(0)
Description

Calling plugins in headings in pages where maketoc is used can cause breakage. For example, this happens when calling the ANAME or FOOTNOTE plugins.

Effect on ANAME

Although Tiki generates anchors for all headings automatically, I find using ANAME is a great way of creating manageable and easily memorable Anchors for otherwise unwieldy headings
If a heading within a tiki page is coded as follows

1. Tiki Source Code snippet
Copy to clipboard
!! Fourth and Even More Forgetful Heading{ANAME()}Quick4{ANAME}
then Tiki generates the following HTML code
2. Generated HTML snippet
Copy to clipboard
<h3 class="showhide_heading" id="Fourth_and_Even_More_Forgetful_Heading"> Fourth and Even More Forgetful Heading<a id="Quick4"></a></h3>
which can be exploited by
3. Tiki Source Code snippet
Copy to clipboard
{ALINK(aname=Quick4)}Link to Fourth Heading by its Quick4 Anchor{ALINK}
All the above works flawlessly.


However, add MAKETOC to the page above the source line where ANAME is last used and it breaks the ANAME anchor(s). For this example, the maketoc is restricted to level 2 headings only as {maketoc levels="2"} which makes the generated HTML a little more compact.
Tiki generates the following HTML in response to the inclusion of maketoc

Generated HTML for maketoc snippet 3
Copy to clipboard
<ul><li><a href='#First_Level_Two_Heading' class='link'> First Level Two Heading</a> </li><li><a href='#Second_Long_and_Equally_Unmemorable_Heading' class='link'> Second Long and Equally Unmemorable Heading</a> </li><li><a href='#Third_Painfully_Difficult_Heading' class='link'> Third Painfully Difficult Heading</a> </li><li><a href='#Fourth_and_Even_More_Forgetful_Heading' class='link'> Fourth and Even More Forgetful Heading<a id="Quick4"></a></a> </li><li><a href='#Fifth_Long_and_Not_Very_Memorable_Heading' class='link'> Fifth Long and Not Very Memorable Heading</a> </li></ul></li></ul><!--toc--></div><br />
Note how the entry for the Fourth Paragraph has the anchor "Quick4" associated with it. The HTML code generated for the Fourth Paragraph heading remains identical.


The effect of this is that the tiki anchor Quick4 is now incorrectly linked to the TOC entry, being the first instance of HTML ANCHOR within the HTML file.

If the MAKETOC plugin is included below the ANAME, then the ANAME works as intended, since that is the first occurrence of the generated HTML ANCHOR statement.

I have a couple of test pages which illustrate this issue, if they are of any use in your testing.

Effect on FOOTNOTE

Calling FOOTNOTE returns an HTML A element with an id, so using that same identifier twice causes invalid HTML. Additionally, since browsers favor the first element using the identifier in such cases, the TOC's instance wins if {maketoc} precedes headings, which is not what we want.

Cause

Plugin calls are executed in parse_first(). (Calls to plugins in "html" format are replaced by alphanumeric fingerprints.) After, parse_data_process_maketoc() is called and expands "{maketoc}" to headings, so that each plugin call in a heading in the TOC has its result (or fingerprint) twice in the source. (After, replace_preparse() replaces fingerprints with the result of plugin functions (stored during parse_first's execution).)

This issue happens because maketoc therefore causes a plugin call's result to be repeated in the TOC (instead of possibly executed again specifically for TOC-s), which has 2 problems:

  • plugins don't expect their output included twice in the page, so some (such as ANAME) may use HTML's id attribute in a manner incompatible with maketoc, causing invalid HTML
  • plugins don't expect their output to be included in an HTML A element, so some (such as FOOTNOTE) for example generate links themselves, again causing invalid HTML
Solution

I believe there is no general solution to this. Each plugin needs to adapt its behavior when the output is to be used in a heading. For example, SUP can return the same thing, but ANAME should return nothing.

A solution could be implemented by potentially calling a plugin function twice per in-heading plugin call. With an extra parameter indicating a call for a TOC, FOOTNOTE could return just text, no link. However, if there are 2 independent calls, it would be hard for FOOTNOTE to know that it should return the same number.

wikiplugin_foo_info() could return an extra "headings" array element indicating what to do if the plugin is called in a heading. For SUP, this could be "'headings' => 'same'". For the GOOGLEANALYTICS plugin, the value could be "ignore".

Unfortunately, in order to do that, we need to distinguish headings before plugins are called. As of r66644, plugins are called (in parse_first()) well before headings are distinguished (in parse_data_process_maketoc()).

Dirty hack

The 2 patches attached provide a dirty solution which seems to work well on UTF-8 databases. These would need validation for compatibility with other encodings before being integrated.

The very same patch works verbatim against Tiki 15 too.

This is very much of a hack and may very well cause regressions.

Workaround
For ANAME, put the call on the line before or after the heading
Importance
7
Easy to solve?
2
Priority
14
Demonstrate Bug (Tiki 19+)
Please demonstrate your bug on show2.tiki.org
 About show2.tiki.org

To help developers solve the bug, we kindly request that you demonstrate your bug on a show2.tiki.org instance. To start, simply select a version and click on "Create show2.tiki.org instance". Once the instance is ready (in a minute or two), as indicated in the status window below, you can then access that instance, login (the initial admin username/password is "admin") and configure the Tiki to demonstrate your bug. Priority will be given to bugs that have been demonstrated on show2.tiki.org.

Version: Create show2.tiki.org instance
Demonstrate Bug (older Tiki versions)
Please demonstrate your bug on show.tikiwiki.org
 About show.tikiwiki.org

To help developers solve the bug, we kindly request that you demonstrate your bug on a show.tikiwiki.org instance. To start, simply select a version and click on "Create show.tikiwiki.org instance". Once the instance is ready (in a minute or two), as indicated in the status window below, you can then access that instance, login (the initial admin username/password is "admin") and configure the Tiki to demonstrate your bug. Priority will be given to bugs that have been demonstrated on show.tikiwiki.org.

Version: Create show.tikiwiki.org instance
Ticket ID
4235
Created
Tuesday 29 May, 2012 13:08:17 GMT-0000
by EmmArrBee
LastModif
Thursday 25 April, 2019 18:26:48 GMT-0000

Attachments

 filenamecreatedhitscommentversionfiletype 
Parser_TOC_HTML_fix_trunk.diff 13 Jul 18 13:59 GMT-00000Against r66952
Parser_TOC_HTML_fix_18.diff 13 Jul 18 13:59 GMT-00000Against r66952


Keywords

The following is a list of keywords that should serve as hubs for navigation within the Tiki development and should correspond to documentation keywords.

Each feature in Tiki has a wiki page which regroups all the bugs, requests for enhancements, etc. It is somewhat a form of wiki-based project management. You can also express your interest in a feature by adding it to your profile. You can also try out the Dynamic filter.

Accessibility (WAI & 508)
Accounting
Administration
Ajax
Articles & Submissions
Backlinks
Banner
Batch
BigBlueButton audio/video/chat/screensharing
Blog
Bookmark
Browser Compatibility
Calendar
Category
Chat
Comment
Communication Center
Consistency
Contacts Address book
Contact us
Content template
Contribution
Cookie
Copyright
Credits
Custom Home (and Group Home Page)
Database MySQL - MyISAM
Database MySQL - InnoDB
Date and Time
Debugger Console
Diagram
Directory (of hyperlinks)
Documentation link from Tiki to doc.tiki.org (Help System)
Docs
DogFood
Draw -superseded by Diagram
Dynamic Content
Preferences
Dynamic Variable
External Authentication
FAQ
Featured links
Feeds (RSS)
File Gallery
Forum
Friendship Network (Community)
Gantt
Group
Groupmail
Help
History
Hotword
HTML Page
i18n (Multilingual, l10n, Babelfish)
Image Gallery
Import-Export
Install
Integrator
Interoperability
Inter-User Messages
InterTiki
jQuery
Kaltura video management
Kanban
Karma
Live Support
Logs (system & action)
Lost edit protection
Mail-in
Map
Menu
Meta Tag
Missing features
Visual Mapping
Mobile
Mods
Modules
MultiTiki
MyTiki
Newsletter
Notepad
OS independence (Non-Linux, Windows/IIS, Mac, BSD)
Organic Groups (Self-managed Teams)
Packages
Payment
PDF
Performance Speed / Load / Compression / Cache
Permission
Poll
Profiles
Quiz
Rating
Realname
Report
Revision Approval
Scheduler
Score
Search engine optimization (SEO)
Search
Security
Semantic links
Share
Shopping Cart
Shoutbox
Site Identity
Slideshow
Smarty Template
Social Networking
Spam protection (Anti-bot CATPCHA)
Spellcheck
Spreadsheet
Staging and Approval
Stats
Survey
Syntax Highlighter (Codemirror)
Tablesorter
Tags
Task
Tell a Friend
Terms and Conditions
Theme
TikiTests
Federated Timesheets
Token Access
Toolbar (Quicktags)
Tours
Trackers
TRIM
User Administration
User Files
User Menu
Watch
Webmail and Groupmail
WebServices
Wiki History, page rename, etc
Wiki plugins extends basic syntax
Wiki syntax text area, parser, etc
Wiki structure (book and table of content)
Workspace and perspectives
WYSIWTSN
WYSIWYCA
WYSIWYG
XMLRPC
XMPP




Useful Tools