git.iko.soy/typeable/pandoc
on master help sign in
MediaWiki writer: make links to relative URLs wikilinks.

The new rule: If the link target is an absolute URL, an external link is created. Otherwise, a wikilink is created. Examples: 1. [label](/foo/bar) => [[foo/bar|label]] 2. [label](foo) => [[foo|label]] 3. [label](http://gitit.net/foo) => [http://gitit.net/foo label] Note on 1: We strip the leading / here, since otherwise we get a link to Help:Links/foo/bar. would it be better for 1 to become [http://{SERVERNAME}}/foo/bar label]? Perhaps, since this would guarantee the same link destination as you'd get if you used the HTML writer directly. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1904 788f1e2b-df1e-0410-8736-df70ead52e1b

commitff68dd388390a110897d37fc8eff2219eb6ed1aa authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateThu 18 Mar 2010, 06:45 (17 years ago) parentd7e5bb9
2 files changed+31−33
src/Text/Pandoc/Writers/MediaWiki.hs+9−11 tests/writer.mediawiki+22−22
src/Text/Pandoc/Writers/MediaWiki.hs+9−11
@@ -377,17 +377,15 @@ inlineToMediaWiki _ (LineBreak) = return "<br />\n"
377377inlineToMediaWiki _ Space = return " "
378378
379379inlineToMediaWiki opts (Link txt (src, _)) = do
380− link <- inlineListToMediaWiki opts txt
381− let useAuto = txt == [Code src]
382− let src' = if isURI src
383− then src
384− else if take 1 src == "/"
385− then "http://{{SERVERNAME}}" ++ src
386− else "http://{{SERVERNAME}}/" ++ src
387− return $ if useAuto
388− then src'
389− else "[" ++ src' ++ " " ++ link ++ "]"
390−
380+ label <- inlineListToMediaWiki opts txt
381+ if txt == [Code src] -- autolink
382+ then return src
383+ else if isURI src
384+ then return $ "[" ++ src ++ " " ++ label ++ "]"
385+ else return $ "[[" ++ src' ++ "|" ++ label ++ "]]"
386+ where src' = case src of
387+ '/':xs -> xs -- with leading / it's a
388+ _ -> src -- link to a help page
391389inlineToMediaWiki opts (Image alt (source, tit)) = do
392390 alt' <- inlineListToMediaWiki opts alt
393391 let txt = if (null tit)
tests/writer.mediawiki+22−22
@@ -5,7 +5,7 @@ This is a set of tests for pandoc. Most of them are adapted from John Gruber&rsq
55
66= Headers =
77
8−== Level 2 with an [http://{{SERVERNAME}}/url embedded link] ==
8+== Level 2 with an [[url|embedded link]] ==
99
1010=== Level 3 with ''emphasis'' ===
1111
@@ -430,7 +430,7 @@ This is ''emphasized'', and so ''is this''.
430430
431431This is '''strong''', and so '''is this'''.
432432
433−An ''[http://{{SERVERNAME}}/url emphasized link]''.
433+An ''[[url|emphasized link]]''.
434434
435435'''''This is strong and em.'''''
436436
@@ -558,48 +558,48 @@ Minus: -
558558
559559== Explicit ==
560560
561−Just a [http://{{SERVERNAME}}/url/ URL].
561+Just a [[url/|URL]].
562562
563−[http://{{SERVERNAME}}/url/ URL and title].
563+[[url/|URL and title]].
564564
565−[http://{{SERVERNAME}}/url/ URL and title].
565+[[url/|URL and title]].
566566
567−[http://{{SERVERNAME}}/url/ URL and title].
567+[[url/|URL and title]].
568568
569−[http://{{SERVERNAME}}/url/ URL and title]
569+[[url/|URL and title]]
570570
571−[http://{{SERVERNAME}}/url/ URL and title]
571+[[url/|URL and title]]
572572
573−[http://{{SERVERNAME}}/url/with_underscore with_underscore]
573+[[url/with_underscore|with_underscore]]
574574
575575[mailto:nobody@nowhere.net Email link]
576576
577−[http://{{SERVERNAME}}/ Empty].
577+[[|Empty]].
578578
579579== Reference ==
580580
581−Foo [http://{{SERVERNAME}}/url/ bar].
581+Foo [[url/|bar]].
582582
583−Foo [http://{{SERVERNAME}}/url/ bar].
583+Foo [[url/|bar]].
584584
585−Foo [http://{{SERVERNAME}}/url/ bar].
585+Foo [[url/|bar]].
586586
587−With [http://{{SERVERNAME}}/url/ embedded [brackets]].
587+With [[url/|embedded [brackets]]].
588588
589−[http://{{SERVERNAME}}/url/ b] by itself should be a link.
589+[[url/|b]] by itself should be a link.
590590
591−Indented [http://{{SERVERNAME}}/url once].
591+Indented [[url|once]].
592592
593−Indented [http://{{SERVERNAME}}/url twice].
593+Indented [[url|twice]].
594594
595−Indented [http://{{SERVERNAME}}/url thrice].
595+Indented [[url|thrice]].
596596
597597This should [not][] be a link.
598598
599599<pre>[not]: /url</pre>
600−Foo [http://{{SERVERNAME}}/url/ bar].
600+Foo [[url/|bar]].
601601
602−Foo [http://{{SERVERNAME}}/url/ biz].
602+Foo [[url/|biz]].
603603
604604== With ampersands ==
605605
@@ -607,9 +607,9 @@ Here&rsquo;s a [http://example.com/?foo=1&bar=2 link with an ampersand in the UR
607607
608608Here&rsquo;s a link with an amersand in the link text: [http://att.com/ AT&amp;T].
609609
610−Here&rsquo;s an [http://{{SERVERNAME}}/script?foo=1&bar=2 inline link].
610+Here&rsquo;s an [[script?foo=1&bar=2|inline link]].
611611
612−Here&rsquo;s an [http://{{SERVERNAME}}/script?foo=1&bar=2 inline link in pointy braces].
612+Here&rsquo;s an [[script?foo=1&bar=2|inline link in pointy braces]].
613613
614614== Autolinks ==
615615