Edgewall Software

Opened 15 years ago

Closed 13 years ago

Last modified 6 years ago

#1468 closed enhancement (duplicate)

User-defined alternate formats [export] [wiki]

Reported by: shad Owned by: Jonas Borgström
Priority: normal Milestone:
Component: wiki system Version: 0.8.1
Severity: normal Keywords:
Cc: m@…, tapted@…, danarmak@…, trac@… Branch:
Release Notes:
API Changes:


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 (2)

wiki-exporter.diff (9.3 KB ) - added by Alec Thomas <alec@…> 14 years ago.
wiki-exporter-2.diff (4.1 KB ) - added by Alec Thomas <alec@…> 14 years ago.

Download all attachments as: .zip

Change History (23)

comment:1 by rosenauer - at + gmx . at, 15 years ago

Summary: User-defined alternate formatsUser-defined alternate formats [export] [wiki]

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.

comment:2 by anonymous, 14 years ago

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 by remi@…, 14 years ago

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_header('Content-Type', 'text/html;charset=utf-8')
        out = StringIO.StringIO()
        Formatter(self.req.hdf, self.env,self.db).format(self.page.text, out)

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()
        # 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')
        os.system('export HTMLDOC_NOCGI="yes"; htmldoc --webpage %s -f %s' % (htmlF, pdfF))
        self.req.send_header('Content-Type', 'application/pdf')
        f = open(pdfF, 'rb')

Hope this helps … And thanks again for a great tool !

comment:4 by Alec Thomas <alec@…>, 14 years ago

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 by Alec Thomas <alec@…>, 14 years ago

Whoops, too much patch.

by Alec Thomas <alec@…>, 14 years ago

Attachment: wiki-exporter.diff added

by Alec Thomas <alec@…>, 14 years ago

Attachment: wiki-exporter-2.diff added

comment:6 by Alec Thomas <alec@…>, 14 years ago

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 by James S., 14 years ago

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 by Emmanuel Blot, 14 years ago

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 by Alec Thomas <alec@…>, 14 years ago

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 by Matthew Good, 14 years ago

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 by James S., 14 years ago

thanks a lot mgood - I'll get this one figured out now I guess :-)

comment:12 by Chris Read, 14 years ago

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 by Markus Tacker <m@…>, 14 years ago

Cc: m@… added

comment:14 by anonymous, 14 years ago

Cc: daved@… added

comment:15 by Trent Apted <tapted@…>, 14 years ago

Cc: tapted@… added

See also ticket #2296 (export to LaTeX + pdflatex = much nicer PDF)

comment:16 by anonymous, 14 years ago

Cc: danarmak@… added

comment:17 by trac@…, 14 years ago

Cc: trac@… added
Type: defectenhancement

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.

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 by Alec Thomas, 14 years ago

More updates and a cleaner patch at #2296. Will hopefully merge this into trunk soon.

comment:19 by sid, 13 years ago

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 by Christian Boos, 13 years ago

Resolution: duplicate
Status: newclosed

Yes, let's close this one as dup of #3332, which implements this feature.

comment:21 by anonymous, 13 years ago

Cc: daved@… removed

Modify Ticket

Change Properties
Set your email in Preferences
as closed The owner will remain Jonas Borgström.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Jonas Borgström to the specified user.

Add Comment

E-mail address and name can be saved in the Preferences .
Note: See TracTickets for help on using tickets.