]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/stxview/StructuredText/Zwiki.py
2 ##############################################################################
4 # Zope Public License (ZPL) Version 1.0
5 # -------------------------------------
7 # Copyright (c) Digital Creations. All rights reserved.
9 # This license has been certified as Open Source(tm).
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are
15 # 1. Redistributions in source code must retain the above copyright
16 # notice, this list of conditions, and the following disclaimer.
18 # 2. Redistributions in binary form must reproduce the above copyright
19 # notice, this list of conditions, and the following disclaimer in
20 # the documentation and/or other materials provided with the
23 # 3. Digital Creations requests that attribution be given to Zope
24 # in any manner possible. Zope includes a "Powered by Zope"
25 # button that is installed by default. While it is not a license
26 # violation to remove this button, it is requested that the
27 # attribution remain. A significant investment has been put
28 # into Zope, and this effort will continue if the Zope community
29 # continues to grow. This is one way to assure that growth.
31 # 4. All advertising materials and documentation mentioning
32 # features derived from or use of this software must display
33 # the following acknowledgement:
35 # "This product includes software developed by Digital Creations
36 # for use in the Z Object Publishing Environment
37 # (http://www.zope.org/)."
39 # In the event that the product being advertised includes an
40 # intact Zope distribution (with copyright and license included)
41 # then this clause is waived.
43 # 5. Names associated with Zope or Digital Creations must not be used to
44 # endorse or promote products derived from this software without
45 # prior written permission from Digital Creations.
47 # 6. Modified redistributions of any form whatsoever must retain
48 # the following acknowledgment:
50 # "This product includes software developed by Digital Creations
51 # for use in the Z Object Publishing Environment
52 # (http://www.zope.org/)."
54 # Intact (re-)distributions of any official Zope release do not
55 # require an external acknowledgement.
57 # 7. Modifications are encouraged but must be packaged separately as
58 # patches to official Zope releases. Distributions that do not
59 # clearly separate the patches from the original work must be clearly
60 # labeled as unofficial distributions. Modifications which do not
61 # carry the name Zope may be packaged in any form, as long as they
62 # conform to all of the clauses above.
67 # THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
68 # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
69 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
70 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
71 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
72 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
73 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
74 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
75 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
76 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
77 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
81 # This software consists of contributions made by Digital Creations and
82 # many individuals on behalf of Digital Creations. Specific
83 # attributions are listed in the accompanying credits file.
85 ##############################################################################
88 from string
import split
93 This is the new structured text type.
97 def __init__(self
,str=''):
98 self
.expr1
= re
.compile('([A-Z]+[A-Z]+[a-zA-Z]*)').search
99 self
.expr2
= re
.compile('([A-Z]+[a-z]+[A-Z]+[a-zA-Z]*)').search
101 self
.typ
= "Zwiki_Title"
104 return '%s' % self
.typ
109 def __getitem__(self
,index
):
110 return self
.str[index
]
112 def __call__(self
,raw_string
,subs
):
115 The raw_string is checked to see if it matches the rules
116 for this structured text expression. If the raw_string does,
117 it is parsed for the sub-string which matches and a doc_inner_link
118 instance is returned whose string is the matching substring.
119 If raw_string does not match, nothing is returned.
122 if self
.expr1(raw_string
):
123 start
,end
= self
.expr1(raw_string
).span()
124 result
= Zwiki_Title(raw_string
[start
:end
])
125 result
.start
,result
.end
= self
.expr1(raw_string
).span()
127 elif self
.expr2(raw_string
):
128 start
,end
= self
.expr2(raw_string
).span()
129 result
= Zwiki_Title(raw_string
[start
:end
])
130 result
.start
,result
.end
= self
.expr2(raw_string
).span()
136 return self
.start
,self
.end
138 class Zwiki_doc(DOC
):
143 Add the new type to self.types
145 self
.types
.append(Zwiki_Title())
147 class Zwiki_parser(HTML
):
150 self
.types
["Zwiki_Title"] = self
.zwiki_title
152 def zwiki_title(self
,object):
154 for x
in object.string():
156 result
= "<a href=%s>%s</a>" % (result
,result
)
157 #result = "<dtml-wikiname %s>" % result
158 self
.string
= self
.string
+ result