"Fossies" - the Fresh Open Source Software Archive 
Member "Tahchee-1.0.0/Sources/tahchee/plugins/_kiwi/kiwi2twiki.py" (22 Oct 2009, 5057 Bytes) of package /linux/privat/old/tahchee-1.0.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style:
standard) with prefixed line numbers.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "kiwi2twiki.py" see the
Fossies "Dox" file reference documentation.
1 #!/usr/bin/env python
2 # Encoding: iso-8859-1
3 # vim: tw=80 ts=4 sw=4 noet
4 # -----------------------------------------------------------------------------
5 # Project : Kiwi
6 # -----------------------------------------------------------------------------
7 # Author : Sebastien Pierre <sebastien@type-z.org>
8 # -----------------------------------------------------------------------------
9 # Creation date : 19-Nov-2007
10 # Last mod. : 19-Nov-2007
11 # -----------------------------------------------------------------------------
12
13 import re, xml.dom
14 import sys
15 from formatting import *
16 import templates
17
18 #------------------------------------------------------------------------------
19 #
20 # Actual element processing
21 #
22 #------------------------------------------------------------------------------
23
24 def convertDocument(element):
25 return process(element, """\
26 $(Header:title)
27 $(Content)
28 $(References)
29 """)
30
31 def convertHeader( element ):
32 return process(element, "---+ $(Title/title)\n---++ $(Title/subtitle)\n" )
33
34 def convertHeading( element ):
35 return process(element, "$(*)")
36
37 def convertSection( element ):
38 level = int(element.getAttributeNS(None, "_depth"))
39 prefix = "---+" + "+" * level
40 return process(element,
41 prefix + " $(Heading)\n\n"
42 + "$(Content:section)"
43 )
44
45 def convertReferences( element ):
46 return process(element, """ $(Entry)""")
47
48 def convertParagraph( element ):
49 return process(element, """$(*)\n\n""")
50
51 def convertParagraph_cell( element ):
52 return process(element, """$(*)\n""")
53
54 def convertList( element ):
55 is_todo = element.getAttributeNS(None, "type")
56 attrs = [""]
57 return process(element, """$(*)\n\n""")
58
59 def convertListItem( element ):
60 attrs = [""]
61 is_todo = element.getAttributeNS(None, "todo")
62 return process(element, """ * $(*)\n""")
63
64 def convertTable( element ):
65 return process(element, """$(Content:table)\n\n""")
66
67 def convertDefinition( element ):
68 return process(element, """$(*)\n\n""")
69
70 def convertDefinitionItem( element ):
71 return process(element, """ $ $(Title) : $(Content)\n""")
72
73 def convertRow( element ):
74 try: index = element.parentNode.childNodes.index(element) % 2 + 1
75 except: index = 0
76 classes = ( "", "even", "odd" )
77 return process(element, """$(*) |\n""")
78
79 def convertCell( element ):
80 suffix = ""
81 if element.hasAttributeNS(None, "colspan"):
82 suffix = " " + "|" * (int(element.getAttributeNS(None,"colspan")) - 2)
83 cell = process(element, "$(*:cell)")[:-1]
84 return ("| " + cell + suffix)
85
86 def convertBlock( element ):
87 title = element.getAttributeNS(None,"title") or element.getAttributeNS(None, "type") or ""
88 css_class = ""
89 if title:
90 css_class=" class='ann%s'" % (element.getAttributeNS(None, "type").capitalize())
91 title = "<div class='title'>%s</div>" % (title)
92 div_type = "div"
93 elif not element.getAttributeNS(None, "type"):
94 div_type = "blockquote"
95 return process(element, """<%s%s>%s<div class='content'%s>$(*)</div></%s>""" % (div_type, css_class, title, "", div_type))
96
97 def stringToTarget( text ):
98 return text.replace(" ", " ").strip().replace(" ", "-").upper()
99
100 def convertlink( element ):
101 if element.getAttributeNS(None, "type") == "ref":
102 return process(element, """[[#%s][$(*)]]""" %
103 (stringToTarget(element.getAttributeNS(None, "target"))))
104 else:
105 # TODO: Support title
106 return process(element, """[[%s][$(*)]]""" %
107 (element.getAttributeNS(None, "target")))
108
109 def converttarget( element ):
110 name = element.getAttributeNS(None, "name")
111 return process(element, """#%s $(*)""" % (stringToTarget(name)))
112
113
114 def convertemail( element ):
115 mail = ""
116 for c in process(element, """$(*)"""):
117 mail += c
118 return """[[mailto:%s][%s]]""" % (mail, mail)
119
120 def converturl( element ):
121 return process(element, """[[$(*)][(*)]]""")
122
123 def convertterm( element ):
124 return process(element, """*$(*)*""")
125
126 def convertquote( element ):
127 return process(element, """''_$(*)_''""")
128
129 def convertstrong( element ):
130 return process(element, """__$(*)__""")
131
132 def convertpre( element ):
133 return process(element, """<verbatim>\n$(*)\n</verbatim>\n\n""")
134
135 def convertcode( element ):
136 return process(element, """=$(*)=""")
137
138 def convertemphasis( element ):
139 return process(element, """_$(*)_""")
140
141 def convertbreak( element ):
142 return process(element, """ """)
143
144 def convertnewline( element ):
145 return process(element, """ """)
146
147 def convertarrow( element ):
148 arrow = element.getAttributeNS(None, "type")
149 if arrow == "left":
150 return "<--"
151 elif arrow == "right":
152 return "-->"
153 else:
154 return "<-->"
155
156 def convertdots( element ):
157 return "..."
158
159 def convertendash( element ):
160 return " -- "
161
162 def convertemdash( element ):
163 return " -- "
164
165 def convertentity( element ):
166 return "&%s;" % (element.getAttributeNS( None, "num"))
167
168 # We create the processor, register the rules and define the process variable
169 processor = templates.Processor()
170 name2functions = {}
171 for symbol in filter(lambda x:x.startswith("convert"), dir()):
172 name2functions[symbol] = eval(symbol)
173 processor.register(name2functions)
174 process = processor.process
175
176 # EOF