comparison MoinMoin/script/migration/_conv160_wiki.py @ 2603:c61c10e3fcde

1.6 converter: improve content conversion, more tests
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 05 Aug 2007 00:05:34 +0200
parents b601db2e4d34
children 27f06531a91b
comparison
equal deleted inserted replaced
2602:b601db2e4d34 2603:c61c10e3fcde
76 _ent_numeric_repl = return_word 76 _ent_numeric_repl = return_word
77 _ent_symbolic_repl = return_word 77 _ent_symbolic_repl = return_word
78 _heading_repl = return_word 78 _heading_repl = return_word
79 _email_repl = return_word 79 _email_repl = return_word
80 _macro_repl = return_word 80 _macro_repl = return_word
81 _interwiki_repl = return_word
82 _word_repl = return_word 81 _word_repl = return_word
83 _indent_repl = return_word 82 _indent_repl = return_word
84 _li_none_repl = return_word 83 _li_none_repl = return_word
85 _li_repl = return_word 84 _li_repl = return_word
86 _ol_repl = return_word 85 _ol_repl = return_word
123 122
124 def interwiki(self, target_and_text, **kw): 123 def interwiki(self, target_and_text, **kw):
125 # TODO: maybe support [wiki:Page http://wherever/image.png] ? 124 # TODO: maybe support [wiki:Page http://wherever/image.png] ?
126 scheme, rest = target_and_text.split(':', 1) 125 scheme, rest = target_and_text.split(':', 1)
127 wikiname, pagename, text = wikiutil.split_wiki(rest) 126 wikiname, pagename, text = wikiutil.split_wiki(rest)
128 if not text:
129 text = pagename
130 #self.request.log("interwiki: split_wiki -> %s.%s.%s" % (wikiname,pagename,text)) 127 #self.request.log("interwiki: split_wiki -> %s.%s.%s" % (wikiname,pagename,text))
131 128
132 if wikiname.lower() == 'self': # [wiki:Self:LocalPage text] or [:LocalPage:text] 129 if wikiname.lower() == 'self': # [wiki:Self:LocalPage text] or [:LocalPage:text]
133 return '[%s %s]' % (wikiutil.quoteName(pagename), text) # ["LocalPage" text] 130 pagename = self._replace(('PAGE', pagename))
131 if not text:
132 return '[%s]' % wikiutil.quoteName(pagename) # ["LocalPage"]
133 else:
134 return '[%s %s]' % (wikiutil.quoteName(pagename), text) # ["LocalPage" text]
134 135
135 # check for image URL, and possibly return IMG tag 136 # check for image URL, and possibly return IMG tag
136 if not kw.get('pretty_url', 0) and wikiutil.isPicture(pagename): 137 if not kw.get('pretty_url', 0) and wikiutil.isPicture(pagename):
137 dummy, wikiurl, dummy, wikitag_bad = wikiutil.resolve_wiki(self.request, rest) 138 dummy, wikiurl, dummy, wikitag_bad = wikiutil.resolve_wiki(self.request, rest)
138 href = wikiutil.join_wiki(wikiurl, pagename) 139 href = wikiutil.join_wiki(wikiurl, pagename)
164 165
165 if text: 166 if text:
166 text = ' ' + text 167 text = ' ' + text
167 return "%s:%s%s" % (scheme, qname, text) 168 return "%s:%s%s" % (scheme, qname, text)
168 169
170 def _interwiki_repl(self, word):
171 """Handle InterWiki links."""
172 # XXX if we have access to the cfg, we can limit this to really existings interwiki identifiers
173 return self.interwiki("wiki:" + word)
174
169 def _url_repl(self, word): 175 def _url_repl(self, word):
170 """Handle literal URLs including inline images.""" 176 """Handle literal URLs including inline images."""
171 scheme = word.split(":", 1)[0] 177 scheme = word.split(":", 1)[0]
172 178
173 if scheme == "wiki": 179 if scheme == "wiki":
174 return word # self.interwiki(word) 180 return self.interwiki(word)
175 181
176 if scheme in self.attachment_schemas: 182 if scheme in self.attachment_schemas:
177 return self.attachment(word) 183 return self.attachment(word)
178 184
179 if wikiutil.isPicture(word): 185 if wikiutil.isPicture(word):
223 link = wikiutil.quoteName(link) 229 link = wikiutil.quoteName(link)
224 if text: 230 if text:
225 text = ' ' + text 231 text = ' ' + text
226 return '[%s%s]' % (link, text) # use freelink with text 232 return '[%s%s]' % (link, text) # use freelink with text
227 233
228 return '[%s]' % word 234 scheme_and_rest = word.split(":", 1)
229 235 if len(scheme_and_rest) == 2: # scheme given
236 scheme, rest = scheme_and_rest
237 if scheme == "wiki":
238 return self.interwiki(word, pretty_url=1)
239 if scheme in self.attachment_schemas:
240 return self.attachment(word, pretty_url=1)
241
242 words = word.split(None, 1)
243 if len(words) == 1:
244 link, text = words[0], ''
245 else:
246 link, text = words
247 if text:
248 text = ' ' + text
249 return '[%s%s]' % (link, text)
230 250
231 # SCANNING --------------------------------------------------------------- 251 # SCANNING ---------------------------------------------------------------
232 def scan(self, scan_re, line): 252 def scan(self, scan_re, line):
233 """ Scans one line 253 """ Scans one line
234 254