annotate MoinMoin/formatter/text_docbook.py @ 5640:3cb7a64eaef5

fix pep8 failures
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 02 Apr 2010 19:54:22 +0200
parents 689e2b04bd4d
children cabef5f26ec5
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
5640
3cb7a64eaef5 fix pep8 failures
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5639
diff changeset
12 import os, re
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
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
23 #For revision history
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
24 from MoinMoin.logfile import editlog
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
25 from MoinMoin import user
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
26
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
27
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
28 class InternalError(CompositeError):
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
29 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
30
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
31 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
32 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
33 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
34 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
35
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
36
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 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
38 #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
39 # 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
40 # 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
41
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
42 # 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
43 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
44
3248
2ea14aac1a35 Blacklist navigation macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3247
diff changeset
45 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
46
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
47 # 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
48 # 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
49 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
50
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
51 # 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
52 _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
53
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
54 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
55 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
56 self.request = request
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
57
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
58 '''
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
59 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
60 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
61 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
62 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
63 work properly unless they are called.
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
64 '''
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
65 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
66 self.include_kludge = True
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
67 else:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
68 self.include_kludge = False
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
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 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
71 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
72 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
73
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 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
75 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
76 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
77 "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
78
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
79 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
80 self.root = self.doc.documentElement
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
81
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
82 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
83 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
84 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
85 self._addTitleElement(self.title, targetNode=info)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
86 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
87 else:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
88 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
89
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
90 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
91 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
92
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
93 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
94 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
95 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
96 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
97
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 def endContent(self):
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
99 if self.include_kludge:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
100 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
101 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
102
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
103 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
104 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
105 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
106
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 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
108 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
109 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
110 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
111
952f8f1268c5 - Remove dummy formatter which did a lot of stuff to output text, instead
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3158
diff changeset
112 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
113 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
114
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
115 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
116 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
117 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
118 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
119 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
120
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 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
122
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 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
124 # 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
125 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
126 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
127 # 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
128 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
129
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
130 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
131 """
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 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
133 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
134 """
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 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
136 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
137 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
138 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
139 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
140 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
141 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
142 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
143 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
144
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 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
146 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
147 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
148
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
149 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
150 # 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
151 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
152 # 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
153 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
154 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
155 # 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
156 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
157 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
158
3191
a4cfe360dd33 Removed cruft from section handling and made it cover more possible cases
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3190
diff changeset
159 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
160 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
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 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
163 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
164 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
165
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 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
167 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
168 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
169 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
170 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
171 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
172
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
173 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
174
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
175 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
176 FormatterBase.paragraph(self, on)
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
177
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
178 # 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
179 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
180 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
181 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
182 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
183 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
184 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
185
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
186 # Let's prevent para inside para
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
187 if on and self.cur.nodeName == "para":
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
188 return ""
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
189 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
190
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
191 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
192 """
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
193 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
194 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
195 """
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
196 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205
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 ### 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
207
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
208 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
209 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
210
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
211 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
212 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
213
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
214 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
215 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
216
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
217 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
218 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
219
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
220 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
221 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
222
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
223 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
224 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
225
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
226 def strike(self, on, **kw):
264
67e1f1d49a97 Fixed XML formatters.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 217
diff changeset
227 # does not yield <strike> using the HTML XSLT files here ...
67e1f1d49a97 Fixed XML formatters.
Alexander Schremmer <alex@alexanderweb.de.tla>
parents: 217
diff changeset
228 # 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
229 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
230 (('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
231
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
232 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
233 # 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
234 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
235 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
236 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
237 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
238 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
239 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
240 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
241
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
242 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
243 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
244
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
245
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
246 ### 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
247
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
248 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
249 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
250 '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
251 '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
252 '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
253 '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
254
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 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
256 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
257 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
258 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
259
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 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
261
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
262 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
263 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
264
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
265 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
266 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
267 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
268 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
269 """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
270 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
271 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
272
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 = []
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 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
275 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
276 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
277 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
278
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
279 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
280
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
281 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
282 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
283
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
284 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
285 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
286 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
287 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
288 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
289 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
290 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
291 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
292 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
293 # 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
294 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
295 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
296 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
297 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
298 return ""
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
299
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
300 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
301 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
302 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
303 # 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
304 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
305 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
306
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
307 # 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
308 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
309 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
310 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
311 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
312 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
313 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
314
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 # 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
316 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
317 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
318 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
319 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
320 # 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
321 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
322 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
323 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
324 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
325
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
326 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
327 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
328 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
329
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
330 ### 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
331 # 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
332 # 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
333 # 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
334 # 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
335 # - 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
336 # - 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
337 # - 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
338 # 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
339 # element.
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
340 # 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
341 # 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
342 # 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
343
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 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
346 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
347 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
348
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
349 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
350 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
351 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
352
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
353 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
354 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
355 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
356 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
357 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
358
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
359 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
360 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
361
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
362 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
363
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
364 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
365 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
366 # convert to absolute path:
4229
c60dee8f45be Fixed docbook rendering (and obviously several other problems that didn't show in tests)
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 3291
diff changeset
367 url = "%s%s"%(self.request.base_url, url)
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
368
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
369 if not on:
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
370 self._cleanupUlinkNode()
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
371
3247
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
372 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
373 #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
374 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
375 else:
c715d62efc50 Anchor links within a page and within the wiki were not handled.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3245
diff changeset
376 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
377
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 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
379 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
380 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
381 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
382
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
383 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
384 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
385 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
386 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
387 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
388 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
389 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
390 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
391 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
392
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
393 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
394
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
395 ### 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
396
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
397 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
398 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
399 # 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
400 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
401 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
402 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
403 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
404 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
405 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
406 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
407
7c5bba88937b attachment methods for the text_xml and xml_docbook formatters
Florian Festi <Florian.Festi@trick.informatik.uni-stuttgart.de>
parents: 159
diff changeset
408 def attachment_image(self, url, **kw):
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
409 """
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
410 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
411 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
412 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
413 use the suggestion if no other text alternative is found.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
414
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
415 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
416 """
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
417 _ = 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
418 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
419 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
420 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
421 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
422 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
423 else:
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
424 return self.image(
5098
ff588e9e24d6 simplify getAttachUrl: remove upload parameter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 4334
diff changeset
425 src=AttachFile.getAttachUrl(pagename, filename, self.request, addts=1),
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
426 attachment_title=url,
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
427 **kw)
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
428
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
429
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 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
431 _ = 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
432 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
433 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
434 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
435 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
436 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
437 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
438 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
439 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
440 else:
3158
3ea8d2e4af32 minor whitespace fix
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3150
diff changeset
441 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
442 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
443
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
444 ### 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
445
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
446 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
447 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
448 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
449 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
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 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
452 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
453
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
454 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
455 if kw.has_key('src'):
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
456 src = kw['src']
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
457 if src.startswith("/"):
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
458 # convert to absolute path:
4334
7add275cf4de Fixed: deprecated (and missing) getBaseURL() method
Florian Krupicka <florian.krupicka@googlemail.com>
parents: 4229
diff changeset
459 src = self.request.url_root + src
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
460 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
461 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
462 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
463 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
464 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
465 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
466
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
467 # 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
468 title = ''
3201
e26c52c2ef0b Image handling fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3200
diff changeset
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 media.appendChild(txtcontainer)
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
477
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
478 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
479 return ""
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
480
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 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
482 # 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
483 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
484 return ""
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
485
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
486 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
487 # 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
488 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
489 return ""
ddb2d19684d7 add transclusion / transclusion_param formatter methods (for html: <object> / <param>)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2701
diff changeset
490
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
491 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
492 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
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 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
495 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
496
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
497
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
498 ### 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
499
5284
a83a65fcbb69 bug fix for MoinMoinBugs/LineNumbersWorkingBuggyWithHighlightParser (thanks to Eugene Syromyatnikov for the patch)
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5098
diff changeset
500 def code_area(self, on, code_id, code_type=None, show=0, start=-1, step=-1, msg=None):
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
501 """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
502 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
503
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
504 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
505 there to remain compatible with the HTML formatter's function.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
506
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
507 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
508 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
509
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
510 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
511 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
512 """
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
513
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
514 if not on:
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
515 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
516
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
517 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
518 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
519 start = 1
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
520
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
521 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
522 "ColorizedPython": "python",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
523 "ColorizedCPlusPlus": "c++",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
524 "ColorizedPascal": "pascal",
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
525 }
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
526
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
527 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
528 attrs = (('linenumbering', show),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
529 ('startinglinenumber', str(start)),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
530 ('format', 'linespecific'),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
531 )
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
532 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
533 else:
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
534 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
535 code_type = programming_languages[code_type]
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
536
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
537 attrs = (('linenumbering', show),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
538 ('startinglinenumber', str(start)),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
539 ('language', code_type),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
540 ('format', 'linespecific'),
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
541 )
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
542 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
543
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
544 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
545 if on:
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
546 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
547 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
548
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
549 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
550 """
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
551 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
552 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
553 """
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
554 toks_map = {'ID': 'methodname',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
555 'Operator': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
556 'Char': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
557 'Comment': 'lineannotation',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
558 'Number': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
559 'String': 'phrase',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
560 'SPChar': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
561 'ResWord': 'token',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
562 'ConsWord': 'symbol',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
563 'Error': 'errortext',
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
564 'ResWord2': 'type',
2286
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
565 'Special': '',
01f05e74aa9c Big PEP8 and whitespace cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2274
diff changeset
566 'Preprc': '',
3194
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
567 'Text': '',
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
568 }
3e7bfe175714 Improve code areas to support line numbering and programming language
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3193
diff changeset
569 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
570 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
571 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
572 return ""
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
573 ### 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
574
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
575 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
576 """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
577 kinds of macros: Bad, Handled and Unknown.
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
578
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
579 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
580 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
581 noting that the macro is not supported.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
582
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
583 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
584 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
585 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
586 pieces of information filles in.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
587
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
588 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
589 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
590 should call formatter methods. This is unfortunately not always true,
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
591 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
592 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
593 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
594 should be fixed.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
595
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
596 """
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
597 # 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
598 # 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
599 # 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
600 excludes=("articleinfo", "title")
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
601
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
602 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
603 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
604
a36faa9f9d9f Add support for the FootNote macro by creating a DocBook-native footnote.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3185
diff changeset
605 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
606 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
607 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
608 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
609
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
610 elif name == "Include":
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
611 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
612 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
613 self.paragraph(0)
5640
3cb7a64eaef5 fix pep8 failures
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5639
diff changeset
614
5636
61d77b5506a5 Fix docbook formatter crashing, see MoinMoinPatch/IncludeMacroWithDocBookFormatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3291
diff changeset
615 # Regular Expression to match editlink arg, remove it because it causes trouble.
61d77b5506a5 Fix docbook formatter crashing, see MoinMoinPatch/IncludeMacroWithDocBookFormatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3291
diff changeset
616 _arg_editlink = r'(,\s*(?P<editlink>editlink))?'
61d77b5506a5 Fix docbook formatter crashing, see MoinMoinPatch/IncludeMacroWithDocBookFormatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3291
diff changeset
617 macro_args = re.sub(_arg_editlink, '', args)
5640
3cb7a64eaef5 fix pep8 failures
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5639
diff changeset
618
5636
61d77b5506a5 Fix docbook formatter crashing, see MoinMoinPatch/IncludeMacroWithDocBookFormatter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3291
diff changeset
619 text = FormatterBase.macro(self, macro_obj, name, macro_args)
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
620 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
621 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
622 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
623 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
624
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
625 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
626 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
627 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
628 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
629 try:
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
630 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
631 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
632 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
633 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
634
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
635 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
636
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
637 ### Util functions ##################################################
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
638
3184
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
639 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
640 if not target:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
641 target = self.cur
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
642
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
643 for node in nodes:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
644 if node.nodeName in exclude:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
645 pass
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
646 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
647 self._copyExternalNodes(node.childNodes, target=target)
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
648 self.cur = target.parentNode
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
649 else:
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
650 target.appendChild(self.doc.importNode(node, deep))
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
651
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
652 def _emitComment(self, text):
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
653 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
654 self.cur.appendChild(self.doc.createComment(text))
4c7c12b775e0 - Add support for the Include macro
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3183
diff changeset
655
3190
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
656 def _handleNode(self, name, on, attributes=()):
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
657 if on:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
658 node = self.doc.createElement(name)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
659 self.cur.appendChild(node)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
660 if len(attributes) > 0:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
661 for name, value in attributes:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
662 node.setAttribute(name, value)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
663 self.cur = node
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
664 else:
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
665 """
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
666 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
667 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
668
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
669 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
670 """
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
671 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
672 return ""
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
673
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
674 self.cur = self.cur.parentNode
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
675 return ""
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
676
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
677 def _handleFormatting(self, name, on, attributes=()):
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
678 # 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
679 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
680 self.section_should_break.append(name)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
681 return self._handleNode(name, on, attributes)
a8d2fdac4662 Reordered some functions, no changes to code
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3189
diff changeset
682
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
683 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
684 """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
685 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
686 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
687 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
688 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
689 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
690 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
691 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
692 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
693
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
694 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
695 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
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 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
698 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
699 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
700 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
701 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
702
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
703 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
704 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
705 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
706
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
707 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
708 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
709 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
710 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
711
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
712 def _convertStylesToDict(self, styles):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
713 '''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
714 attrs = {}
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
715 for s in styles.split(";"):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
716 if s.strip(' "') == "":
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
717 continue
3282
5aefbb27f8c5 clean up the css colon check to be more pythonic
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3258
diff changeset
718 if ":" not in s:
3258
1ff7cb6c381b Don't assume style attribute contains colon
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3248
diff changeset
719 continue
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
720 (key, value) = s.split(":", 1)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
721 key = key.strip(' "')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
722 value = value.strip(' "')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
723
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
724 if key == 'vertical-align':
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
725 key = 'valign'
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
726 elif key == 'text-align':
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
727 key = 'align'
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
728 elif key == 'background-color':
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
729 key = 'bgcolor'
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
730
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
731 attrs[key] = value
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
732 return attrs
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
733
3198
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
734 def _cleanupUlinkNode(self):
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
735 """
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
736 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
737 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
738 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
739 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
740 """
813972c4f43b Fixes to link handling. Simplify code area and improve documentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3196
diff changeset
741 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
742 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
743 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
744 self.cur.removeChild(self.cur.firstChild)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
745
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
746 def _addTextElem(self, target, elemName, text):
3227
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
747 """
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
748 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
749 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
750 to the element target.
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
751 """
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
752 newElement = self.doc.createElement(elemName)
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
753 newElement.appendChild(self.doc.createTextNode(text))
c545e53c1b76 Documented _addTextElem and fixed indentation
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3225
diff changeset
754 target.appendChild(newElement)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
755
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 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
758 """
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
759 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
760 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
761 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
762
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
763 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
764 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
765 page info on the wiki.
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
766
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
767 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
768 edit, then it will be the hostname/ip-address.
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
769
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
770 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
771 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
772 """
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
773 _ = self.request.getText
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
774 log = editlog.EditLog(self.request, rootpagename=self.title)
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
775 user_cache = {}
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 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
778
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
779 # 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
780 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
781 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
782 #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
783 continue
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
784 revision = self.doc.createElement("revision")
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
785
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
786 # 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
787 self._addTextElem(revision, "revnumber", line.rev.lstrip('0'))
3228
c7fabea3fb4f PEP8 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3227
diff changeset
788
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
789 # 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
790 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
791 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
792 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
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 # 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
795 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
796 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
797 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
798 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
799 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
800 else:
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
801 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
802
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
803 # 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
804 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
805 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
806 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
807 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
808 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
809 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
810 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
811 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
812
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
813 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
814
3245
630e6066c935 Don't output empty revision history
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3228
diff changeset
815 if history.firstChild:
630e6066c935 Don't output empty revision history
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3228
diff changeset
816 #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
817 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
818
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 ### 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
820
999
97ce857bdebf whitespace-only cleanup and minor style changes
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 828
diff changeset
821 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
822 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
823 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
824
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 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
826 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
827 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
828 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
829
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
830 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
831 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
832 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
833 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
834
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
835 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
836 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
837 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
838
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 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
840 # 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
841 # 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
842 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
843 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
844 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
845 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
846 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
847 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
848 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
849
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 # 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
851 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
852 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
853 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
854
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
855 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
856
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
857 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
858 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
859
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
860 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
861 """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
862 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
863 of the div carries the information.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
864
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
865 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
866 corresponding DocBook element.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
867
3206
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
868 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
869
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
870 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
871 warning, caution, important, note and hint
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
872
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
873 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
874 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
875 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
876 """
3225
76015771ce72 Support for revision history in docbookm, fix a common issue when including.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3219
diff changeset
877 # 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
878 # 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
879 # 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
880 # 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
881 # 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
882 class_to_docbook = {"warning": "warning",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
883 "caution": "caution",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
884 "important": "important",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
885 "note": "note",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
886 "tip": "tip",
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
887 "comment": "remark"}
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
888
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
889 if on and kw.get('css_class'):
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
890 css_classes = kw.get('css_class').split()
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
891 for style in class_to_docbook.keys():
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
892 if style in css_classes:
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
893 return self._handleNode(class_to_docbook[style], on)
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
894
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
895 elif not on:
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
896 if self.cur.nodeName in class_to_docbook.values():
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
897 return self._handleNode(self.cur.nodeName, on)
79cd11198076 Support for admonitions.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3204
diff changeset
898
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 return ""
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
900
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
901 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
902 """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
903 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
904
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
905 A comment is represented in DocBook by the remark element.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
906
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
907 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
908 "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
909 """
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
910 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
911 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
912 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
913 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
914 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
915 return ""
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
916
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
917
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
918
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
919 ### Tables ##########################################################
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(self, on, attrs=(), **kw):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
922 if(on):
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
923 if attrs:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
924 self.curtable = Table(self, self.doc, self.cur, dict(attrs))
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
925 else:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
926 self.curtable = Table(self, self.doc, self.cur)
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
927 self.cur = self.curtable.tableNode
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
928 else:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
929 self.cur = self.curtable.finalizeTable()
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
930 self.curtable = None
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
931 return ""
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
932
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
933 def table_row(self, on, attrs=(), **kw):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
934 if(on):
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
935 if attrs:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
936 self.curtable.addRow(dict(attrs))
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
937 else:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
938 self.cur = self.curtable.addRow()
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
939 return ""
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 def table_cell(self, on, attrs=(), **kw):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
942 if(on):
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
943 if attrs:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
944 self.cur = self.curtable.addCell(dict(attrs))
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
945 else:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
946 self.cur = self.curtable.addCell()
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
947 return ""
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
948
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
949 class Table:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
950 '''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
951 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
952 it calculates the different spans of the cells and columns.
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
953
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
954 Note that it expects all arguments to be passed in a dict.
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
955 '''
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
956
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
957 def __init__(self, formatter, doc, parent, argsdict={}):
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
958 self.formatter = formatter
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
959 self.doc = doc
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
960
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
961 self.tableNode = self.doc.createElement('informaltable')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
962 parent.appendChild(self.tableNode)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
963 self.colWidths = {}
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
964 self.tgroup = self.doc.createElement('tgroup')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
965 # 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
966 #self.tgroup.setAttribute('rowsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
967 #self.tgroup.setAttribute('colsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
968 self.curColumn = 0
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
969 self.maxColumn = 0
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
970 self.row = None
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
971 self.tableNode.appendChild(self.tgroup)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
972
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
973 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
974
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
975 def finalizeTable(self):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
976 """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
977 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
978 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
979 element.
3204
aae4a2384804 whitespace fixes
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3201
diff changeset
980
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
981 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
982 to the functions
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
983 """
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
984 self.tgroup.setAttribute('cols', str(self.maxColumn))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
985 for colnr in range(0, self.maxColumn):
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
986 colspecElem = self.doc.createElement('colspec')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
987 colspecElem.setAttribute('colname', 'col_%s' % str(colnr))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
988 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
989 colspecElem.setAttribute('colwidth', self.colWidths[str(colnr)])
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
990 self.tgroup.appendChild(colspecElem)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
991 self.tgroup.appendChild(self.tbody)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
992 return self.tableNode.parentNode
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
993
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
994 def addRow(self, argsdict={}):
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
995 self.curColumn = 0
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
996 self.row = self.doc.createElement('row')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
997 # Bug in yelp, doesn't affect the outcome.
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
998 self.row.setAttribute("rowsep", "1") #Rows should have lines between them
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
999 self.tbody.appendChild(self.row)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1000 return self.row
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1001
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1002 def addCell(self, argsdict={}):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1003 if 'style' in argsdict:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1004 argsdict.update(self.formatter._convertStylesToDict(argsdict['style'].strip('"')))
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1005
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1006 cell = self.doc.createElement('entry')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1007 cell.setAttribute('rowsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1008 cell.setAttribute('colsep', '1')
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1009
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1010 self.row.appendChild(cell)
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1011 self._handleSimpleCellAttributes(cell, argsdict)
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1012 self._handleColWidth(argsdict)
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1013 self.curColumn += self._handleColSpan(cell, argsdict)
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1014
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1015 self.maxColumn = max(self.curColumn, self.maxColumn)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1016
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1017 return cell
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1018
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1019 def _handleColWidth(self, argsdict={}):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1020 if not argsdict.has_key("width"):
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1021 return
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1022 argsdict["width"] = argsdict["width"].strip('"')
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1023 if not argsdict["width"].endswith("%"):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1024 self.formatter._emitComment("Width %s not supported" % argsdict["width"])
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1025 return
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1026
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1027 self.colWidths[str(self.curColumn)] = argsdict["width"][:-1] + "*"
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1028
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1029 def _handleColSpan(self, element, argsdict={}):
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1030 """Returns the number of colums this entry spans"""
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1031 if not argsdict or not argsdict.has_key('colspan'):
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1032 return 1
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1033 assert(element.nodeName == "entry")
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1034 extracols = int(argsdict['colspan'].strip('"')) - 1
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1035 element.setAttribute('namest', "col_" + str(self.curColumn))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1036 element.setAttribute('nameend', "col_" + str(self.curColumn + extracols))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1037 return 1 + extracols
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1038
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1039 def _handleSimpleCellAttributes(self, element, argsdict={}):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1040 if not argsdict:
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1041 return
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1042 assert(element.nodeName == "entry")
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1043
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1044 safe_values_for = {'valign': ('top', 'middle', 'bottom'),
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1045 'align': ('left', 'center', 'right'),
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1046 }
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1047
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1048 if argsdict.has_key('rowspan'):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1049 extrarows = int(argsdict['rowspan'].strip('"')) - 1
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1050 element.setAttribute('morerows', str(extrarows))
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1051
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1052 if argsdict.has_key('align'):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1053 value = argsdict['align'].strip('"')
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1054 if value in safe_values_for['align']:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1055 element.setAttribute('align', value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1056 else:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1057 self.formatter._emitComment("Alignment %s not supported" % value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1058 pass
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1059
3291
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1060 if argsdict.has_key('valign'):
954300d424eb Make the Table-helper class in DocBook formatter always expect its args in dict. Fix missing gettext for revision history.
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3282
diff changeset
1061 value = argsdict['valign'].strip('"')
3189
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1062 if value in safe_values_for['valign']:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1063 element.setAttribute('valign', value)
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1064 else:
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1065 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
1066 pass
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1067
c13eca15e247 Completely reworked table support, including:
Mikko Virkkil? <mvirkkil@cc.hut.fi>
parents: 3188
diff changeset
1068