annotate MoinMoin/script/migration/_conv160_wiki.py @ 3119:2a380f99afa8

migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 26 Feb 2008 00:19:10 +0100
parents 5dfd26496da8
children 3caaa8c74c41
rev   line source
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
3 MoinMoin - convert content in 1.5.8 wiki markup to 1.6.0 style
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
4 by using a modified 1.5.8 parser as translator.
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 Assuming we have this "renames" map:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 -------------------------------------------------------
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 'PAGE', 'some_page' -> 'some page'
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 'FILE', 'with%20blank.txt' -> 'with blank.txt'
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 Markup transformations needed:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 -------------------------------------------------------
2726
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
13 ["some_page"] -> [[some page]] # renamed
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
14 [:some_page:some text] -> [[some page|some text]]
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
15 [:page:text] -> [[page|text]]
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 (with a page not being renamed)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
2726
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
18 attachment:with%20blank.txt -> [[attachment:with blank.txt]]
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
19 attachment:some_page/with%20blank.txt -> [[attachment:some page/with blank.txt]]
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 The attachment processing should also urllib.unquote the filename (or at
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 least replace %20 by space) and put it into "quotes" if it contains spaces.
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 @copyright: 2007 MoinMoin:JohannesBerg,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 2007 MoinMoin:ThomasWaldmann
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 @license: GNU GPL, see COPYING for details.
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 """
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
28 import re
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
29
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 from MoinMoin import i18n
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
31 i18n.wikiLanguages = lambda: {}
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
32
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
33 from MoinMoin import config, wikiutil, macro
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
34 from MoinMoin.action import AttachFile
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
35 from MoinMoin.Page import Page
2761
3a6a25169f55 use rsplit for splitting off anchor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2759
diff changeset
36 from MoinMoin.support.python_compatibility import rsplit
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
37
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
38 from text_moin158_wiki import Parser
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
39
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
40 def convert_wiki(request, pagename, intext, renames):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
41 """ Convert content written in wiki markup """
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
42 noeol = False
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
43 if not intext.endswith('\r\n'):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
44 intext += '\r\n'
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
45 noeol = True
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
46 c = Converter(request, pagename, intext, renames)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
47 result = request.redirectedOutput(c.convert, request)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
48 if noeol and result.endswith('\r\n'):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
49 result = result[:-2]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
50 return result
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
51
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
3119
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
53 STONEAGE_IMAGELINK = False # True for ImageLink(target,image), False for ImageLink(image,target)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
54
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
55 # copied from moin 1.6.0 macro/ImageLink.py (to be safe in case we remove ImageLink some day)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
56 # ... and slightly modified/refactored for our needs here.
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
57 # hint: using parse_quoted_separated from wikiutil does NOT work here, because we do not have
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
58 # quoted urls when they contain a '=' char in the 1.5 data input.
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
59 def explore_args(args):
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
60 """ explore args for positional and keyword parameters """
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
61 if args:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
62 args = args.split(',')
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
63 args = [arg.strip() for arg in args]
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
64 else:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
65 args = []
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
66
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
67 kw_count = 0
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
68 kw = {} # keyword args
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
69 pp = [] # positional parameters
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
70
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
71 kwAllowed = ('width', 'height', 'alt')
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
72
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
73 for arg in args:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
74 if '=' in arg:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
75 key, value = arg.split('=', 1)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
76 key_lowerstr = str(key.lower())
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
77 # avoid that urls with "=" are interpreted as keyword
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
78 if key_lowerstr in kwAllowed:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
79 kw_count += 1
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
80 kw[key_lowerstr] = value
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
81 elif not kw_count and '://' in arg:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
82 # assuming that this is the image
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
83 pp.append(arg)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
84 else:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
85 pp.append(arg)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
86
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
87 if STONEAGE_IMAGELINK and len(pp) >= 2:
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
88 pp[0], pp[1] = pp[1], pp[0]
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
89
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
90 return pp, kw
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
91
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
92
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 class Converter(Parser):
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
94 def __init__(self, request, pagename, raw, renames):
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
95 self.pagename = pagename
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 self.raw = raw
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 self.renames = renames
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
98 self.request = request
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 self._ = None
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
100 self.in_pre = 0
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
101
3119
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
102 self.formatting_rules = self.formatting_rules % {'macronames': u'|'.join(['ImageLink', ] + macro.getNames(self.request.cfg))}
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
103
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
104 # no change
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
105 def return_word(self, word):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
106 return word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
107 _emph_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
108 _emph_ibb_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
109 _emph_ibi_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
110 _emph_ib_or_bi_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
111 _u_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
112 _strike_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
113 _sup_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
114 _sub_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
115 _small_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
116 _big_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
117 _tt_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
118 _tt_bt_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
119 _remark_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
120 _table_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
121 _tableZ_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
122 _rule_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
123 _smiley_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
124 _smileyA_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
125 _ent_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
126 _ent_numeric_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
127 _ent_symbolic_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
128 _heading_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
129 _email_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
130 _notword_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
131 _indent_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
132 _li_none_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
133 _li_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
134 _ol_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
135 _dl_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
136 _comment_repl = return_word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
137
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
138 # translate pagenames using pagename translation map
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
140 def _replace(self, key):
2611
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
141 """ replace a item_name if it is in the renames dict
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
142 key is either a 2-tuple ('PAGE', pagename)
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
143 or a 3-tuple ('FILE', pagename, filename)
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
144 """
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
145 current_page = self.pagename
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
146 item_type, page_name, file_name = (key + (None, ))[:3]
2706
d2d4e74978bd remove superfluous request parameter from AbsPageName/RelPageName
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
147 abs_page_name = wikiutil.AbsPageName(current_page, page_name)
2611
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
148 if item_type == 'PAGE':
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
149 key = (item_type, abs_page_name)
2752
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
150 new_name = self.renames.get(key)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
151 if new_name is None:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
152 # we don't have an entry in rename map - apply the same magic
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
153 # to the page name as 1.5 did (" " -> "_") and try again:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
154 abs_magic_name = abs_page_name.replace(u' ', u'_')
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
155 key = (item_type, abs_magic_name)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
156 new_name = self.renames.get(key)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
157 if new_name is None:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
158 # we didn't find it under the magic name either -
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
159 # that means we do not rename it!
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
160 new_name = page_name
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
161 if new_name != page_name and abs_page_name != page_name:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
162 # we have to fix the (absolute) new_name to be a relative name (as it was before)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
163 new_name = wikiutil.RelPageName(current_page, new_name)
2611
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
164 elif item_type == 'FILE':
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
165 key = (item_type, abs_page_name, file_name)
2752
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
166 new_name = self.renames.get(key)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
167 if new_name is None:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
168 # we don't have an entry in rename map - apply the same magic
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
169 # to the page name as 1.5 did (" " -> "_") and try again:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
170 abs_magic_name = abs_page_name.replace(u' ', u'_')
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
171 key = (item_type, abs_magic_name, file_name)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
172 new_name = self.renames.get(key)
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
173 if new_name is None:
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
174 # we didn't find it under the magic name either -
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
175 # that means we do not rename it!
7f6093028a66 1.6 converter: create complete.txt (for reference, not used yet), use 1.5 underscore magic when looking up pages in rename map
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2749
diff changeset
176 new_name = file_name
2611
7ed38f2af242 1.6 converter: add tests for sister and sub page relative links (commented as they are still failing), do converter tests in a class
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2610
diff changeset
177 return new_name
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
179 def _replace_target(self, target):
2761
3a6a25169f55 use rsplit for splitting off anchor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2759
diff changeset
180 target_and_anchor = rsplit(target, '#', 1)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
181 if len(target_and_anchor) > 1:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
182 target, anchor = target_and_anchor
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
183 target = self._replace(('PAGE', target))
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
184 return '%s#%s' % (target, anchor)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
185 else:
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
186 target = self._replace(('PAGE', target))
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187 return target
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
188
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
189 # markup conversion
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
190
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
191 def _macro_repl(self, word):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
192 # we use [[...]] for links now, macros will be <<...>>
2814
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
193 macro_rule = ur"""
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
194 \[\[
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
195 (?P<macro_name>\w+)
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
196 (\((?P<macro_args>.*?)\))?
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
197 \]\]
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
198 """
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
199 word = unicode(word) # XXX why is word not unicode before???
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
200 m = re.match(macro_rule, word, re.X|re.U)
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
201 macro_name = m.group('macro_name')
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
202 macro_args = m.group('macro_args')
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
203 if macro_name == 'ImageLink':
3119
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
204 fixed, kw = explore_args(macro_args)
3018
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
205 #print "macro_args=%r" % macro_args
3119
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
206 #print "fixed=%r, kw=%r" % (fixed, kw)
2814
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
207 image, target = (fixed + ['', ''])[:2]
3018
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
208 if image is None:
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
209 image = ''
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
210 if target is None:
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
211 target = ''
2814
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
212 if '://' not in image:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
213 # if it is not a URL, it is meant as attachment
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
214 image = u'attachment:%s' % image
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
215 if not target:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
216 target = image
2833
ea9a38d2ec09 1.6 converter: if ImageLink target is inline:..., then replace it with attachment: as we do not support inline: any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2814
diff changeset
217 elif target.startswith('inline:'):
ea9a38d2ec09 1.6 converter: if ImageLink target is inline:..., then replace it with attachment: as we do not support inline: any more
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2814
diff changeset
218 target = 'attachment:' + target[7:] # we don't support inline:
3119
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
219 elif target.startswith('wiki:'):
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
220 target = target[5:] # drop wiki:
2814
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
221 image_attrs = []
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
222 alt = kw.get('alt') or ''
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
223 width = kw.get('width')
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
224 if width is not None:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
225 image_attrs.append(u"width=%s" % width)
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
226 height = kw.get('height')
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
227 if height is not None:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
228 image_attrs.append(u"height=%s" % height)
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
229 image_attrs = u", ".join(image_attrs)
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
230 if image_attrs:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
231 image_attrs = u'|' + image_attrs
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
232 if alt or image_attrs:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
233 alt = u'|' + alt
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
234 result = u'[[%s|{{%s%s%s}}]]' % (target, image, alt, image_attrs)
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
235 else:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
236 if macro_args:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
237 macro_args = u"(%s)" % macro_args
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
238 else:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
239 macro_args = u''
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
240 result = u"<<%s%s>>" % (macro_name, macro_args)
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
241 # XXX later check whether some to be renamed pagename is used as macro param
2814
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
242 return result
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
243
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
244 def _word_repl(self, word, text=None):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
245 """Handle WikiNames."""
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
246 if not text:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
247 return word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
248 else: # internal use:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
249 return '[[%s|%s]]' % (word, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
250
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
251 def _wikiname_bracket_repl(self, word):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
252 """Handle special-char wikinames."""
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
253 pagename = word[2:-2]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
254 if pagename:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
255 pagename = self._replace(('PAGE', pagename))
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
256 return '[[%s]]' % pagename
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
257 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
258 return word
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
259
2603
c61c10e3fcde 1.6 converter: improve content conversion, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2602
diff changeset
260 def _interwiki_repl(self, word):
c61c10e3fcde 1.6 converter: improve content conversion, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2602
diff changeset
261 """Handle InterWiki links."""
2604
27f06531a91b 1.6 converter: improve content conversion, give request obj to converter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2603
diff changeset
262 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, word)
27f06531a91b 1.6 converter: improve content conversion, give request obj to converter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2603
diff changeset
263 if wikitag_bad:
27f06531a91b 1.6 converter: improve content conversion, give request obj to converter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2603
diff changeset
264 return word
27f06531a91b 1.6 converter: improve content conversion, give request obj to converter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2603
diff changeset
265 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
266 wikiname, pagename = word.split(':', 1)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
267 pagename = wikiutil.url_unquote(pagename) # maybe someone has used %20 for blanks in pagename
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
268 camelcase = wikiutil.isStrictWikiname(pagename)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
269 if wikiname in ('Self', self.request.cfg.interwikiname):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
270 pagename = self._replace(('PAGE', pagename))
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
271 if camelcase:
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
272 return '%s' % pagename # optimize special case
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
273 else:
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
274 return '[[%s]]' % pagename # optimize special case
2608
3ff3beef1edf 1.6 converter: add more tests, fixed bugs, better quoting, cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2606
diff changeset
275 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
276 if ' ' in pagename: # we could get a ' ' by urlunquoting
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
277 return '[[%s:%s]]' % (wikiname, pagename)
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
278 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
279 return '%s:%s' % (wikiname, pagename)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
280
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
281 def interwiki(self, url_and_text):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
282 if len(url_and_text) == 1:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
283 url = url_and_text[0]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
284 text = ''
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
285 else:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
286 url, text = url_and_text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
287 text = '|' + text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
288
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
289 # keep track of whether this is a self-reference, so links
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
290 # are always shown even the page doesn't exist.
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
291 scheme, url = url.split(':', 1)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
292 wikiname, pagename = wikiutil.split_wiki(url)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
293 if (url.startswith(wikiutil.CHILD_PREFIX) or # fancy link to subpage [wiki:/SubPage text]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
294 Page(self.request, url).exists()): # fancy link to local page [wiki:LocalPage text]
2742
0f16bcbc0344 1.6 converter: fix wiki:/localsubpage case
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2740
diff changeset
295 pagename = wikiutil.url_unquote(url)
0f16bcbc0344 1.6 converter: fix wiki:/localsubpage case
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2740
diff changeset
296 pagename = self._replace_target(pagename)
0f16bcbc0344 1.6 converter: fix wiki:/localsubpage case
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2740
diff changeset
297 return '[[%s%s]]' % (pagename, text)
0f16bcbc0344 1.6 converter: fix wiki:/localsubpage case
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2740
diff changeset
298 if wikiname in ('Self', self.request.cfg.interwikiname, ''): # [wiki:Self:LocalPage text] or [:LocalPage:text]
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
299 pagename = wikiutil.url_unquote(pagename)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
300 pagename = self._replace_target(pagename)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
301 return '[[%s%s]]' % (pagename, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
302
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
303 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, url)
3119
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
304 if wikitag_bad: # likely we got some /InterWiki as wikitail, we don't want that!
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
305 pagename = wikiutil.url_unquote(pagename)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
306 pagename = self._replace_target(pagename)
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
307 wikitail = pagename
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
308 else: # good
2a380f99afa8 migration scripts: copied from 1.6 as of rev 2560:e2d1e0285eda
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3018
diff changeset
309 wikitail = wikiutil.url_unquote(wikitail)
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
310
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
311 # link to self?
2759
fe6098e2a895 1.6 converter: remove unused code, generate simpler interwiki markup if possible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2752
diff changeset
312 if wikiutil.isPicture(wikitail):
fe6098e2a895 1.6 converter: remove unused code, generate simpler interwiki markup if possible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2752
diff changeset
313 return '{{%s:%s%s}}' % (wikitag, wikitail, text)
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
314 else:
2759
fe6098e2a895 1.6 converter: remove unused code, generate simpler interwiki markup if possible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2752
diff changeset
315 if ' ' not in wikitail and not text:
fe6098e2a895 1.6 converter: remove unused code, generate simpler interwiki markup if possible
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2752
diff changeset
316 return '%s:%s' % (wikitag, wikitail)
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
317 else:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
318 return '[[%s:%s%s]]' % (wikitag, wikitail, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
319
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
320 def attachment(self, url_and_text):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
321 """ This gets called on attachment URLs. """
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
322 if len(url_and_text) == 1:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
323 url = url_and_text[0]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
324 text = ''
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
325 else:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
326 url, text = url_and_text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
327 text = '|' + text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
328
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
329 scheme, fname = url.split(":", 1)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
330 #scheme, fname, text = wikiutil.split_wiki(target_and_text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
331
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
332 pagename, fname = AttachFile.absoluteName(fname, self.pagename)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
333 from_this_page = pagename == self.pagename
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
334 fname = self._replace(('FILE', pagename, fname))
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
335 fname = wikiutil.url_unquote(fname, want_unicode=True)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
336 fname = self._replace(('FILE', pagename, fname))
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
337 pagename = self._replace(('PAGE', pagename))
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
338 if from_this_page:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
339 name = fname
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
340 else:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
341 name = "%s/%s" % (pagename, fname)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
342
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
343 if scheme == 'drawing':
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
344 return "{{drawing:%s%s}}" % (name, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
345
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
346 # check for image URL, and possibly return IMG tag
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
347 # (images are always inlined, just like for other URLs)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
348 if wikiutil.isPicture(name):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
349 return "{{attachment:%s%s}}" % (name, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
350
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
351 # inline the attachment
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
352 if scheme == 'inline':
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
353 return '{{attachment:%s%s}}' % (name, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
354 else: # 'attachment'
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
355 return '[[attachment:%s%s]]' % (name, text)
2603
c61c10e3fcde 1.6 converter: improve content conversion, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2602
diff changeset
356
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
357 def _url_repl(self, word):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
358 """Handle literal URLs including inline images."""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
359 scheme = word.split(":", 1)[0]
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
360
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
361 if scheme == 'wiki':
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
362 return self.interwiki([word])
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
363 if scheme in self.attachment_schemas:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
364 return '%s' % self.attachment([word])
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
365
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
366 if wikiutil.isPicture(word): # magic will go away in 1.6!
2740
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
367 return '{{%s}}' % word # new markup for inline images
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
368 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
369 return word
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
370
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
371 def _url_bracket_repl(self, word):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
372 """Handle bracketed URLs."""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
373 word = word[1:-1] # strip brackets
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
374
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
375 # Local extended link?
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
376 if word[0] == ':':
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
377 words = word[1:].split(':', 1)
2612
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
378 link, text = (words + ['', ''])[:2]
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
379 if link.strip() == text.strip():
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
380 text = ''
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
381 link = self._replace_target(link)
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
382 if text:
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
383 text = '|' + text
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
384 return '[[%s%s]]' % (link, text)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
385
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
386 # Traditional split on space
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
387 words = word.split(None, 1)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
388 if words[0][0] == '#':
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
389 # anchor link
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
390 link, text = (words + ['', ''])[:2]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
391 if link.strip() == text.strip():
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
392 text = ''
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
393 #link = self._replace_target(link)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
394 if text:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
395 text = '|' + text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
396 return '[[%s%s]]' % (link, text)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
397
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
398 scheme = words[0].split(":", 1)[0]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
399 if scheme == "wiki":
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
400 return self.interwiki(words)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
401 #scheme, wikiname, pagename, text = self.interwiki(word)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
402 #print "%r %r %r %r" % (scheme, wikiname, pagename, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
403 #if wikiname in ('Self', self.request.cfg.interwikiname, ''):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
404 # if text:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
405 # text = '|' + text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
406 # return '[[%s%s]]' % (pagename, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
407 #else:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
408 # if text:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
409 # text = '|' + text
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
410 # return "[[%s:%s%s]]" % (wikiname, pagename, text)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
411 if scheme in self.attachment_schemas:
2740
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
412 m = self.attachment(words)
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
413 if m.startswith('{{') and m.endswith('}}'):
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
414 # with url_bracket markup, 1.5.8 parser does not embed, but link!
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
415 m = '[[%s]]' % m[2:-2]
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
416 return m
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
417
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
418 target, desc = (words + ['', ''])[:2]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
419 if wikiutil.isPicture(desc) and re.match(self.url_rule, desc):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
420 #return '[[%s|{{%s|%s}}]]' % (words[0], words[1], words[0])
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
421 return '[[%s|{{%s}}]]' % (target, desc)
2603
c61c10e3fcde 1.6 converter: improve content conversion, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2602
diff changeset
422 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
423 if desc:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
424 desc = '|' + desc
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
425 return '[[%s%s]]' % (target, desc)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
426
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
427 def _pre_repl(self, word):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
428 w = word.strip()
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
429 if w == '{{{' and not self.in_pre:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
430 self.in_pre = True
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
431 elif w == '}}}' and self.in_pre:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
432 self.in_pre = False
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
433 return word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
434
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
435 def _processor_repl(self, word):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
436 self.in_pre = True
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
437 return word
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
438
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
439 def scan(self, scan_re, line):
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
440 """ Scans one line - append text before match, invoke replace() with match, and add text after match. """
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
441 result = []
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
442 lastpos = 0
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
443
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
444 for match in scan_re.finditer(line):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
445 # Add text before the match
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446 if lastpos < match.start():
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
447 result.append(line[lastpos:match.start()])
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
448 # Replace match with markup
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
449 result.append(self.replace(match))
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
450 lastpos = match.end()
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
451
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
452 # Add remainder of the line
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453 result.append(line[lastpos:])
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
454 return u''.join(result)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
455
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
456
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
457 def replace(self, match):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
458 """ Replace match using type name """
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
459 result = []
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
460 for _type, hit in match.groupdict().items():
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
461 if hit is not None and not _type in ["hmarker", ]:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
462 # Get replace method and replace hit
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
463 replace = getattr(self, '_' + _type + '_repl')
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
464 # print _type, hit
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
465 result.append(replace(hit))
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
466 return ''.join(result)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
467 else:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
468 # We should never get here
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
469 import pprint
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
470 raise Exception("Can't handle match %r\n%s\n%s" % (
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
471 match,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
472 pprint.pformat(match.groupdict()),
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473 pprint.pformat(match.groups()),
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
474 ))
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
475
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476 return ""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
477
2604
27f06531a91b 1.6 converter: improve content conversion, give request obj to converter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2603
diff changeset
478 def convert(self, request):
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
479 """ For each line, scan through looking for magic
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
480 strings, outputting verbatim any intervening text.
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
481 """
2604
27f06531a91b 1.6 converter: improve content conversion, give request obj to converter
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2603
diff changeset
482 self.request = request
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
483 # prepare regex patterns
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
484 rules = self.formatting_rules.replace('\n', '|')
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
485 if self.request.cfg.bang_meta:
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
486 rules = ur'(?P<notword>!%(word_rule)s)|%(rules)s' % {
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
487 'word_rule': self.word_rule,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
488 'rules': rules,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
489 }
2749
ef2268e5f605 1.6 converter: fix pre scan rules
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2747
diff changeset
490 pre_rules = r'''(?P<pre>\}\}\})'''
ef2268e5f605 1.6 converter: fix pre scan rules
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2747
diff changeset
491 pre_scan_re = re.compile(pre_rules, re.UNICODE)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
492 scan_re = re.compile(rules, re.UNICODE)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
493 eol_re = re.compile(r'\r?\n', re.UNICODE)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495 rawtext = self.raw
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
496
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
497 # remove last item because it's guaranteed to be empty
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
498 self.lines = eol_re.split(rawtext)[:-1]
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
499 self.in_processing_instructions = True
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
500
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
501 # Main loop
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
502 for line in self.lines:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
503 # ignore processing instructions
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
504 if self.in_processing_instructions:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505 found = False
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
506 for pi in ("##", "#format", "#refresh", "#redirect", "#deprecated",
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
507 "#pragma", "#form", "#acl", "#language"):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
508 if line.lower().startswith(pi):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
509 self.request.write(line + '\r\n')
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
510 found = True
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
511 break
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
512 if not found:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
513 self.in_processing_instructions = False
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
514 else:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
515 continue # do not parse this line
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
516 if not line.strip():
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
517 self.request.write(line + '\r\n')
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
518 else:
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
519 # Scan line, format and write
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
520 scanning_re = self.in_pre and pre_scan_re or scan_re
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
521 formatted_line = self.scan(scanning_re, line)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
522 self.request.write(formatted_line + '\r\n')
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
523