Modify

Opened 6 years ago

Last modified 6 years ago

#3584 new defect

ToC Macro doesn't work with relative links

Reported by: jimse@… Owned by: coderanger
Priority: normal Component: TocMacro
Severity: normal Keywords:
Cc: jimse@… Trac Release: 0.11

Description

The second ToC here does not work -- gives "Error: Page ./sub does not exist"

[[TOC(inline,noheading,depth=1, test/sub, test/sub2)]]

[[TOC(inline,noheading,depth=1, ./sub, ./sub2)]]

[./sub sub][[BR]]
[./sub2 sub2]

Note that the first ToC works (but I need relative links) as do the relative links at the bottom.

Attachments (0)

Change History (6)

comment:1 Changed 6 years ago by anonymous

  • Trac Release changed from 0.10 to 0.11

comment:2 Changed 6 years ago by anonymous

  • Cc jimse@… added; anonymous removed

comment:3 Changed 6 years ago by dbuss

A dirty hack for jimse was to insert the following code at the bottom of expandmacro()

for pagename in pagenames:

new if pagename.startswith('.'): new rel_url = get_relative_url(self.env, self.resource, self.context.href, pagename) new pagename = rel_url.lstrip(self.context.href.base+'/'+self.resource.realm)

page_resource = self.resource(id=pagename) if not 'WIKI_VIEW' in self.context.perm(page_resource):

# Not access to the page, so should not be included continue

if 'title_index' in params:

self._render_title_index(ol, page_resource, active and \

pagename == current_page, paramsmin_depth? < 2)

else:

self._render_page_outline(ol, page_resource, active, params)

return base

comment:4 Changed 6 years ago by dbuss

      for pagename in pagenames:
            // the three lines below this comment are new
            if pagename.startswith('.'):
               rel_url = get_relative_url(self.env, self.resource,  self.context.href, pagename)
               pagename = rel_url.lstrip(self.context.href.base+'/'+self.resource.realm)
            page_resource = self.resource(id=pagename)
            if not 'WIKI_VIEW' in self.context.perm(page_resource):
                # Not access to the page, so should not be included
                continue
            if 'title_index' in params:
                self._render_title_index(ol, page_resource, active and \
                            pagename == current_page,
                            params['min_depth'] < 2)
            else:
                self._render_page_outline(ol, page_resource, active, params)
        return base

comment:5 Changed 6 years ago by anonymous

Please attach patches as unified diffs (diff -u or svn diff)

comment:6 Changed 6 years ago by dbuss

It's not a diff because I don't think that is the perfect fix. A better fix would be to have a relative resource id generator function in trac which could be used.

Add Comment

Modify Ticket

Action
as new The owner will remain coderanger.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.