Ticket #1468 (closed enhancement: duplicate)
Opened 7 years ago
Last modified 2 years ago
User-defined alternate formats [export] [wiki]
| Reported by: | shad | Owned by: | jonas |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | wiki system | Version: | 0.8.1 |
| Severity: | normal | Keywords: | |
| Cc: | m@…, tapted@…, danarmak@…, trac@… | ||
| Release Notes: | |||
| API Changes: | |||
Description
It would be very usefull to allow user to create a plugin that shows page (Wiki-page for example) in different format.
For example, I would like to create an alternate format that allows to download a Wiki-page in OpenOffice format, or in PDF-format.
Another example, it would be nice to show timeline or roadmap in alternate formats as an image generated on the fly based on tickets states.
Attachments
Change History
comment:1 Changed 7 years ago by rosenauer - at + gmx . at
- Summary changed from User-defined alternate formats to User-defined alternate formats [export] [wiki]
comment:2 Changed 7 years ago by anonymous
Question, how did these guys do this with trac?
http://smartpm.python-hosting.com/?format=pdf
It renders their trac wiki as a pdf file.
comment:3 Changed 7 years ago by remi@…
At Python-Hosting.com we just hacked Wiki.py to add the "HTML - no header/footer" and the "PDF" formats.
Here is the "HTML - no header/footer" code:
def display_html(self): self.req.send_response(200) self.req.send_header('Content-Type', 'text/html;charset=utf-8') self.req.end_headers() out = StringIO.StringIO() Formatter(self.req.hdf, self.env,self.db).format(self.page.text, out) self.req.write("<html><body>") self.req.write(out.getvalue()) self.req.write("</body></html>")
And here is the PDF code: it just makes a system call to the "HTMLDoc" tool (see http://www.htmldoc.org), which easily converts HTML documents to PDF.
def display_pdf(self): out = StringIO.StringIO() Formatter(self.req.hdf, self.env,self.db).format(self.page.text, out) html = StringIO.StringIO() html.write("<html><body>") html.write(out.getvalue()) html.write("</body></html>") # Write html content to random file i = random.randint(0,1000000) htmlF = '/tmp/trac-%s.html' % i pdfF = htmlF.replace('.html', '.pdf') f = open(htmlF, 'wb') f.write(html.getvalue()) f.close() os.system('export HTMLDOC_NOCGI="yes"; htmldoc --webpage %s -f %s' % (htmlF, pdfF)) self.req.send_response(200) self.req.send_header('Content-Type', 'application/pdf') self.req.end_headers() f = open(pdfF, 'rb') self.req.write(f.read()) f.close() os.remove(htmlF) os.remove(pdfF)
Hope this helps ... And thanks again for a great tool !
comment:4 Changed 6 years ago by Alec Thomas <alec@…>
I've attached a patch against [2737] which adds an !IWikiFormatExporter
extension point. It currently exports the original 'txt' format in
addition to a raw HTML format (because it was an easy example).
Thus it should be trivial to create a PDF export plugin.
comment:5 Changed 6 years ago by Alec Thomas <alec@…>
Whoops, too much patch.
Changed 6 years ago by Alec Thomas <alec@…>
- Attachment wiki-exporter.diff added
Changed 6 years ago by Alec Thomas <alec@…>
- Attachment wiki-exporter-2.diff added
comment:6 Changed 6 years ago by Alec Thomas <alec@…>
Matt suggested creating a generic MIME type converter rather than
having a specific Wiki exporter. This made sense to me and I have
implemented a patch, available [http://swapoff.org/files/mime-system.diff
here].
I also added an IMimeRegistry extension point which could be used to
perform "real" lookups against the [http://www.freedesktop.org/Standards
/shared-mime-info-spec shared-mime-info] database. At the moment it just
implements some basic types used by Trac, including trac/x-trac-wiki.
comment:7 Changed 6 years ago by James S.
wow - just what I've been looking for. Would anyone care to explain to me how I can get the .diff files merged into the wiki?
I looked everywhere, but couldn't find a Wiki.py file - I'm using the latest stable though.
Please help me!
comment:8 Changed 6 years ago by eblot
There is no "Wiki.py" file in the diff file.
Please ask support and "howto" questions on the ML or on IRC, not in the bug tracking DB. You need the "patch" tool or TortoiseSVN for example to apply a patch file (.diff) onto the current code.
comment:9 Changed 6 years ago by Alec Thomas <alec@…>
I have updated the patch a bit, and implemented a PDF export on top of the interface provided. Patch is here, PDF export plugin is here. It uses HTMLDOC, pretty much in the same manner as Python Hosting do.
comment:10 Changed 6 years ago by mgood
James: the modifications above with Wiki.py by done by Python-Hosting.com on Trac 0.8. Now those methods would be in source:/trunk/trac/wiki/web_ui.py.
comment:11 Changed 6 years ago by James S.
thanks a lot mgood - I'll get this one figured out now I guess :-)
comment:12 Changed 6 years ago by Chris Read
Excellent patch, is it due to make its way into future releases?
I've written a little python script that uses this to pull down an entire wiki. The script is available at http://www.chris-read.net/files/trac-html-scraper.py
comment:13 Changed 6 years ago by Markus Tacker <m@…>
- Cc m@… added
comment:14 Changed 6 years ago by anonymous
- Cc daved@… added
comment:15 Changed 6 years ago by Trent Apted <tapted@…>
- Cc tapted@… added
See also ticket #2296 (export to LaTeX + pdflatex = much nicer PDF)
comment:16 Changed 6 years ago by anonymous
- Cc danarmak@… added
comment:17 Changed 6 years ago by trac@…
- Cc trac@… added
- Type changed from defect to enhancement
I edited Chris Read's script. http://ragnarok.2y.net/trac-html-scraper.py
I added reports and tickets, authentication, and a few other tweaks.
I also put together a quick script (there may be transcription errors) that gets run in cron.daily. To use it, you add to the top level of the subversion directory 'trac_html' and also check in the '/trac' directory from htdocs (includes the CSS and PNG). This has worked well for us where we had a customer that had svn but not trac but wanted to see all our progress reports, etc, that we had in trac.
http://ragnarok.2y.net/trac_html.sh
Both of these were hand copied from printouts (but the python one was somewhat tested) so if you see any blatant errors, please email me. Also note I'm not a python programmer so I faked it a lot.
comment:18 Changed 6 years ago by athomas
More updates and a cleaner patch at #2296. Will hopefully merge this into trunk soon.
comment:19 Changed 5 years ago by sid
TracHacks now has a PageToPdf plugin available that uses the IContentConverter API to create a user-defined Wiki export format.
Also, #3332 discusses some of the work remaining for IContentConverter.
comment:20 Changed 5 years ago by cboos
- Resolution set to duplicate
- Status changed from new to closed
Yes, let's close this one as dup of #3332, which implements this feature.
comment:21 Changed 5 years ago by anonymous
- Cc daved@… removed



This would be a very needed feature here, too.
I love to use Trac and its Wiki for all project-documentation.
However, when I need something to pass on (i.e. as a final result), I'd like to be able to export all Wiki-Pages to a printable form or at least html.
I understand there's a dump-feature, but I have not yet tried it out, also it only supports html (which won't keep images I suppose?) and is not available from the admin-page.