Modify

Opened 5 years ago

Last modified 5 years ago

#4616 assigned enhancement

Simplify the creation of multi-page documents

Reported by: mvlcek Owned by: grigi
Priority: high Component: TracWikiToPdfPlugin
Severity: normal Keywords: patch
Cc: Trac Release: 0.11

Description

The patch allows the definition of a document on a wiki page like follows:

----

Anything between the two horizontal lines will be put on the title page.

The configured title page is not used.

----

In the section all linked pages are added to the document. The links must be in the following format:
 * [wiki:Chapter1]
 * [wiki:Chapter2]
 * [wiki:Chapter3]
 * ...
Everything besides the links is ignored.

Attachments (2)

wikitopdf.py (5.7 KB) - added by mvlcek 5 years ago.
multiple_pages_patch.txt (5.2 KB) - added by mickem 5 years ago.
patch to add "this" to 0.11

Download all attachments as: .zip

Change History (8)

Changed 5 years ago by mvlcek

comment:1 Changed 5 years ago by mvlcek

  • Priority changed from normal to high

Added support for reading the header for the table of content:

----

Anything between the two horizontal lines will be put on the title page.

The configured title page is not used.

----

The first header in this section is used as caption for the table of content

== Table of Content ==

In the section all linked pages are added to the document. The links must be in the following format:
 * [wiki:Chapter1]
 * [wiki:Chapter2]
 * [wiki:Chapter3]
 * ...
Everything besides the links is ignored.}}}

comment:2 Changed 5 years ago by izzy

Will there be a similar patch (or the functionality added to the code) for 0.11?

comment:3 Changed 5 years ago by grigi

  • Owner changed from diorgenes to grigi
  • Status changed from new to assigned

I think that this functionality is very important for this plugin, I just don't know if this is the "right" way to do something like this.

I agree it should use a TOC-like structure, but maybe a macro/ or markup would be of more use?

Something like:

{{{
#!PDFBook
---
<Frontpage override, if you don't specify this it uses the default one>
---

Variables to replace data in frontpage.
Title = <blah>
Sub-Title = <blah>
Version = <blah>
Date = <blah>
If Date is not specified, it will automatically populate it with the generation date.

TOCCaption = <Table of Contents Caption>
Pages = PageOne,PageTwo,Pages/*

Anything else is ignored.
}}}

The preprocessor by default returns blank back to Trac.

You could pace a link to "Download Current PDF book" like:

Download all documentation as [wiki:ThisPage?format=pdfbook PDF Book]

The issue is HOW, I'm not entirely sure how to do all this.

comment:4 Changed 5 years ago by grigi

mvlcek:
Commit [5673] adds your patch for version 0.10
I cannot support 0.10 properly, since I didn't have a 0.10 installation for ages.
Please check that is works fine.
Thanks in advance,
Grigi

comment:5 Changed 5 years ago by anonymous

http://svn.ipd.uka.de/trac/javaparty/wiki/TracNav allows to specify such a page usable for the wiki.

if the macro text could be specified on the tracnav table of contents page it would be usable for both, (1) the wiki itself, and (2) printing pdf.

another possibility for specifying the contents would be the TagsPlugin, by using lists like [[ListTagged(macro -plugin)]].

comment:6 Changed 5 years ago by mickem

  • Keywords patch added
  • Trac Release changed from 0.10 to 0.11

I did a quick fix to add this support to the 0.11 branch.
Now I am (as always) not a python/trac/* expert so take this for hat it is.
There are also some issues with the title/subject (which are not set, but they are not set from the admin either so maybe I have configured something wrong).
The relevant sections are the onse below, the patch has some other things I have played with as well (which might not be what everyone wants).

@@ -224,9 +230,48 @@
         page = wiki_to_pdf(text, self.env, req, base_dir, codepage)

         hfile, hfilename = mkstemp('wikitopdf')
-        os.write(hfile, page)
+       os.write(hfile, page)
         os.close(hfile)

+       mo = None
+       if text.startswith('----'):
+               mo = re.match(r'\-+\r\n([^\-].*?)\r\n\-\-\-\-+\r\n([^\-].*?)\r\n\-\-\-\-+\r\n(.*)', text, re.DOTALL | re.MULTILINE)
+
+       if mo:
+               bookname = 'WikiToPdf'
+               title = 'WikiToPdf'
+               subject = 'WikiToPdf'
+               title = mo.group(2)
+               bn = re.match(r'.*?bookname\=(.*?)\r\n', mo.group(1), re.DOTALL | re.MULTILINE)
+               if bn:
+                       bookname = bn.group(1)
+               bn = re.match(r'.*?title\=(.*?)\r\n', mo.group(1), re.DOTALL | re.MULTILINE)
+               if bn:
+                       title = bn.group(1)
+               bn = re.match(r'.*?subject\=(.*?)\r\n', mo.group(1), re.DOTALL | re.MULTILINE)
+               if bn:
+                       subject = bn.group(1)
+               pages = [p for p in re.findall(r'\[wiki:([^\] ]+)', mo.group(3))]
+               title_page = mo.group(1)
+
+               formats = {}
+               for provider in self.formats:
+                   for format, name in provider.wikitopdf_formats(req):
+                       formats[format] = {
+                           'name': name,
+                           'provider': provider,
+                       }
+                       self.env.log.error('TEST => Name: %s' % (name))
+
+               date = '2008-01-01'
+               version = '1.0'
+               format = 'pdf'
+
+               if not format or format not in formats:
+                       raise TracError('Bad format given for WikiToPdf output.')
+
+               return formats[format]['provider'].process_wikitopdf(req, format, title, subject, pages, date, version, bookname)
+
         htmldoc_args = { 'webpage': '', 'format': 'pdf14', 'charset': codepage }
         htmldoc_args.update(dict(self.env.config.options('wikitopdf-page')))

Changed 5 years ago by mickem

patch to add "this" to 0.11

Add Comment

Modify Ticket

Action
as assigned .
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.