Edgewall Software

Ticket #1468 (closed enhancement: duplicate)

Opened 4 years ago

Last modified 23 months 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@…

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

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

Change History

Changed 4 years ago by rosenauer - at + gmx . at

  • summary changed from User-defined alternate formats to User-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.

Changed 3 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.

Changed 3 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 !

Changed 3 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.

Changed 3 years ago by Alec Thomas <alec@…>

Whoops, too much patch.

Changed 3 years ago by Alec Thomas <alec@…>

Changed 3 years ago by Alec Thomas <alec@…>

Changed 3 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.

Changed 3 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!

Changed 3 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.

Changed 3 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.

Changed 3 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.

Changed 3 years ago by James S.

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

Changed 3 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

Changed 3 years ago by Markus Tacker <m@…>

  • cc m@… added

Changed 3 years ago by anonymous

  • cc daved@… added

Changed 3 years ago by Trent Apted <tapted@…>

  • cc tapted@… added

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

Changed 3 years ago by anonymous

  • cc danarmak@… added

Changed 3 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.

Changed 3 years ago by athomas

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

Changed 2 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.

Changed 2 years ago by cboos

  • status changed from new to closed
  • resolution set to duplicate

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

Changed 23 months ago by anonymous

  • cc daved@… removed

Add/Change #1468 (User-defined alternate formats [export] [wiki])

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
to The owner will change from jonas. Next status will be 'closed'
 
Note: See TracTickets for help on using tickets.