]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/stxview/StructuredText/HTMLClass.py
1 ##############################################################################
3 # Zope Public License (ZPL) Version 1.0
4 # -------------------------------------
6 # Copyright (c) Digital Creations. All rights reserved.
8 # This license has been certified as Open Source(tm).
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions are
14 # 1. Redistributions in source code must retain the above copyright
15 # notice, this list of conditions, and the following disclaimer.
17 # 2. Redistributions in binary form must reproduce the above copyright
18 # notice, this list of conditions, and the following disclaimer in
19 # the documentation and/or other materials provided with the
22 # 3. Digital Creations requests that attribution be given to Zope
23 # in any manner possible. Zope includes a "Powered by Zope"
24 # button that is installed by default. While it is not a license
25 # violation to remove this button, it is requested that the
26 # attribution remain. A significant investment has been put
27 # into Zope, and this effort will continue if the Zope community
28 # continues to grow. This is one way to assure that growth.
30 # 4. All advertising materials and documentation mentioning
31 # features derived from or use of this software must display
32 # the following acknowledgement:
34 # "This product includes software developed by Digital Creations
35 # for use in the Z Object Publishing Environment
36 # (http://www.zope.org/)."
38 # In the event that the product being advertised includes an
39 # intact Zope distribution (with copyright and license included)
40 # then this clause is waived.
42 # 5. Names associated with Zope or Digital Creations must not be used to
43 # endorse or promote products derived from this software without
44 # prior written permission from Digital Creations.
46 # 6. Modified redistributions of any form whatsoever must retain
47 # the following acknowledgment:
49 # "This product includes software developed by Digital Creations
50 # for use in the Z Object Publishing Environment
51 # (http://www.zope.org/)."
53 # Intact (re-)distributions of any official Zope release do not
54 # require an external acknowledgement.
56 # 7. Modifications are encouraged but must be packaged separately as
57 # patches to official Zope releases. Distributions that do not
58 # clearly separate the patches from the original work must be clearly
59 # labeled as unofficial distributions. Modifications which do not
60 # carry the name Zope may be packaged in any form, as long as they
61 # conform to all of the clauses above.
66 # THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
67 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
69 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
70 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
71 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
72 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
73 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
74 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
75 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
76 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80 # This software consists of contributions made by Digital Creations and
81 # many individuals on behalf of Digital Creations. Specific
82 # attributions are listed in the accompanying credits file.
84 ##############################################################################
86 from string
import join
, split
, find
93 'StructuredTextDocument': 'document',
94 'StructuredTextParagraph': 'paragraph',
95 'StructuredTextExample': 'example',
96 'StructuredTextBullet': 'bullet',
97 'StructuredTextNumbered': 'numbered',
98 'StructuredTextDescription': 'description',
99 'StructuredTextDescriptionTitle': 'descriptionTitle',
100 'StructuredTextDescriptionBody': 'descriptionBody',
101 'StructuredTextSection': 'section',
102 'StructuredTextSectionTitle': 'sectionTitle',
103 'StructuredTextLiteral': 'literal',
104 'StructuredTextEmphasis': 'emphasis',
105 'StructuredTextStrong': 'strong',
106 'StructuredTextLink': 'link',
107 'StructuredTextXref': 'xref',
108 'StructuredTextInnerLink':'innerLink',
109 'StructuredTextNamedLink':'namedLink',
110 'StructuredTextUnderline':'underline',
111 'StructuredTextTable':'table',
112 'StructuredTextSGML':'sgml',
115 def dispatch(self
, doc
, level
, output
):
116 getattr(self
, self
.element_types
[doc
.getNodeName()])(doc
, level
, output
)
118 def __call__(self
, doc
, level
=1):
120 self
.dispatch(doc
, level
-1, r
.append
)
123 def _text(self
, doc
, level
, output
):
124 output(doc
.getNodeValue())
126 def document(self
, doc
, level
, output
):
128 children
=doc
.getChildNodes()
130 children
[0].getNodeName() == 'StructuredTextSection'):
131 output('<head>\n<title>%s</title>\n</head>\n' %
132 children
[0].getChildNodes()[0].getNodeValue())
135 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
139 def section(self
, doc
, level
, output
):
140 children
=doc
.getChildNodes()
142 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
+1, output
)
144 def sectionTitle(self
, doc
, level
, output
):
145 output('<h%d>' % (level
))
146 for c
in doc
.getChildNodes():
147 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
148 output('</h%d>\n' % (level
))
150 def description(self
, doc
, level
, output
):
151 p
=doc
.getPreviousSibling()
152 if p
is None or p
.getNodeName() is not doc
.getNodeName():
154 for c
in doc
.getChildNodes():
155 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
156 n
=doc
.getNextSibling()
157 if n
is None or n
.getNodeName() is not doc
.getNodeName():
160 def descriptionTitle(self
, doc
, level
, output
):
162 for c
in doc
.getChildNodes():
163 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
166 def descriptionBody(self
, doc
, level
, output
):
168 for c
in doc
.getChildNodes():
169 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
172 def bullet(self
, doc
, level
, output
):
173 p
=doc
.getPreviousSibling()
174 if p
is None or p
.getNodeName() is not doc
.getNodeName():
177 for c
in doc
.getChildNodes():
178 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
179 n
=doc
.getNextSibling()
181 if n
is None or n
.getNodeName() is not doc
.getNodeName():
184 def numbered(self
, doc
, level
, output
):
185 p
=doc
.getPreviousSibling()
186 if p
is None or p
.getNodeName() is not doc
.getNodeName():
189 for c
in doc
.getChildNodes():
190 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
191 n
=doc
.getNextSibling()
193 if n
is None or n
.getNodeName() is not doc
.getNodeName():
196 def example(self
, doc
, level
, output
):
198 for c
in doc
.getChildNodes():
201 output(html_quote(c
.getNodeValue()))
204 getattr(self
, self
.element_types
[c
.getNodeName()])(
207 def paragraph(self
, doc
, level
, output
):
210 for c
in doc
.getChildNodes():
211 if c
.getNodeName() in ['StructuredTextParagraph']:
212 getattr(self
, self
.element_types
[c
.getNodeName()])(
215 getattr(self
, self
.element_types
[c
.getNodeName()])(
219 def link(self
, doc
, level
, output
):
220 output('<a href="%s">' % doc
.href
)
221 for c
in doc
.getChildNodes():
222 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
225 def emphasis(self
, doc
, level
, output
):
227 for c
in doc
.getChildNodes():
228 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
231 def literal(self
, doc
, level
, output
):
233 for c
in doc
.getChildNodes():
234 output(html_quote(c
.getNodeValue()))
237 def strong(self
, doc
, level
, output
):
239 for c
in doc
.getChildNodes():
240 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
243 def underline(self
, doc
, level
, output
):
245 for c
in doc
.getChildNodes():
246 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
249 def innerLink(self
, doc
, level
, output
):
250 output('<a href="#');
251 for c
in doc
.getChildNodes():
252 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
254 for c
in doc
.getChildNodes():
255 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
258 def namedLink(self
, doc
, level
, output
):
260 for c
in doc
.getChildNodes():
261 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
263 for c
in doc
.getChildNodes():
264 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
267 def sgml(self
,doc
,level
,output
):
268 for c
in doc
.getChildNodes():
269 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
271 def table(self
,doc
,level
,output
):
273 A StructuredTextTable holds StructuredTextRow(s) which
274 holds StructuredTextColumn(s). A StructuredTextColumn
275 is a type of StructuredTextParagraph and thus holds
278 output("<table border=1 cellpadding=2>\n")
279 for row
in doc
.getRows()[0]:
281 for column
in row
.getColumns()[0]:
282 str = "<td colspan=%s>" % column
.getSpan()
284 #for c in doc.getChildNodes():
285 # getattr(self, self.element_types[c.getNodeName()])(c, level, output)
286 for c
in column
.getChildNodes():
287 getattr(self
, self
.element_types
[c
.getNodeName()])(c
, level
, output
)
292 def html_quote(v
, name
='(Unknown name)', md
={},
299 (('"'), '"'))): #"
301 for re
,name
in character_entities
:
302 if find(text
, re
) >= 0: text
=join(split(text
,re
),name
)