#11024 closed enhancement (fixed)
Internalise links to document
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Component: | TracWikiPrintPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 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?
Attachments (0)
Change History (12)
comment:1 Changed 11 years ago by
comment:2 follow-up: 5 Changed 8 years ago by
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
164 164 httpauth_user = Option('wikiprint', 'httpauth_user') 165 165 httpauth_password = Option('wikiprint', 'httpauth_password') 166 166 omit_links = BoolOption('wikiprint', 'omit_links') 167 local_anchor = BoolOption('wikiprint', 'local_anchor') 167 168 omit_macros = ListOption('wikiprint', 'omit_macros') 168 169 rebase_links = Option('wikiprint', 'rebase_links') 169 170 default_charset = Option('trac', 'default_charset', 'utf-8') … … 240 241 #Now convert in that context 241 242 page = format_to_html(self.env, context, text) 242 243 self.env.log.debug('WikiPrint => Wiki to HTML output: %r', page) 244 245 if self.local_anchor: 246 page = Markup("<a name=" + page_name + "></a>") + page 247 regex = re.escape(req.abs_href()) + r'\/wiki\/' 248 r = re.compile((regex)+r'(\w*)(#?)') 249 page = r.sub('#\g<1>' ,page) 250 r1 = re.compile(r'(span class="wikianchor" id=")(.*)(\/span)') 251 page = r1.sub('a name="' + page_name + '\g<2>/a',page) 252 self.env.log.debug('WikiPrint => HTML input to html_to_pdf is: %r', 253 page) 243 254 244 self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r',245 page)246 255 self.env.log.debug('WikiPrint => Finish function wikipage_to_html') 247 256 248 257 return page
comment:3 Changed 8 years ago by
Owner: | changed from Álvaro Iradier to Ryan J Ollos |
---|---|
Status: | new → accepted |
comment:5 follow-up: 7 Changed 8 years ago by
Replying to 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 Link to [#heading2]. = Heading 2 #heading2 Some more text.
comment:6 Changed 8 years ago by
Owner: | Ryan J Ollos deleted |
---|---|
Status: | accepted → new |
comment:7 Changed 8 years ago by
Replying to Ryan J Ollos:
Replying to 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 Link to [#heading2]. = Heading 2 #heading2 Some more text.
I addressed the above example. I also add '/' seperators for consistency with links to subpages.
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
164 164 httpauth_user = Option('wikiprint', 'httpauth_user') 165 165 httpauth_password = Option('wikiprint', 'httpauth_password') 166 166 omit_links = BoolOption('wikiprint', 'omit_links') 167 local_anchor = BoolOption('wikiprint', 'local_anchor') 167 168 omit_macros = ListOption('wikiprint', 'omit_macros') 168 169 rebase_links = Option('wikiprint', 'rebase_links') 169 170 default_charset = Option('trac', 'default_charset', 'utf-8') … … 240 241 #Now convert in that context 241 242 page = format_to_html(self.env, context, text) 242 243 self.env.log.debug('WikiPrint => Wiki to HTML output: %r', page) 243 244 self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r', 244 245 if self.local_anchor: 246 page = Markup("<a name=" + page_name + "/></a>") + page 247 regex = re.escape(req.abs_href()) + r'\/wiki\/' 248 r = re.compile((regex)+r'([a-zA-Z0-9_/]*)(#?)') 249 page = r.sub('#\g<1>/' ,page) 250 r1 = re.compile(r'(span class="wikianchor" id=")(.*)(\/span)') 251 page = r1.sub('a name="' + page_name + '/\g<2>/a',page) 252 r1 = re.compile(r'(h[0-9] id=")(.*)(">)') 253 page = r1.sub('\g<1>' + page_name + '/\g<2>\g<3><a name="' + page_name + '/\g<2>"></a>' ,page) 254 255 self.env.log.debug('WikiPrint => HTML input to html_to_pdf is: %r', 245 256 page) 246 257 self.env.log.debug('WikiPrint => Finish function wikipage_to_html')
comment:8 follow-up: 9 Changed 8 years ago by
Thanks for the additional change. It will need to be rebased on r16431.
comment:9 follow-up: 10 Changed 8 years ago by
Replying to Ryan J Ollos:
Thanks for the additional change. It will need to be rebased on r16431.
Sorry about that.
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
243 243 self.env.log.debug('WikiPrint => Wiki to HTML output: %r', page) 244 244 245 245 # Link to internal sections of document. 246 # This needs further development for section headings (th:#11024)247 246 if self.local_anchor: 248 page = Markup('<a name=' + page_name + ' ></a>') + page249 r = re.compile(re.escape(req.abs_href.wiki()) + r'/( .*?)(#\w+)')250 page = r.sub('#\g<1> ', page)247 page = Markup('<a name=' + page_name + '/></a>') + page 248 r = re.compile(re.escape(req.abs_href.wiki()) + r'/([a-zA-Z0-9_/]*)(#?)') 249 page = r.sub('#\g<1>/', page) 251 250 r1 = re.compile(r'(span class="wikianchor" id=")(.*)(/span)') 252 page = r1.sub('a name="' + page_name + '\g<2>/a', page) 251 page = r1.sub('a name="' + page_name + '/\g<2>/a', page) 252 r2 = re.compile(r'(h[0-9] id=")(.*)(">)') 253 page = r2.sub('\g<1>' + page_name + '/\g<2>\g<3><a name="' + page_name + '/\g<2>"></a>' ,page) 253 254 self.env.log.debug("WikiPrint => HTML input to html_to_pdf is: %r", 254 255 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 Changed 8 years ago by
Replying to 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 7 years ago by
Owner: | set to Ryan J Ollos |
---|---|
Resolution: | → fixed |
Status: | new → closed |
In 16816:
comment:12 Changed 7 years ago by
Owner: | changed from Ryan J Ollos to christiano@… |
---|
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.