From ff68dd388390a110897d37fc8eff2219eb6ed1aa Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Thu, 18 Mar 2010 06:45:23 +0000 Subject: 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 --- src/Text/Pandoc/Writers/MediaWiki.hs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs index f81fda5d4..f1e985bb7 100644 --- a/src/Text/Pandoc/Writers/MediaWiki.hs +++ b/src/Text/Pandoc/Writers/MediaWiki.hs @@ -377,17 +377,15 @@ inlineToMediaWiki _ (LineBreak) = return "
\n" inlineToMediaWiki _ Space = return " " inlineToMediaWiki opts (Link txt (src, _)) = do - link <- inlineListToMediaWiki opts txt - let useAuto = txt == [Code src] - let src' = if isURI src - then src - else if take 1 src == "/" - then "http://{{SERVERNAME}}" ++ src - else "http://{{SERVERNAME}}/" ++ src - return $ if useAuto - then src' - else "[" ++ src' ++ " " ++ link ++ "]" - + label <- inlineListToMediaWiki opts txt + if txt == [Code src] -- autolink + then return src + else if isURI src + then return $ "[" ++ src ++ " " ++ label ++ "]" + else return $ "[[" ++ src' ++ "|" ++ label ++ "]]" + where src' = case src of + '/':xs -> xs -- with leading / it's a + _ -> src -- link to a help page inlineToMediaWiki opts (Image alt (source, tit)) = do alt' <- inlineListToMediaWiki opts alt let txt = if (null tit) -- cgit v1.2.3