annotate MoinMoin/script/migration/_conv160_wiki.py @ 6133:a6283e189869 tip

fixup: remove nonexisting passlib.utils._blowfish this was removed by the passlib 1.7.1 upgrade.
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 01 Jun 2017 18:10:19 +0200
parents 500f68d3e2fd
children
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
5072
6cdf52df1219 migration _conv160_wiki and _conv160a_wiki reverted changeset 5067:0965bc1ee3c
Reimar Bauer <rb.proj AT googlemail DOT com>
parents: 5067
diff changeset
31 i18n.wikiLanguages = lambda: {}
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
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
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
36
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 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
38
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 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
40 """ 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
41 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
42 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
43 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
44 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
45 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
46 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
47 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
48 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
49 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
50
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51
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
52 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
53
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 # 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
55 # ... 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
56 # 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
57 # 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
58 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
59 """ 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
60 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
61 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
62 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
63 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
64 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
65
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 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
67 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
68 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
69
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 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
71
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 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
73 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
74 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
75 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
76 # 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
77 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
78 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
79 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
80 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
81 # 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
82 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
83 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
84 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
85
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 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
87 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
88
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 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
90
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
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92 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
93 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
94 self.pagename = pagename
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 self.raw = raw
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 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
97 self.request = request
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 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
99 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
100
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
101 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
102
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 # 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
104 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
105 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
106 _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
107 _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
108 _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
109 _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
110 _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
111 _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
112 _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
113 _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
114 _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
115 _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
116 _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
117 _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
118 _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
119 _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
120 _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
121 _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
122 _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
123 _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
124 _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
125 _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
126 _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
127 _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
128 _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
129 _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
130 _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
131 _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
132 _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
133 _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
134 _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
135 _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
136
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 # 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
138
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
139 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
140 """ 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
141 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
142 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
143 """
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 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
145 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
146 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
147 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
148 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
149 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
150 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
151 # 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
152 # 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
153 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
154 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
155 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
156 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
157 # 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
158 # 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
159 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
160 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
161 # 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
162 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
163 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
164 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
165 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
166 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
167 # 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
168 # 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
169 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
170 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
171 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
172 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
173 # 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
174 # 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
175 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
176 return new_name
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
177
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
178 def _replace_target(self, target):
6103
500f68d3e2fd remove our own usage of python_compatibility module
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5072
diff changeset
179 target_and_anchor = target.rsplit('#', 1)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
180 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
181 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
182 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
183 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
184 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
185 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
186 return target
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
187
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
188 # markup conversion
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
189
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
190 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
191 # 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
192 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
193 \[\[
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
194 (?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
195 (\((?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
196 \]\]
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 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
199 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
200 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
201 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
202 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
203 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
204 #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
205 #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
206 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
207 if image is None:
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
208 image = ''
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
209 if target is None:
5dfd26496da8 copied mig scripts from 1.6 branch
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2833
diff changeset
210 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
211 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
212 # 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 else:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
235 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
236 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
237 else:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
238 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
239 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
240 # 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
241 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
242
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 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
244 """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
245 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
246 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
247 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
248 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
249
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 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
251 """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
252 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
253 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
254 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
255 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
256 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
257 return word
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
258
2603
c61c10e3fcde 1.6 converter: improve content conversion, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2602
diff changeset
259 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
260 """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
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270 if camelcase:
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
271 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
272 else:
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
273 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
274 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
275 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
276 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
277 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
278 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
279
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 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
281 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
282 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
283 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
284 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
285 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
286 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
287
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 # 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
289 # 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
290 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
291 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
292 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
293 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
294 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
295 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
296 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
297 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
298 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
299 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
300 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
301
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 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
303 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
304 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
305 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
306 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
307 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
308 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
309
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 # 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
311 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
312 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
313 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
314 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
315 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
316 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
317 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
318
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 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
320 """ 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
321 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
322 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
323 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
324 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
325 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
326 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
327
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 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
329 #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
330
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 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
332 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
333 fname = self._replace(('FILE', pagename, fname))
4569
3caaa8c74c41 wikiutil: replace moin's cgi/urllib wrappers by calls to werkzeug.utils code
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 3119
diff changeset
334 fname = wikiutil.url_unquote(fname)
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
335 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
336 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
337 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
338 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
339 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
340 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
341
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 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
343 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
344
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 # 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
346 # (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
347 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
348 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
349
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 # 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
351 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
352 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
353 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
354 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
355
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
356 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
357 """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
358 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
359
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
360 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
361 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
362 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
363 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
364
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
365 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
366 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
367 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
368 return word
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
369
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
370 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
371 """Handle bracketed URLs."""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
372 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
373
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
374 # Local extended link?
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
375 if word[0] == ':':
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
376 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
377 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
378 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
379 text = ''
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
380 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
381 if text:
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
382 text = '|' + text
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
383 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
384
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
385 # 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
386 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
387 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
388 # 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
389 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
390 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
391 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
392 #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
393 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
394 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
395 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
396
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
397 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
398 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
399 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
400 #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
401 #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
402 #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
403 # 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
404 # 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
405 # 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
406 #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
407 # 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
408 # 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
409 # 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
410 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
411 m = self.attachment(words)
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
412 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
413 # 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
414 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
415 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
416
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 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
418 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
419 #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
420 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
421 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
422 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
423 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
424 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
425
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
426 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
427 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
428 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
429 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
430 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
431 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
432 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
433
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 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
435 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
436 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
437
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
438 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
439 """ 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
440 result = []
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
441 lastpos = 0
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
442
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
443 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
444 # 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
445 if lastpos < match.start():
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446 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
447 # Replace match with markup
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
448 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
449 lastpos = match.end()
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
450
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
451 # 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
452 result.append(line[lastpos:])
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453 return u''.join(result)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
454
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
455
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
456 def replace(self, match):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
457 """ 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
458 result = []
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
459 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
460 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
461 # 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
462 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
463 # print _type, hit
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
464 result.append(replace(hit))
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
465 return ''.join(result)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
466 else:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
467 # 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
468 import pprint
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
469 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
470 match,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
471 pprint.pformat(match.groupdict()),
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
472 pprint.pformat(match.groups()),
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
473 ))
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 return ""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
476
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
477 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
478 """ 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
479 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
480 """
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
481 self.request = request
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
482 # prepare regex patterns
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
483 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
484 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
485 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
486 '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
487 'rules': rules,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
488 }
2749
ef2268e5f605 1.6 converter: fix pre scan rules
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2747
diff changeset
489 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
490 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
491 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
492 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
493
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
494 rawtext = self.raw
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
495
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
496 # 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
497 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
498 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
499
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
500 # Main loop
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
501 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
502 # ignore processing instructions
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
503 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
504 found = False
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
505 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
506 "#pragma", "#form", "#acl", "#language"):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
507 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
508 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
509 found = True
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
510 break
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
511 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
512 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
513 else:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
514 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
515 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
516 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
517 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
518 # 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
519 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
520 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
521 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
522