Opened 6 years ago

Closed 15 months ago

## #11024 closed enhancement (fixed)

Reported by: Owned by: trent.jones@… christiano@… normal TracWikiPrintPlugin normal 0.12

### Description

When I have links in a a word file and convert it to a pdf, those links still work for the file. This however, maintains the links to the server, which is not ideal as I was hoping to use the exported PDF as an offline version of the wiki. Is it possible to make an option so that links can be internalised?

### comment:1 Changed 6 years ago by tekknokrat

I would support this request. It would be great to have links pointed to internal sections anchors of the pdf document. I see a huge benefit when resolving internal links, external links could be kept as-is. For this to work the plugin needs be able to convert the linked (wiki) content to html and attach this to output as well.

### comment:2 follow-up:  5 Changed 21 months ago by Christian <christiano@…>

I don't know if anyone is interested, but I thought I would throw this up here. I hacked the ability to have local links of type wiki turned into anchors in the pdf. Must set the new option, local_anchor=true, to true in trac.ini.

This only works for links to local wiki pages and anchors on local wiki pages. I doubt this is the best way of going about getting this functionality, but here it is if you need it.

• ## wikiprint/wikiprint.py

 httpauth_user = Option('wikiprint', 'httpauth_user') httpauth_password = Option('wikiprint', 'httpauth_password') omit_links = BoolOption('wikiprint', 'omit_links') local_anchor = BoolOption('wikiprint', 'local_anchor') omit_macros = ListOption('wikiprint', 'omit_macros') rebase_links = Option('wikiprint', 'rebase_links') default_charset = Option('trac', 'default_charset', 'utf-8') #Now convert in that context page = format_to_html(self.env, context, text) self.env.log.debug('WikiPrint => Wiki to HTML output: %r', page) if self.local_anchor: page = Markup("") + page regex = re.escape(req.abs_href()) + r'\/wiki\/' r = re.compile((regex)+r'(\w*)(#?)') page = r.sub('#\g<1>' ,page) r1 = re.compile(r'(span class="wikianchor" id=")(.*)(\/span)') page = r1.sub('a name="' + page_name + '\g<2>/a',page) self.env.log.debug('WikiPrint => HTML input to html_to_pdf is: %r', page) self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r', page) self.env.log.debug('WikiPrint => Finish function wikipage_to_html') return page

### comment:3 Changed 21 months ago by Ryan J Ollos

Owner: changed from Álvaro Iradier to Ryan J Ollos new → accepted

### comment:4 Changed 21 months ago by Ryan J Ollos

In 16431:

TracWikiPrintPlugin 2.0.0dev: Link to sections in book format

Refs #11024.

### comment:5 in reply to:  2 ; follow-up:  7 Changed 21 months ago by Ryan J Ollos

I don't know if anyone is interested, but I thought I would throw this up here. I hacked the ability to have local links of type wiki turned into anchors in the pdf. Must set the new option, local_anchor=true, to true in trac.ini.

Looks like a good start. More work is needed for linking to section headings. Example markup:

= Heading1

Some more text.


### comment:6 Changed 21 months ago by Ryan J Ollos

Owner: Ryan J Ollos deleted accepted → new

### comment:7 in reply to:  5 Changed 21 months ago by Christian <christiano@…>

I don't know if anyone is interested, but I thought I would throw this up here. I hacked the ability to have local links of type wiki turned into anchors in the pdf. Must set the new option, local_anchor=true, to true in trac.ini.

Looks like a good start. More work is needed for linking to section headings. Example markup:

= Heading1

Some more text.


This hack will break if the trac format_to_html functionality changes at all. I'm really out of my element here. I employed as a hardware engineer and probably know just enough to get myself into trouble when it comes to this type of coding.

