annotate MoinMoin/script/migration/_conv160_wiki.py @ 2814:7bde33d15531

1.6 converter: convert ImageLink to new link/transclusion syntax
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 09 Sep 2007 22:19:45 +0200
parents 3a6a25169f55
children ea9a38d2ec09
rev   line source
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
3 MoinMoin - convert content in 1.5.8 wiki markup to 1.6.0 style
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
4 by using a modified 1.5.8 parser as translator.
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 Assuming we have this "renames" map:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 -------------------------------------------------------
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 'PAGE', 'some_page' -> 'some page'
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 'FILE', 'with%20blank.txt' -> 'with blank.txt'
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 Markup transformations needed:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 -------------------------------------------------------
2726
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
13 ["some_page"] -> [[some page]] # renamed
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
14 [:some_page:some text] -> [[some page|some text]]
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
15 [:page:text] -> [[page|text]]
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 (with a page not being renamed)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
2726
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
18 attachment:with%20blank.txt -> [[attachment:with blank.txt]]
6cb75379c073 change ["free link"] to [[free link]] in all built-in markup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2612
diff changeset
19 attachment:some_page/with%20blank.txt -> [[attachment:some page/with blank.txt]]
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 The attachment processing should also urllib.unquote the filename (or at
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 least replace %20 by space) and put it into "quotes" if it contains spaces.
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 @copyright: 2007 MoinMoin:JohannesBerg,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 2007 MoinMoin:ThomasWaldmann
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 @license: GNU GPL, see COPYING for details.
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 """
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
28 import re
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
29
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30 from MoinMoin import i18n
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
31 i18n.wikiLanguages = lambda: {}
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
32
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
33 from MoinMoin import config, wikiutil, macro
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
34 from MoinMoin.action import AttachFile
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
35 from MoinMoin.Page import Page
2761
3a6a25169f55 use rsplit for splitting off anchor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2759
diff changeset
36 from MoinMoin.support.python_compatibility import rsplit
2730
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
37
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
38 from text_moin158_wiki import Parser
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
39
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
40 def convert_wiki(request, pagename, intext, renames):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
41 """ Convert content written in wiki markup """
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
42 noeol = False
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
43 if not intext.endswith('\r\n'):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
44 intext += '\r\n'
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
45 noeol = True
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
46 c = Converter(request, pagename, intext, renames)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
47 result = request.redirectedOutput(c.convert, request)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
48 if noeol and result.endswith('\r\n'):
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
49 result = result[:-2]
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
50 return result
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
51
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 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
54 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
55 self.pagename = pagename
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 self.raw = raw
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 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
58 self.request = request
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 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
60 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
61
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
62 self.formatting_rules = self.formatting_rules % {'macronames': u'|'.join(macro.getNames(self.request.cfg))}
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
63
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
64 # 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
65 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
66 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
67 _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
68 _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
69 _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
70 _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
71 _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
72 _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
73 _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
74 _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
75 _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
76 _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
77 _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
78 _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
79 _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
80 _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
81 _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
82 _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
83 _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
84 _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
85 _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
86 _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
87 _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
88 _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
89 _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
90 _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
91 _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
92 _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
93 _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
94 _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
95 _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
96 _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
97
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
98 # 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
99
2602
b601db2e4d34 1.6 converter: improve content conversion, add test for it
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2599
diff changeset
100 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
101 """ 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
102 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
103 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
104 """
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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 # 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
113 # 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
114 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
115 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
116 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
117 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
118 # 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
119 # 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
120 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
121 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
122 # 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
123 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
124 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
125 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
126 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
127 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
128 # 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
129 # 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
130 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
131 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
132 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
133 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
134 # 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
135 # 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
136 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
137 return new_name
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 def _replace_target(self, target):
2761
3a6a25169f55 use rsplit for splitting off anchor
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2759
diff changeset
140 target_and_anchor = rsplit(target, '#', 1)
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141 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
142 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
143 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
144 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
145 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
146 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
147 return target
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
148
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
149 # markup conversion
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
150
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
151 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
152 # 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
153 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
154 \[\[
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
155 (?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
156 (\((?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
157 \]\]
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
158 """
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
159 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
160 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
161 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
162 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
163 if macro_name == 'ImageLink':
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
164 fixed, kw, trailing = wikiutil.parse_quoted_separated(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
165 image, target = (fixed + ['', ''])[:2]
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
166 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
167 # 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
168 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
169 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
170 target = image
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
171 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
172 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
173 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
174 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
175 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
176 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
177 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
178 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
179 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
180 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
181 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
182 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
183 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
184 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
185 else:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
186 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
187 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
188 else:
7bde33d15531 1.6 converter: convert ImageLink to new link/transclusion syntax
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2761
diff changeset
189 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
190 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
191 # 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
192 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
193
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
194 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
195 """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
196 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
197 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
198 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
199 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
200
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
201 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
202 """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
203 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
204 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
205 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
206 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
207 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
208 return word
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
209
2603
c61c10e3fcde 1.6 converter: improve content conversion, more tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2602
diff changeset
210 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
211 """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
212 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
213 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
214 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
215 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
216 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
217 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
218 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
219 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
220 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
221 if camelcase:
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
222 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
223 else:
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
224 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
225 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
226 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
227 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
228 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
229 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
230
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
239 # 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
240 # 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
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 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
250 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
251 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
252
a907a61c33b3 * The 1.5.8 to 1.6.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 wikitag, wikiurl, wikitail, wikitag_bad = wikiutil.resolve_wiki(self.request, 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
254 wikitail = wikiutil.url_unquote(wikitail)
a907a61c33b3 * The 1.5.8 to 1.6.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
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
256 # 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264
a907a61c33b3 * The 1.5.8 to 1.6.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 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
266 """ 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
267 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
268 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
269 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
270 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
271 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
272 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
273
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
274 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
275 #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
276
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
277 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
278 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
279 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
280 fname = wikiutil.url_unquote(fname, want_unicode=True)
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
281 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
282 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
283 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
284 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
285 else:
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
286 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
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 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
289 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
290
a907a61c33b3 * The 1.5.8 to 1.6.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 # 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
292 # (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
293 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
294 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
295
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
296 # 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
297 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
298 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
299 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
300 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
301
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
302 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
303 """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
304 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
305
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
306 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
307 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
308 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
309 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
310
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
311 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
312 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
313 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
314 return word
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
315
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
316 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
317 """Handle bracketed URLs."""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
318 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
319
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
320 # Local extended link?
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
321 if word[0] == ':':
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
322 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
323 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
324 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
325 text = ''
e3e5e2373c60 1.6 converter: cleanup link conversion, cleanup/add tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2611
diff changeset
326 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
327 if text:
2729
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
328 text = '|' + text
012d5ec31f92 tests: fix most wiki markup converter tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2728
diff changeset
329 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
330
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
331 # 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
332 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
333 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
334 # 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
335 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
336 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
337 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
338 #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
339 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
340 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
341 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
342
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
343 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
344 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
345 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
346 #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
347 #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
348 #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
349 # 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
350 # 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
351 # 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
352 #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
353 # 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
354 # 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
355 # 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
356 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
357 m = self.attachment(words)
63ae36c70930 1.6 converter: less magic, better tests
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2730
diff changeset
358 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
359 # 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
360 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
361 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
362
a907a61c33b3 * The 1.5.8 to 1.6.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 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
364 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
365 #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
366 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
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 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
369 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
370 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
371
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
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379
a907a61c33b3 * The 1.5.8 to 1.6.0 converter now uses the 1.5.8 wiki parser, for better
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2729
diff changeset
380 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
381 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
382 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
383
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
384 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
385 """ 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
386 result = []
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
387 lastpos = 0
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
388
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
389 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
390 # 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
391 if lastpos < match.start():
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
392 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
393 # Replace match with markup
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
394 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
395 lastpos = match.end()
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
396
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
397 # 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
398 result.append(line[lastpos:])
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
399 return u''.join(result)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
400
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
401
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
402 def replace(self, match):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
403 """ 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
404 result = []
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
405 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
406 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
407 # 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
408 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
409 # print _type, hit
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
410 result.append(replace(hit))
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
411 return ''.join(result)
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
412 else:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
413 # 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
414 import pprint
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
415 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
416 match,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
417 pprint.pformat(match.groupdict()),
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
418 pprint.pformat(match.groups()),
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
419 ))
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
420
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
421 return ""
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
422
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
423 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
424 """ 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
425 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
426 """
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
427 self.request = request
2599
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
428 # prepare regex patterns
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
429 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
430 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
431 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
432 '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
433 'rules': rules,
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
434 }
2749
ef2268e5f605 1.6 converter: fix pre scan rules
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 2747
diff changeset
435 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
436 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
437 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
438 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
439
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
440 rawtext = self.raw
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
441
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
442 # 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
443 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
444 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
445
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
446 # Main loop
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
447 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
448 # ignore processing instructions
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
449 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
450 found = False
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
451 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
452 "#pragma", "#form", "#acl", "#language"):
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
453 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
454 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
455 found = True
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
456 break
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
457 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
458 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
459 else:
13f0331f3a42 1.6 converter: add content conversion (unfinished), cleanup
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
460 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
461 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
462 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
463 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
464 # 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
465 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
466 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
467 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
468