annotate MoinMoin/formatter/text_docbook.py @ 3248:2ea14aac1a35

Blacklist navigation macro
author Mikko Virkkil? <mvirkkil@cc.hut.fi>
date Thu, 13 Mar 2008 11:06:11 +0100
parents c715d62efc50
children 1ff7cb6c381b
rev   line source
3199
593d2e6265ce Change back to iso-8859-1
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3198
diff changeset
1 # -*- coding: iso-8859-1 -*-
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
2 """
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
3 MoinMoin - DocBook Formatter
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
4
3199
593d2e6265ce Change back to iso-8859-1
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3198
diff changeset
5 @copyright: 2005,2008 by Mikko Virkkilä <mvirkkil@cc.hut.fi>
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
6 @copyright: 2005 by MoinMoin:AlexanderSchremmer (small modifications)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
7 @copyright: 2005 by MoinMoin:Petr Pytelka <pyta@lightcomp.com> (small modifications)
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
8
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
9 @license: GNU GPL, see COPYING for details.
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
10 """
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
11
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
12 import os
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
13
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
14 from xml.dom import getDOMImplementation
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
15 from xml.dom.ext.reader import Sax
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
16 from xml.dom.ext import Node
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
17
661
19ef5f9fff84 moved formatter.base to formatter.__init__
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 660
diff changeset
18 from MoinMoin.formatter import FormatterBase
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
19 from MoinMoin import wikiutil
86
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
20 from MoinMoin.error import CompositeError
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
21 from MoinMoin.action import AttachFile
86
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
22
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
23
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
24 class InternalError(CompositeError):
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
25 pass
86
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
26
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
27 try:
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
28 dom = getDOMImplementation("4DOM")
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
29 except ImportError:
2233
666625ecde91 Fix error message in the docbook formatter, should be ported to 1.7.
Alexander Schremmer <alex AT alexanderweb DOT de>
parents: 1796
diff changeset
30 raise InternalError("You need to install 4suite to use the DocBook formatter.")
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
31
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
32
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
33 class Formatter(FormatterBase):
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
34 #TODO: How to handle revision history and other meta-info from included files?
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
35 # The problem is that we don't know what the original page is, since
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
36 # the Inlcude-macro doesn't pass us the information.
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
37
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
38 # this list is extended as the page is parsed. Could be optimized by adding them here?
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
39 section_should_break = ['abstract', 'para', 'emphasis']
3192
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
40
3248
2ea14aac1a35 Blacklist navigation macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3247
diff changeset
41 blacklisted_macros = ('TableOfContents', 'ShowSmileys', 'Navigation')
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
42
3187
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
43 # If the current node is one of the following and we are about the emit
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
44 # text, the text should be wrapped in a paragraph
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
45 wrap_text_in_para = ('listitem', 'glossdef', 'article', 'chapter', 'tip', 'warning', 'note', 'caution', 'important')
3192
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
46
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
47 # from dtd
3191
a4cfe360dd33 Removed cruft from section handling and made it cover more possible cases
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3190
diff changeset
48 _can_contain_section = ("section", "appendix", "article", "chapter", "patintro", "preface")
3187
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
49
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
50 def __init__(self, request, doctype="article", **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
51 FormatterBase.__init__(self, request, **kw)
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
52 self.request = request
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
53
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
54 '''
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
55 If the formatter is used by the Include macro, it will set
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
56 is_included=True in which case we know we need to call startDocument
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
57 and endDocument from startContent and endContent respectively, since
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
58 the Include macro will not be calling them, and the formatter doesn't
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
59 work properly unless they are called.
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
60 '''
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
61 if kw.has_key("is_included") and kw["is_included"]:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
62 self.include_kludge = True
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
63 else:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
64 self.include_kludge = False
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
65
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
66 self.doctype = doctype
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
67 self.curdepth = 0
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
68 self.cur = None
86
5181bcd3feb5 Show a better error message if PyXML is not installed and the docbook formatter is used.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 82
diff changeset
69
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
70 def startDocument(self, pagename):
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
71 self.doc = dom.createDocument(None, self.doctype, dom.createDocumentType(
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
72 self.doctype, "-//OASIS//DTD DocBook XML V4.4//EN",
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
73 "http://www.docbook.org/xml/4.4/docbookx.dtd"))
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
74
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
75 self.title = pagename
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
76 self.root = self.doc.documentElement
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
77
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
78 if not self.include_kludge and self.doctype == "article":
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
79 info = self.doc.createElement("articleinfo")
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
80 self.root.appendChild(info)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
81 self._addTitleElement(self.title, targetNode=info)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
82 self._addRevisionHistory(targetNode=info)
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
83 else:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
84 self._addTitleElement(self.title, targetNode=self.root)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
85
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
86 self.cur = self.root
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
87 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
88
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
89 def startContent(self, content_id="content", **kw):
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
90 if self.include_kludge and not self.cur:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
91 return self.startDocument("OnlyAnIdiotWouldCreateSuchaPage")
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
92 return ""
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
93
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
94 def endContent(self):
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
95 if self.include_kludge:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
96 return self.endDocument()
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
97 return ""
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
98
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
99 def endDocument(self):
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
100 from xml.dom.ext import PrettyPrint, Print
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
101 import StringIO
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
102
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
103 f = StringIO.StringIO()
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
104 Print(self.doc, f)
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
105 txt = f.getvalue()
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
106 f.close()
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
107
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
108 self.cur = None
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
109 return txt
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
110
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
111 def text(self, text, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
112 if text == "\\n":
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
113 srcText = "\n"
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
114 else:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
115 srcText = text
3192
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
116
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
117 if srcText and self._isInsidePreformatted():
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
118
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
119 if self.cur.lastChild is not None and self.cur.lastChild.nodeType == Node.CDATA_SECTION_NODE:
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
120 # We can add it to a previous CDATA section
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
121 self.cur.lastChild.nodeValue = self.cur.lastChild.nodeValue + srcText
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
122 else:
3192
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
123 # We create a new cdata section
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
124 self.cur.appendChild(self.doc.createCDATASection(srcText))
3192
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
125
3187
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
126 elif self.cur.nodeName in self.wrap_text_in_para:
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
127 """
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
128 If we already wrapped one text item in a para, we should add to that para
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
129 and not create a new one. Another question is if we should add a space?
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
130 """
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
131 if self.cur.lastChild is not None and self.cur.lastChild.nodeName == 'para':
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
132 self.cur.lastChild.appendChild(self.doc.createTextNode(srcText))
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
133 else:
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
134 self.paragraph(1)
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
135 self.text(text)
4232b56627c7 Only some elements can contain text-nodes directly, while other elements must have the text wrapped in a paragraph for them to be able to contain it. This commit adds support for wrapping textnodes in paragrap-elements when needed.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3186
diff changeset
136 self.paragraph(0)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
137 else:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
138 self.cur.appendChild(self.doc.createTextNode(srcText))
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
139 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
140
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
141 def heading(self, on, depth, **kw):
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
142 while self.cur.nodeName in self.section_should_break:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
143 self.cur = self.cur.parentNode
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
144
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
145 if on:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
146 # try to go to higher level if needed
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
147 if depth <= self.curdepth:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
148 # number of levels we want to go higher
2450
3d08f1cb4429 pep8 whitespace fixes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2286
diff changeset
149 numberOfLevels = self.curdepth - depth + 1
1793
2a4caa295346 Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 1791
diff changeset
150 for dummy in range(numberOfLevels):
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
151 # find first non section node
3191
a4cfe360dd33 Removed cruft from section handling and made it cover more possible cases
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3190
diff changeset
152 while not self.cur.nodeName in self._can_contain_section:
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
153 self.cur = self.cur.parentNode
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
154
3191
a4cfe360dd33 Removed cruft from section handling and made it cover more possible cases
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3190
diff changeset
155 if self.cur.nodeName == "section":
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
156 self.cur = self.cur.parentNode
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
157
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
158 section = self.doc.createElement("section")
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
159 self.cur.appendChild(section)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
160 self.cur = section
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
161
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
162 title = self.doc.createElement("title")
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
163 self.cur.appendChild(title)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
164 self.cur = title
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
165 self.curdepth = depth
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
166 else:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
167 self.cur = self.cur.parentNode
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
168
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
169 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
170
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
171 def paragraph(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
172 FormatterBase.paragraph(self, on)
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
173
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
174 # Let's prevent empty paras
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
175 if not on:
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
176 if not self._hasContent(self.cur):
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
177 oldnode = self.cur
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
178 self.cur = oldnode.parentNode
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
179 self.cur.removeChild(oldnode)
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
180 return ""
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
181
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
182 # Let's prevent para inside para
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
183 if on and self.cur.nodeName == "para":
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
184 return ""
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
185 return self._handleNode("para", on)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
186
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
187 def linebreak(self, preformatted=1):
3188
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
188 """
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
189 If preformatted, it will simply output a linebreak.
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
190 If we are in a paragraph, we will close it, and open another one.
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
191 """
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
192 if preformatted:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
193 self.text('\\n')
3188
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
194 elif self.cur.nodeName == "para":
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
195 self.paragraph(0)
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
196 self.paragraph(1)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
197 else:
3188
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
198 self._emitComment("Warning: Probably not emitting right sort of linebreak")
fd905ed64dff Added support for linebreaks in paragraphs by exiting the current paragraph element and creating a new one.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3187
diff changeset
199 self.text('\n')
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
200 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
201
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
202 ### Inline ##########################################################
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
203
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
204 def strong(self, on, **kw):
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
205 return self._handleFormatting("emphasis", on, (('role', 'strong'), ))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
206
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
207 def emphasis(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
208 return self._handleFormatting("emphasis", on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
209
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
210 def underline(self, on, **kw):
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
211 return self._handleFormatting("emphasis", on, (('role', 'underline'), ))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
212
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
213 def highlight(self, on, **kw):
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
214 return self._handleFormatting("emphasis", on, (('role', 'highlight'), ))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
215
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
216 def sup(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
217 return self._handleFormatting("superscript", on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
218
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
219 def sub(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
220 return self._handleFormatting("subscript", on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
221
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
222 def strike(self, on, **kw):
264
67e1f1d49a97 Fixed XML formatters.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 217
diff changeset
223 # does not yield <strike> using the HTML XSLT files here ...
67e1f1d49a97 Fixed XML formatters.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 217
diff changeset
224 # but seems to be correct
217
98df82a31b87 Added strike() to non HTML formatters. PLEASE REVIEW the xml_docbook FORMATTER!
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 200
diff changeset
225 return self._handleFormatting("emphasis", on,
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
226 (('role', 'strikethrough'), ))
217
98df82a31b87 Added strike() to non HTML formatters. PLEASE REVIEW the xml_docbook FORMATTER!
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 200
diff changeset
227
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
228 def code(self, on, **kw):
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
229 # Let's prevent empty code
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
230 if not on:
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
231 if not self._hasContent(self.cur):
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
232 oldnode = self.cur
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
233 self.cur = oldnode.parentNode
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
234 self.cur.removeChild(oldnode)
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
235 return ""
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
236 return self._handleFormatting("code", on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
237
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
238 def preformatted(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
239 return self._handleFormatting("screen", on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
240
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
241
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
242 ### Lists ###########################################################
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
243
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
244 def number_list(self, on, type=None, start=None, **kw):
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
245 docbook_ol_types = {'1': "arabic",
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
246 'a': "loweralpha",
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
247 'A': "upperalpha",
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
248 'i': "lowerroman",
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
249 'I': "upperroman"}
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
250
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
251 if type and docbook_ol_types.has_key(type):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
252 attrs = [("numeration", docbook_ol_types[type])]
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
253 else:
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
254 attrs = []
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
255
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
256 return self._handleNode('orderedlist', on, attrs)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
257
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
258 def bullet_list(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
259 return self._handleNode("itemizedlist", on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
260
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
261 def listitem(self, on, style=None, **kw):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
262 if self.cur.nodeName == "glosslist" or self.cur.nodeName == "glossentry":
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
263 return self.definition_desc(on)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
264 if on and self.cur.nodeName == "listitem":
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
265 """If we are inside a listitem, and someone wants to create a new one, it
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
266 means they forgot to close the old one, and we need to do it for them."""
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
267 self.listitem(0)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
268
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
269 args = []
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
270 if on and style:
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
271 styles = self._convertStylesToDict(style)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
272 if styles.has_key('list-style-type'):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
273 args.append(('override', styles['list-style-type']))
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
274
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
275 return self._handleNode("listitem", on, attributes=args)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
276
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
277 def definition_list(self, on, **kw):
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
278 return self._handleNode("glosslist", on)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
279
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
280 def definition_term(self, on, compact=0, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
281 if on:
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
282 self._handleNode("glossentry", on)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
283 self._handleNode("glossterm", on)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
284 else:
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
285 if self._hasContent(self.cur):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
286 self._handleNode("glossterm", on)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
287 self._handleNode("glossentry", on)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
288 else:
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
289 # No term info :(
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
290 term = self.cur
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
291 entry = term.parentNode
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
292 self.cur = entry.parentNode
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
293 self.cur.removeChild(entry)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
294 return ""
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
295
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
296 def definition_desc(self, on, **kw):
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
297 if on:
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
298 if self.cur.nodeName == "glossentry":
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
299 # Good, we can add it here.
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
300 self._handleNode("glossdef", on)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
301 return ""
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
302
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
303 # We are somewhere else, let's see...
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
304 if self.cur.nodeName != "glosslist":
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
305 self._emitComment("Trying to add a definition, but we arent in a glosslist")
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
306 return ""
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
307 if not self.cur.lastChild or self.cur.lastChild.nodeName != "glossentry":
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
308 self._emitComment("Trying to add a definition, but there is no entry")
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
309 return ""
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
310
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
311 # Found it, calling again
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
312 self.cur = self.cur.lastChild
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
313 return self.definition_desc(on)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
314 else:
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
315 if not self._hasContent(self.cur):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
316 # Seems no valuable info was added
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
317 assert(self.cur.nodeName == "glossdef")
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
318 toRemove = self.cur
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
319 self.cur = toRemove.parentNode
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
320 self.cur.removeChild(toRemove)
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
321
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
322 while self.cur.nodeName != "glosslist":
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
323 self.cur = self.cur.parentNode
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
324 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
325
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
326 ### Links ###########################################################
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
327 # TODO: Fix anchors to documents which are included. Needs probably to be
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
328 # a postprocessing rule. Could be done by having the anchors have
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
329 # the "linkend" value of PageName#anchor. Then at post process the
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
330 # following would be done for all urls:
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
331 # - get all ulinks with an anchor part in their url
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
332 # - get the ulink's PageName#anchor -part by removing baseurl part
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
333 # - if any of our <anchor> elements have the same PageName#anchor
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
334 # value as our <ulink>, then replace the ulink with a link
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
335 # element.
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
336 # Note: This would the case when someone wants to link to a
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
337 # section on the original webpage impossible. The link would
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
338 # instead point within the docbook page and not to the webpage.
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
339
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
340
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
341 def pagelink(self, on, pagename='', page=None, **kw):
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
342 FormatterBase.pagelink(self, on, pagename, page, **kw)
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
343 return self.interwikilink(on, 'Self', pagename, **kw)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
344
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
345 def interwikilink(self, on, interwiki='', pagename='', **kw):
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
346 if not on:
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
347 return self.url(on, **kw)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
348
2728
59b3d8b8971f remove (un)quoteName, new functions split_interwiki() and resolve_interwiki(), cleanup interwiki mess, fix some link markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2450
diff changeset
349 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_interwiki(self.request, interwiki, pagename)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
350 wikiurl = wikiutil.mapURL(self.request, wikiurl)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
351 href = wikiutil.join_wiki(wikiurl, wikitail)
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
352 if kw.has_key("anchor"):
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
353 href="%s#%s"%(href, kw['anchor'])
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
354
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
355 if pagename == self.page.page_name:
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
356 kw['is_self']=True
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
357
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
358 return self.url(on, href, **kw)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
359
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
360 def url(self, on, url=None, css=None, **kw):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
361 if url and url.startswith("/"):
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
362 # convert to absolute path:
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
363 url = "%s%s"%(self.request.getBaseURL(), url)
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
364
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
365 if not on:
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
366 self._cleanupUlinkNode()
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
367
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
368 if kw.has_key("anchor") and kw.has_key("is_self") and kw["is_self"]:
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
369 #handle the case where we are pointing to somewhere insidee our own document
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
370 return self._handleNode("link", on, attributes=(('linkend', kw["anchor"]), ))
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
371 else:
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
372 return self._handleNode("ulink", on, attributes=(('url', url), ))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
373
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
374 def anchordef(self, name):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
375 self._handleNode("anchor", True, attributes=(('id', name), ))
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
376 self._handleNode("anchor", False)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
377 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
378
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
379 def anchorlink(self, on, name='', **kw):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
380 linkid = kw.get('id', None)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
381 attrs = []
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
382 if name != '':
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
383 attrs.append(('endterm', name))
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
384 if id is not None:
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
385 attrs.append(('linkend', linkid))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
386 elif name != '':
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
387 attrs.append(('linkend', name))
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
388
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
389 return self._handleNode("link", on, attrs)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
390
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
391 ### Attachments ######################################################
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
392
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2450
diff changeset
393 def attachment_link(self, on, url=None, **kw):
3008
f8738a94d990 fix attachment_link of docbook formatter (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2779
diff changeset
394 assert on in (0, 1, False, True) # make sure we get called the new way, not like the 1.5 api was
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2450
diff changeset
395 # we do not output a "upload link" when outputting docbook
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2450
diff changeset
396 if on:
3008
f8738a94d990 fix attachment_link of docbook formatter (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2779
diff changeset
397 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
f8738a94d990 fix attachment_link of docbook formatter (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2779
diff changeset
398 fname = wikiutil.taintfilename(filename)
f8738a94d990 fix attachment_link of docbook formatter (port from 1.6)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2779
diff changeset
399 target = AttachFile.getAttachUrl(pagename, filename, self.request)
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2450
diff changeset
400 return self.url(1, target, title="attachment:%s" % url)
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
401 else:
2701
398af77c7ede fixed attachment_link api - it now has a 'on' parameter like most of the other methods
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2450
diff changeset
402 return self.url(0)
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
403
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
404 def attachment_image(self, url, **kw):
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
405 """
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
406 Figures out the absolute path to the image and then hands over to
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
407 the image function. Any title is also handed over, and an additional
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
408 title suggestion is made based on filename. The image function will
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
409 use the suggestion if no other text alternative is found.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
410
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
411 If the file is not found, then a simple text will replace it.
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
412 """
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
413 _ = self.request.getText
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
414 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
415 fname = wikiutil.taintfilename(filename)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
416 fpath = AttachFile.getFilename(self.request, pagename, fname)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
417 if not os.path.exists(fpath):
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
418 return self.text("[attachment:%s]" % url)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
419 else:
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
420 return self.image(
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
421 src=AttachFile.getAttachUrl(pagename, filename,
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
422 self.request, addts=1),
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
423 attachment_title=url,
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
424 **kw)
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
425
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
426
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
427 def attachment_drawing(self, url, text, **kw):
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
428 _ = self.request.getText
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
429 pagename, filename = AttachFile.absoluteName(url, self.page.page_name)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
430 fname = wikiutil.taintfilename(filename)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
431 drawing = fname
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
432 fname = fname + ".png"
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
433 filename = filename + ".png"
1791
6dd2e29acffe Eclipse PyDev Check: fixed lots of its errors and warnings
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 999
diff changeset
434 fpath = AttachFile.getFilename(self.request, pagename, fname)
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
435 if not os.path.exists(fpath):
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
436 return self.text("[drawing:%s]" % url)
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
437 else:
3158
3ea8d2e4af32 minor whitespace fix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3150
diff changeset
438 src = AttachFile.getAttachUrl(pagename, filename, self.request, addts=1)
3150
8ae94675b9f9 AttachFile: some cosmetical source changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3008
diff changeset
439 return self.image(alt=drawing, src=src, html_class="drawing")
200
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
440
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
441 ### Images and Smileys ##############################################
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
442
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
443 def image(self, src=None, **kw):
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
444 if src:
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
445 kw['src'] = src
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
446 media = self.doc.createElement('inlinemediaobject')
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
447
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
448 imagewrap = self.doc.createElement('imageobject')
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
449 media.appendChild(imagewrap)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
450
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
451 image = self.doc.createElement('imagedata')
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
452 if kw.has_key('src'):
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
453 src = kw['src']
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
454 if src.startswith("/"):
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
455 # convert to absolute path:
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
456 src = self.request.getBaseURL()+src
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
457 image.setAttribute('fileref', src)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
458 if kw.has_key('width'):
734
bf2435e61f97 moved smileys from MoinMoin.config to theme, fixed smiley text_python caching bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 661
diff changeset
459 image.setAttribute('width', str(kw['width']))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
460 if kw.has_key('height'):
734
bf2435e61f97 moved smileys from MoinMoin.config to theme, fixed smiley text_python caching bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 661
diff changeset
461 image.setAttribute('depth', str(kw['height']))
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
462 imagewrap.appendChild(image)
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
463
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
464 # Look for any suitable title, order is important.
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
465 title = ''
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
466 for a in ('title', 'html_title', 'alt', 'html_alt', 'attachment_title'):
466
de6f08a584fa fix broken smileys for docbook formatter
Thomas Waldmann <tw@waldmann-edv.de>
parents: 407
diff changeset
467 if kw.has_key(a):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
468 title = kw[a]
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
469 break
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
470 if title:
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
471 txtcontainer = self.doc.createElement('textobject')
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
472 self._addTextElem(txtcontainer, "phrase", title)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
473 media.appendChild(txtcontainer)
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
474
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
475 self.cur.appendChild(media)
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
476 return ""
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
477
2713
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
478 def transclusion(self, on, **kw):
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
479 # TODO, see text_html formatter
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
480 self._emitComment('transclusion is not implemented in DocBook formatter')
2713
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
481 return ""
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
482
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
483 def transclusion_param(self, **kw):
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
484 # TODO, see text_html formatter
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
485 self._emitComment('transclusion parameters are not implemented in DocBook formatter')
2713
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
486 return ""
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
487
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
488 def smiley(self, text):
734
bf2435e61f97 moved smileys from MoinMoin.config to theme, fixed smiley text_python caching bug
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 661
diff changeset
489 return self.request.theme.make_icon(text)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
490
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
491 def icon(self, type):
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
492 return '' # self.request.theme.make_icon(type)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
493
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
494
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
495 ### Code area #######################################################
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
496
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
497 def code_area(self, on, code_id, code_type=None, show=0, start=-1, step=-1):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
498 """Creates a formatted code region using screen or programlisting,
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
499 depending on if a programming language was defined (code_type).
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
500
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
501 The code_id is not used for anything in this formatter, but is just
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
502 there to remain compatible with the HTML formatter's function.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
503
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
504 Line numbering is supported natively by DocBook so if linenumbering
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
505 is requested the relevant attribute will be set.
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
506
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
507 Call once with on=1 to start the region, and a second time
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
508 with on=0 to end it.
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
509 """
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
510
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
511 if not on:
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
512 return self._handleNode(None, on)
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
513
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
514 show = show and 'numbered' or 'unnumbered'
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
515 if start < 1:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
516 start = 1
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
517
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
518 programming_languages = {"ColorizedJava": "java",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
519 "ColorizedPython": "python",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
520 "ColorizedCPlusPlus": "c++",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
521 "ColorizedPascal": "pascal",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
522 }
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
523
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
524 if code_type is None:
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
525 attrs = (('linenumbering', show),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
526 ('startinglinenumber', str(start)),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
527 ('format', 'linespecific'),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
528 )
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
529 return self._handleNode("screen", on, attributes=attrs)
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
530 else:
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
531 if programming_languages.has_key(code_type):
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
532 code_type = programming_languages[code_type]
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
533
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
534 attrs = (('linenumbering', show),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
535 ('startinglinenumber', str(start)),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
536 ('language', code_type),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
537 ('format', 'linespecific'),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
538 )
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
539 return self._handleNode("programlisting", on, attributes=attrs)
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
540
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
541 def code_line(self, on):
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
542 if on:
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
543 self.cur.appendChild(self.doc.createTextNode('\n'))
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
544 return ''
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
545
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
546 def code_token(self, on, tok_type):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
547 """
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
548 DocBook has some support for semantic annotation of code so the
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
549 known tokens will be mapped to DocBook entities.
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
550 """
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
551 toks_map = {'ID': 'methodname',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
552 'Operator': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
553 'Char': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
554 'Comment': 'lineannotation',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
555 'Number': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
556 'String': 'phrase',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
557 'SPChar': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
558 'ResWord': 'token',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
559 'ConsWord': 'symbol',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
560 'Error': 'errortext',
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
561 'ResWord2': 'type',
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
562 'Special': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
563 'Preprc': '',
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
564 'Text': '',
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
565 }
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
566 if toks_map.has_key(tok_type) and toks_map[tok_type]:
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
567 return self._handleFormatting(toks_map[tok_type], on)
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
568 else:
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
569 return ""
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
570 ### Macro ###########################################################
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
571
2779
c9dd12befda7 wiki parser: match everything looking like a macro and either execute it (macro imports ok) or render the macro markup as text (macro import fails, error msg is in title). This makes scan_rules independent of wiki, so we can move all re.compile time to Parser class (doing it only once on module import time).
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2754
diff changeset
572 def macro(self, macro_obj, name, args, markup=None):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
573 """As far as the DocBook formatter is conserned there are three
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
574 kinds of macros: Bad, Handled and Unknown.
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
575
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
576 The Bad ones are the ones that are known not to work, and are on its
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
577 blacklist. They will be ignored and an XML comment will be written
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
578 noting that the macro is not supported.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
579
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
580 Handled macros are such macros that code is written to handle them.
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
581 For example for the FootNote macro it means that instead of executing
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
582 the macro, a DocBook footnote entity is created, with the relevant
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
583 pieces of information filles in.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
584
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
585 The Unknown are handled by executing the macro and capturing any
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
586 textual output. There shouldn't be any textual output since macros
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
587 should call formatter methods. This is unfortunately not always true,
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
588 so the output it is then fed in to an xml parser and the
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
589 resulting nodes copied to the DocBook-dom tree. If the output is not
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
590 valid xml then a comment is written in the DocBook that the macro
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
591 should be fixed.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
592
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
593 """
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
594 # Another alternative would be to feed the output to rawHTML or even
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
595 # combining these two approaches. The _best_ alternative would be to
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
596 # fix the macros.
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
597 excludes=("articleinfo", "title")
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
598
3185
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
599 if name in self.blacklisted_macros:
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
600 self._emitComment("The macro %s doesn't work with the DocBook formatter." % name)
3186
a36faa9f9d9f Add support for the FootNote macro by creating a DocBook-native footnote.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3185
diff changeset
601
a36faa9f9d9f Add support for the FootNote macro by creating a DocBook-native footnote.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3185
diff changeset
602 elif name == "FootNote":
a36faa9f9d9f Add support for the FootNote macro by creating a DocBook-native footnote.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3185
diff changeset
603 footnote = self.doc.createElement('footnote')
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
604 self._addTextElem(footnote, "para", str(args))
3186
a36faa9f9d9f Add support for the FootNote macro by creating a DocBook-native footnote.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3185
diff changeset
605 self.cur.appendChild(footnote)
a36faa9f9d9f Add support for the FootNote macro by creating a DocBook-native footnote.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3185
diff changeset
606
3185
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
607 elif name == "Include":
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
608 was_in_para = self.cur.nodeName == "para"
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
609 if was_in_para:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
610 self.paragraph(0)
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
611 text = FormatterBase.macro(self, macro_obj, name, args)
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
612 if text.strip():
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
613 self._copyExternalNodes(Sax.FromXml(text).documentElement.childNodes, exclude=excludes)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
614 if was_in_para:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
615 self.paragraph(1)
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
616
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
617 else:
3185
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
618 text = FormatterBase.macro(self, macro_obj, name, args)
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
619 if text:
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
620 from xml.parsers.expat import ExpatError
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
621 try:
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
622 xml_dom = Sax.FromXml(text).documentElement.childNodes
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
623 self._copyExternalNodes(xml_dom, exclude=excludes)
3185
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
624 except ExpatError:
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
625 self._emitComment("The macro %s caused an error and should be blacklisted. It returned the data '%s' which caused the docbook-formatter to choke. Please file a bug." % (name, text))
5e0aede39dea - The DocBook formatter will try to execute any macros it encounters and will
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3184
diff changeset
626
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
627 return u""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
628
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
629 ### Util functions ##################################################
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
630
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
631 def _copyExternalNodes(self, nodes, deep=1, target=None, exclude=()):
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
632 if not target:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
633 target = self.cur
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
634
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
635 for node in nodes:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
636 if node.nodeName in exclude:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
637 pass
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
638 elif target.nodeName == "para" and node.nodeName == "para":
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
639 self._copyExternalNodes(node.childNodes, target=target)
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
640 self.cur = target.parentNode
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
641 else:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
642 target.appendChild(self.doc.importNode(node, deep))
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
643
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
644 def _emitComment(self, text):
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
645 text = text.replace("--", "- -") # There cannot be "--" in XML comment
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
646 self.cur.appendChild(self.doc.createComment(text))
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
647
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
648 def _handleNode(self, name, on, attributes=()):
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
649 if on:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
650 node = self.doc.createElement(name)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
651 self.cur.appendChild(node)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
652 if len(attributes) > 0:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
653 for name, value in attributes:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
654 node.setAttribute(name, value)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
655 self.cur = node
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
656 else:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
657 """
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
658 Because we prevent para inside para, we might get extra "please
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
659 exit para" when we are no longer inside one.
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
660
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
661 TODO: Maybe rethink the para in para case
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
662 """
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
663 if name == "para" and self.cur.nodeName != "para":
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
664 return ""
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
665
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
666 self.cur = self.cur.parentNode
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
667 return ""
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
668
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
669 def _handleFormatting(self, name, on, attributes=()):
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
670 # We add all the elements we create to the list of elements that should not contain a section
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
671 if name not in self.section_should_break:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
672 self.section_should_break.append(name)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
673 return self._handleNode(name, on, attributes)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
674
3192
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
675 def _isInsidePreformatted(self):
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
676 """Walks all parents and checks if one is of a preformatted type, which
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
677 means the child would need to be preformatted == embedded in a cdata
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
678 section"""
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
679 n = self.cur
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
680 while n:
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
681 if n.nodeName in ("screen", "programlisting"):
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
682 return True
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
683 n = n.parentNode
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
684 return False
2c556643b167 Preformatted data such as programlistings need to be in CDATA sektions. Made sure we don't add more CDATA sektions than needed, but that we do add them when they are needed
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3191
diff changeset
685
3193
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
686 def _hasContent(self, node):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
687 if node.attributes and len(node.attributes):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
688 return True
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
689 for child in node.childNodes:
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
690 if child.nodeType == Node.TEXT_NODE and child.nodeValue.strip():
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
691 return True
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
692 elif child.nodeType == Node.CDATA_SECTION_NODE and child.nodeValue.strip():
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
693 return True
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
694
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
695 if self._hasContent(child):
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
696 return True
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
697 return False
c21d8620e432 Improve support for lists and glossaries: bulletless lists, glassary terms with multiple definitions etc.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3192
diff changeset
698
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
699 def _addTitleElement(self, titleTxt, targetNode=None):
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
700 if not targetNode:
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
701 targetNode = self.cur
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
702 self._addTextElem(targetNode, "title", titleTxt)
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
703
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
704 def _convertStylesToDict(self, styles):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
705 '''Takes the CSS styling information and converts it to a dict'''
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
706 attrs = {}
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
707 for s in styles.split(";"):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
708 if s.strip(' "') == "":
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
709 continue
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
710 (key, value) = s.split(":", 1)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
711 key = key.strip(' "')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
712 value = value.strip(' "')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
713
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
714 if key == 'vertical-align':
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
715 key = 'valign'
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
716 elif key == 'text-align':
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
717 key = 'align'
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
718 elif key == 'background-color':
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
719 key = 'bgcolor'
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
720
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
721 attrs[key] = value
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
722 return attrs
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
723
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
724 def _cleanupUlinkNode(self):
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
725 """
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
726 Moin adds the url as the text to a link, if no text is specified.
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
727 Docbook does it when a docbook is rendered, so we don't want moin to
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
728 do it and so if the url is exactly the same as the text node inside
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
729 the ulink, we remove the text node.
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
730 """
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
731 if self.cur.nodeName == "ulink" and len(self.cur.childNodes) == 1 \
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
732 and self.cur.firstChild.nodeType == Node.TEXT_NODE \
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
733 and self.cur.firstChild.nodeValue.strip() == self.cur.getAttribute('url').strip():
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
734 self.cur.removeChild(self.cur.firstChild)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
735
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
736 def _addTextElem(self, target, elemName, text):
3227
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
737 """
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
738 Creates an element of the name elemName and adds a text node to it
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
739 with the nodeValue of text. The new element is then added as a child
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
740 to the element target.
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
741 """
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
742 newElement = self.doc.createElement(elemName)
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
743 newElement.appendChild(self.doc.createTextNode(text))
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
744 target.appendChild(newElement)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
745
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
746
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
747 def _addRevisionHistory(self, targetNode):
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
748 """
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
749 This will generate a revhistory element which it will populate with
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
750 revision nodes. Each revision has the revnumber, date and author-
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
751 initial elements, and if a comment was supplied, the comment element.
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
752
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
753 The date elements format depends on the users settings, so it will
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
754 be in the same format as the revision history as viewed in the
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
755 page info on the wiki.
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
756
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
757 The authorinitials will be the UserName or if it was an anonymous
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
758 edit, then it will be the hostname/ip-address.
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
759
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
760 The revision history of included documents is NOT included at the
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
761 moment due to technical difficulties.
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
762 """
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
763 from MoinMoin.logfile import editlog
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
764 from MoinMoin import user
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
765 log = editlog.EditLog(self.request, rootpagename=self.title)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
766 user_cache = {}
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
767
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
768 history = self.doc.createElement("revhistory")
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
769
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
770 # read in the complete log of this page
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
771 for line in log.reverse():
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
772 if not line.action in ('SAVE', 'SAVENEW', 'SAVE/REVERT', 'SAVE/RENAME', ):
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
773 #Let's ignore adding of attachments
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
774 continue
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
775 revision = self.doc.createElement("revision")
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
776
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
777 # Revision number (without preceeding zeros)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
778 self._addTextElem(revision, "revnumber", line.rev.lstrip('0'))
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
779
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
780 # Date of revision
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
781 date_text = self.request.user.getFormattedDateTime(
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
782 wikiutil.version2timestamp(line.ed_time_usecs))
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
783 self._addTextElem(revision, "date", date_text)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
784
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
785 # Author or revision
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
786 if not (line.userid in user_cache):
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
787 user_cache[line.userid] = user.User(self.request, line.userid, auth_method="text_docbook:740")
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
788 author = user_cache[line.userid]
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
789 if author and author.name:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
790 self._addTextElem(revision, "authorinitials", author.name)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
791 else:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
792 self._addTextElem(revision, "authorinitials", line.hostname)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
793
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
794 # Comment from author of revision
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
795 comment = line.comment
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
796 if not comment:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
797 if '/REVERT' in line.action:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
798 comment = _("Revert to revision %(rev)d.") % {'rev': int(line.extra)}
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
799 elif '/RENAME' in line.action:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
800 comment = _("Renamed from '%(oldpagename)s'.") % {'oldpagename': line.extra}
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
801 if comment:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
802 self._addTextElem(revision, "revremark", comment)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
803
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
804 history.appendChild(revision)
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
805
3245
630e6066c935 Don't output empty revision history
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3228
diff changeset
806 if history.firstChild:
630e6066c935 Don't output empty revision history
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3228
diff changeset
807 #only add revision history is there is history to add
630e6066c935 Don't output empty revision history
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3228
diff changeset
808 targetNode.appendChild(history)
3183
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
809
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
810 ### Not supported ###################################################
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
811
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
812 def rule(self, size=0, **kw):
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
813 self._emitComment('rule (<hr>) is not applicable to DocBook')
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
814 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
815
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
816 def small(self, on, **kw):
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
817 if on:
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
818 self._emitComment('"~-smaller-~" is not applicable to DocBook')
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
819 return ""
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
820
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
821 def big(self, on, **kw):
3195
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
822 if on:
d186dc68f95f Prevent empty code- and para-elements. Output xml comment for some unsupported/unimplemented stuff instead of silently ignoring.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3194
diff changeset
823 self._emitComment('"~+bigger+~" is not applicable to DocBook')
82
0da5d27c0c3c Integrated new additions by Petr into the DocBook formatter. This includes better macro support, better heading semantics and cleaner include-macro results. Fixed line endings.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 0
diff changeset
824 return ""
407
bea43f99cc27 star-merged moin--refactor--1.5 (formatter, parser, converter fixes, see docs/CHANGES.refactor)
Thomas Waldmann <tw@waldmann-edv.de>
parents: 264
diff changeset
825
3196
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
826 def rawHTML(self, markup):
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
827 if markup.strip() == "":
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
828 return ""
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
829
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
830 if "<" not in markup and ">" not in markup:
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
831 # Seems there are no tags.
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
832 # Let's get all the "entity references".
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
833 cleaned = markup
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
834 import re
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
835 entities = re.compile("&(?P<e>[a-zA-Z]+);").findall(cleaned)
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
836 from htmlentitydefs import name2codepoint
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
837 for ent in entities:
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
838 if name2codepoint.has_key(ent):
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
839 cleaned = cleaned.replace("&%s;" % ent, unichr(name2codepoint[ent]))
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
840
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
841 # Then we replace all escaped unicodes.
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
842 escapedunicodes = re.compile("&#(?P<h>[0-9]+);").findall(markup)
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
843 for uni in escapedunicodes:
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
844 cleaned = cleaned.replace("&#%s;" % uni, unichr(int(uni)))
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
845
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
846 self.text(cleaned)
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
847
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
848 self._emitComment("RAW HTML: "+markup)
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
849 return ""
08c2e2727641 Add support for entity refs such as arrows as raw unicode codepoints. Uses name2codepoint from htmlentitydefs.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3195
diff changeset
850
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
851 def div(self, on, **kw):
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
852 """A div cannot really be supported in DocBook as it carries no
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
853 semantic meaning, but the special cases can be handled when the class
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
854 of the div carries the information.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
855
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
856 A dictionary is used for mapping between class names and the
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
857 corresponding DocBook element.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
858
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
859 A MoinMoin comment is represented in DocBook by the remark element.
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
860
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
861 The rest of the known classes are the admonitions in DocBook:
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
862 warning, caution, important, note and hint
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
863
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
864 Note: The remark entity can only contain inline elements, so it is
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
865 very likely that the use of a comment div will produce invalid
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
866 DocBook.
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
867 """
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
868 # Map your styles to docbook elements.
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
869 # Even though comment is right now the only one that needs to be
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
870 # mapped, having two different ways is more complicated than having
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
871 # a single common way. Code clarity and generality first, especially
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
872 # since we might want to do more div to docbook mappings in the future.
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
873 class_to_docbook = {"warning": "warning",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
874 "caution": "caution",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
875 "important": "important",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
876 "note": "note",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
877 "tip": "tip",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
878 "comment": "remark"}
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
879
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
880 if on and kw.get('css_class'):
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
881 css_classes = kw.get('css_class').split()
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
882 for style in class_to_docbook.keys():
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
883 if style in css_classes:
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
884 return self._handleNode(class_to_docbook[style], on)
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
885
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
886 elif not on:
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
887 if self.cur.nodeName in class_to_docbook.values():
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
888 return self._handleNode(self.cur.nodeName, on)
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
889
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
890 return ""
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
891
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
892 def span(self, on, **kw):
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
893 """A span cannot really be supported in DocBook as it carries no
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
894 semantic meaning, but the special case of a comment can be handled.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
895
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
896 A comment is represented in DocBook by the remark element.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
897
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
898 A comment span is recognized by the fact that it has the class
3200
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
899 "comment". Other cases of div use are ignored.
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
900 """
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
901 css_class = kw.get('css_class')
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
902 if on and css_class and 'comment' in css_class.split():
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
903 self._handleFormatting("remark", on)
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
904 if not on and self.cur.nodeName == "remark":
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
905 self._handleFormatting("remark", on)
6a83a46ccf59 Added support for the comment elements by implementing the div and span functions. The comment is mapped as the remark entity in docbook which can really only be inline, so using the div system might produce invalid docbooks.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3199
diff changeset
906 return ""
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
907
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
908
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
909
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
910 ### Tables ##########################################################
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
911
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
912 def table(self, on, attrs=(), **kw):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
913 if(on):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
914 self.curtable = Table(self, self.doc, self.cur, attrs)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
915 self.cur = self.curtable.tableNode
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
916 else:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
917 self.cur = self.curtable.finalizeTable()
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
918 self.curtable = None
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
919 return ""
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
920
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
921 def table_row(self, on, attrs=(), **kw):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
922 if(on):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
923 self.cur = self.curtable.addRow(attrs)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
924 return ""
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
925
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
926 def table_cell(self, on, attrs=(), **kw):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
927 if(on):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
928 self.cur = self.curtable.addCell(attrs)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
929 return ""
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
930
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
931 class Table:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
932 '''The Table class is used as a helper for collecting information about
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
933 what kind of table we are building. When all relelvant data is gathered
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
934 it calculates the different spans of the cells and columns.
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
935 '''
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
936
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
937 def __init__(self, formatter, doc, parent, args):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
938 self.formatter = formatter
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
939 self.doc = doc
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
940
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
941 self.tableNode = self.doc.createElement('informaltable')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
942 parent.appendChild(self.tableNode)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
943 self.colWidths = {}
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
944 self.tgroup = self.doc.createElement('tgroup')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
945 # Bug in yelp, the two lines below don't affect rendering
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
946 #self.tgroup.setAttribute('rowsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
947 #self.tgroup.setAttribute('colsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
948 self.curColumn = 0
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
949 self.maxColumn = 0
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
950 self.row = None
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
951 self.tableNode.appendChild(self.tgroup)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
952
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
953 self.tbody = self.doc.createElement('tbody') # Note: This gets appended in finalizeTable
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
954
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
955 def finalizeTable(self):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
956 """Calculates the final width of the whole table and the width of each
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
957 column. Adds the colspec-elements and applies the colwidth attributes.
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
958 Inserts the tbody element to the tgroup and returns the tables container
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
959 element.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
960
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
961 A lot of the information is gathered from the style attributes passed
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
962 to the functions
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
963 """
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
964 self.tgroup.setAttribute('cols', str(self.maxColumn))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
965 for colnr in range(0, self.maxColumn):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
966 colspecElem = self.doc.createElement('colspec')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
967 colspecElem.setAttribute('colname', 'col_%s' % str(colnr))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
968 if self.colWidths.has_key(str(colnr)) and self.colWidths[str(colnr)] != "1*":
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
969 colspecElem.setAttribute('colwidth', self.colWidths[str(colnr)])
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
970 self.tgroup.appendChild(colspecElem)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
971 self.tgroup.appendChild(self.tbody)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
972 return self.tableNode.parentNode
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
973
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
974 def addRow(self, args):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
975 self.curColumn = 0
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
976 self.row = self.doc.createElement('row')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
977 # Bug in yelp, doesn't affect the outcome.
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
978 #self.row.setAttribute("rowsep", "1") #Rows should have lines between them
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
979 self.tbody.appendChild(self.row)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
980 return self.row
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
981
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
982 def addCell(self, args):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
983 cell = self.doc.createElement('entry')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
984 cell.setAttribute('rowsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
985 cell.setAttribute('colsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
986
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
987 self.row.appendChild(cell)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
988
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
989 args = self._convertStyleAttributes(args)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
990 self._handleSimpleCellAttributes(cell, args)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
991 self._handleColWidth(args)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
992 self.curColumn += self._handleColSpan(cell, args)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
993
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
994 self.maxColumn = max(self.curColumn, self.maxColumn)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
995
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
996 return cell
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
997
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
998 def _handleColWidth(self, args):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
999 if not args.has_key("width"):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1000 return
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1001 args["width"] = args["width"].strip('"')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1002 if not args["width"].endswith("%"):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1003 self.formatter._emitComment("Width %s not supported" % args["width"])
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1004 return
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1005
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1006 self.colWidths[str(self.curColumn)] = args["width"][:-1] + "*"
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1007
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1008 def _handleColSpan(self, element, args):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1009 """Returns the number of colums this entry spans"""
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1010 if not args or not args.has_key('colspan'):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1011 return 1
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1012 assert(element.nodeName == "entry")
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1013 extracols = int(args['colspan'].strip('"')) - 1
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1014 element.setAttribute('namest', "col_" + str(self.curColumn))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1015 element.setAttribute('nameend', "col_" + str(self.curColumn + extracols))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1016 return 1 + extracols
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1017
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1018 def _handleSimpleCellAttributes(self, element, args):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1019 safe_values_for = {'valign': ('top', 'middle', 'bottom'),
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1020 'align': ('left', 'center', 'right'),
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1021 }
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1022 if not args:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1023 return
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1024 assert(element.nodeName == "entry")
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1025
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1026 if args.has_key('rowspan'):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1027 extrarows = int(args['rowspan'].strip('"')) - 1
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1028 element.setAttribute('morerows', str(extrarows))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1029
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1030 if args.has_key('align'):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1031 value = args['align'].strip('"')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1032 if value in safe_values_for['align']:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1033 element.setAttribute('align', value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1034 else:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1035 self.formatter._emitComment("Alignment %s not supported" % value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1036 pass
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1037
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1038 if args.has_key('valign'):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1039 value = args['valign'].strip('"')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1040 if value in safe_values_for['valign']:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1041 element.setAttribute('valign', value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1042 else:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1043 self.formatter._emitComment("Vertical alignment %s not supported" % value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1044 pass
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1045
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1046 def _convertStyleAttributes(self, argslist):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1047 if not argslist.has_key('style'):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1048 return argslist
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1049 styles = self.formatter._convertStylesToDict(argslist['style'].strip('"'))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1050 argslist.update(styles)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1051
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1052 return argslist
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
1053