• ## wikiprint/wikiprint.py

 httpauth_user = Option('wikiprint', 'httpauth_user') httpauth_password = Option('wikiprint', 'httpauth_password') omit_links = BoolOption('wikiprint', 'omit_links') local_anchor = BoolOption('wikiprint', 'local_anchor') omit_macros = ListOption('wikiprint', 'omit_macros') rebase_links = Option('wikiprint', 'rebase_links') default_charset = Option('trac', 'default_charset', 'utf-8') #Now convert in that context page = format_to_html(self.env, context, text) self.env.log.debug('WikiPrint => Wiki to HTML output: %r', page) self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r', if self.local_anchor: page = Markup("") + page regex = re.escape(req.abs_href()) + r'\/wiki\/' r = re.compile((regex)+r'([a-zA-Z0-9_/]*)(#?)') page = r.sub('#\g<1>/' ,page) r1 = re.compile(r'(span class="wikianchor" id=")(.*)(\/span)') page = r1.sub('a name="' + page_name + '/\g<2>/a',page) r1 = re.compile(r'(h[0-9] id=")(.*)(">)') page = r1.sub('\g<1>' + page_name + '/\g<2>\g<3>' ,page) self.env.log.debug('WikiPrint => HTML input to html_to_pdf is: %r', page) self.env.log.debug('WikiPrint => Finish function wikipage_to_html')

### comment:8 follow-up:  9 Changed 21 months ago by Ryan J Ollos

Thanks for the additional change. It will need to be rebased on r16431.

### comment:9 in reply to:  8 ; follow-up:  10 Changed 21 months ago by Christian <christiano@…>

Thanks for the additional change. It will need to be rebased on r16431.

Pages with sub-pages had '/' between the page and the sub-page in the link, but then the anchor would get concatenated with the sub-page name. I don't know if it really matters as we never really look at the links, but to make the links more consistent I added '/' for separators between anchors and page names. Page/<Sub-page><Anchor> ==> Page/Sub-page/Anchor Before I was just concatenating the page name and the anchor. An unwanted result is that page names without Anchors needed a '/' added as well. I'll defer to your opinion.

I had some trouble with tracwikiprintplugin/1.0/wikiprint/wikiprint.py@16431:249#L243. I was getting double #'s and I was having a problem with '/' placement. I reverted it back to the regex pattern I was using before and added a '/' to the group.

• ## wikiprint/wikiprint.py

 self.env.log.debug('WikiPrint => Wiki to HTML output: %r', page) # Link to internal sections of document. # This needs further development for section headings (th:#11024) if self.local_anchor: page = Markup('') + page r = re.compile(re.escape(req.abs_href.wiki()) + r'/(.*?)(#\w+)') page = r.sub('#\g<1>', page) page = Markup('') + page r = re.compile(re.escape(req.abs_href.wiki()) + r'/([a-zA-Z0-9_/]*)(#?)') page = r.sub('#\g<1>/', page) r1 = re.compile(r'(span class="wikianchor" id=")(.*)(/span)') page = r1.sub('a name="' + page_name + '\g<2>/a', page) page = r1.sub('a name="' + page_name + '/\g<2>/a', page) r2 = re.compile(r'(h[0-9] id=")(.*)(">)') page = r2.sub('\g<1>' + page_name + '/\g<2>\g<3>' ,page) self.env.log.debug("WikiPrint => HTML input to html_to_pdf is: %r", page)

I do have an off topic question. What is the plugin used in trac-hacks that does the auto-completion for revision numbers and macros?

### comment:10 in reply to:  9 Changed 21 months ago by Christian <christiano@…>

I do have an off topic question. What is the plugin used in trac-hacks that does the auto-completion for revision numbers and macros?

Never mind. I should have spent two seconds to look at the front page before asking.

### comment:11 Changed 15 months ago by Ryan J Ollos

Owner: set to Ryan J Ollos → fixed new → closed

In 16816:

TracWikiPrintPlugin 2.0.0dev: Link to internal sections of document

Fixes #11024.

### comment:12 Changed 15 months ago by Ryan J Ollos

Owner: changed from Ryan J Ollos to christiano@…

### Modify Ticket

Change Properties