1.1 --- a/convert.py Thu Jul 26 20:30:14 2018 +0200
1.2 +++ b/convert.py Thu Jul 26 20:42:37 2018 +0200
1.3 @@ -11,6 +11,7 @@
1.4 l = filenames = []
1.5 formats = []
1.6 pagenames = []
1.7 + mappings = []
1.8 tree = False
1.9 macros = False
1.10
1.11 @@ -32,6 +33,12 @@
1.12 l = formats
1.13 continue
1.14
1.15 + # Switch to collecting mappings.
1.16 +
1.17 + elif arg == "--mapping":
1.18 + l = mappings
1.19 + continue
1.20 +
1.21 # Switch to collecting page names.
1.22
1.23 elif arg == "--pagename":
1.24 @@ -43,6 +50,9 @@
1.25 else:
1.26 l.append(arg)
1.27
1.28 + if l is mappings:
1.29 + continue
1.30 +
1.31 # Collect filenames normally.
1.32
1.33 l = filenames
1.34 @@ -54,6 +64,20 @@
1.35 filename = filenames[0]
1.36 pagename = pagenames and pagenames[0] or split(filename)[-1]
1.37
1.38 + # Derive a proper mapping from the given list of values.
1.39 +
1.40 + mapping = {}
1.41 + key = None
1.42 +
1.43 + for arg in mappings:
1.44 + if key is None:
1.45 + key = arg
1.46 + else:
1.47 + mapping[key] = arg
1.48 + key = None
1.49 +
1.50 + # Open the file, parse the content, serialise the document.
1.51 +
1.52 f = open(filename)
1.53 try:
1.54 p = make_parser()
1.55 @@ -65,7 +89,7 @@
1.56 if tree:
1.57 print d.prettyprint()
1.58 else:
1.59 - l = make_linker(format, pagename)
1.60 + l = make_linker(format, pagename, mapping)
1.61 s = make_serialiser(format, l)
1.62 print serialise(d, s)
1.63 finally:
2.1 --- a/moinformat/links/__init__.py Thu Jul 26 20:30:14 2018 +0200
2.2 +++ b/moinformat/links/__init__.py Thu Jul 26 20:42:37 2018 +0200
2.3 @@ -32,17 +32,17 @@
2.4
2.5 return linkers.get(name)
2.6
2.7 -def make_linker(name, pagename):
2.8 +def make_linker(name, pagename, mapping=None):
2.9
2.10 """
2.11 Return a linking scheme handler with the given 'name' and using the given
2.12 - 'pagename'.
2.13 + 'pagename' and interwiki 'mapping'.
2.14 """
2.15
2.16 linker_cls = get_linker(name)
2.17 if not linker_cls:
2.18 return None
2.19
2.20 - return linker_cls(pagename)
2.21 + return linker_cls(pagename, mapping)
2.22
2.23 # vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/tests/test_links.tree Thu Jul 26 20:30:14 2018 +0200
3.2 +++ b/tests/test_links.tree Thu Jul 26 20:42:37 2018 +0200
3.3 @@ -22,3 +22,6 @@
3.4 Link
3.5 Text
3.6 Text
3.7 + Link
3.8 + Text
3.9 + Text
4.1 --- a/tests/test_links.txt Thu Jul 26 20:30:14 2018 +0200
4.2 +++ b/tests/test_links.txt Thu Jul 26 20:42:37 2018 +0200
4.3 @@ -1,3 +1,4 @@
4.4 Links: [[TopLevel|top-level]], [[/SubPage|sub-page]], [[/Sub/SubPage|sub-sub-page]],
4.5 [[../Sibling|sibling]], [[../../ParentSibling|sibling of parent]],
4.6 -[[http://www.python.org/|URL]], [[attachment:image.png|attachment]].
4.7 +[[http://www.python.org/|URL]], [[attachment:image.png|attachment]],
4.8 +[[MoinMoin:RecentChanges|interwiki]].