From ffae1567fdaf8b0fbd3d35b2718ff7e35c8cf75f Mon Sep 17 00:00:00 2001
From: Timothy Humphries <tim@utf8.me>
Date: Sun, 9 Nov 2014 00:35:29 -0500
Subject: [PATCH 1/2] DokuWiki writer: fix external images

Handles #1739. Preface relative links with ":", absolute URIs without.
---
 src/Text/Pandoc/Writers/DokuWiki.hs | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/Writers/DokuWiki.hs b/src/Text/Pandoc/Writers/DokuWiki.hs
index 74418aa7e..eed45a965 100644
--- a/src/Text/Pandoc/Writers/DokuWiki.hs
+++ b/src/Text/Pandoc/Writers/DokuWiki.hs
@@ -134,7 +134,9 @@ blockToDokuWiki opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
   let opt = if null txt
                then ""
                else "|" ++ if null tit then capt else tit ++ capt
-  return $ "{{:" ++ src ++ opt ++ "}}\n"
+      -- Relative links fail isURI and receive a colon
+      prefix = if isURI src then "" else ":"
+  return $ "{{" ++ prefix ++ src ++ opt ++ "}}\n"
 
 blockToDokuWiki opts (Para inlines) = do
   indent <- stIndent <$> ask
@@ -478,7 +480,9 @@ inlineToDokuWiki opts (Image alt (source, tit)) = do
               ("", []) -> ""
               ("", _ ) -> "|" ++ alt'
               (_ , _ ) -> "|" ++ tit
-  return $ "{{:" ++ source ++ txt ++ "}}"
+      -- Relative links fail isURI and receive a colon
+      prefix = if isURI source then "" else ":"
+  return $ "{{" ++ prefix ++ source ++ txt ++ "}}"
 
 inlineToDokuWiki opts (Note contents) = do
   contents' <- blockListToDokuWiki opts contents

From 98161afa1a907a904dd86d2906106e28344a21ce Mon Sep 17 00:00:00 2001
From: Timothy Humphries <tim@utf8.me>
Date: Sun, 9 Nov 2014 02:18:58 -0500
Subject: [PATCH 2/2] DokuWiki writer: add external_images test

Add test for #1739.
---
 pandoc.cabal                            | 2 ++
 tests/Tests/Old.hs                      | 2 ++
 tests/dokuwiki_external_images.dokuwiki | 1 +
 tests/dokuwiki_external_images.native   | 1 +
 4 files changed, 6 insertions(+)
 create mode 100644 tests/dokuwiki_external_images.dokuwiki
 create mode 100644 tests/dokuwiki_external_images.native

diff --git a/pandoc.cabal b/pandoc.cabal
index 160d8c7ad..be6eafdf2 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -170,6 +170,8 @@ Extra-Source-Files:
                  tests/lhs-test.html+lhs
                  tests/lhs-test.fragment.html+lhs
                  tests/pipe-tables.txt
+		 tests/dokuwiki_external_images.dokuwiki
+		 tests/dokuwiki_external_images.native
                  tests/dokuwiki_multiblock_table.dokuwiki
                  tests/dokuwiki_multiblock_table.native
                  tests/fb2/*.markdown
diff --git a/tests/Tests/Old.hs b/tests/Tests/Old.hs
index 0f7b33dd1..5bdf325b1 100644
--- a/tests/Tests/Old.hs
+++ b/tests/Tests/Old.hs
@@ -130,6 +130,8 @@ tests = [ testGroup "markdown"
             "dokuwiki_inline_formatting.native" "dokuwiki_inline_formatting.dokuwiki"
           , test "multiblock table" ["-r", "native", "-w", "dokuwiki", "-s"]
             "dokuwiki_multiblock_table.native" "dokuwiki_multiblock_table.dokuwiki"
+          , test "external images" ["-r", "native", "-w", "dokuwiki", "-s"]
+            "dokuwiki_external_images.native" "dokuwiki_external_images.dokuwiki"
           ]
         , testGroup "opml"
           [ test "basic" ["-r", "native", "-w", "opml", "--columns=78", "-s"]
diff --git a/tests/dokuwiki_external_images.dokuwiki b/tests/dokuwiki_external_images.dokuwiki
new file mode 100644
index 000000000..cc7eddcda
--- /dev/null
+++ b/tests/dokuwiki_external_images.dokuwiki
@@ -0,0 +1 @@
+{{https://cooluri.com/image.png|HTTPS image}} {{http://cooluri.com/image.png|HTTP image}} {{ftp://ftp.cooluri.com/image.png|FTP image}} {{file:///tmp/coolimage.png|Filesystem image}} {{:/image.jpg|Relative image 1}} {{:image.jpg|Relative image 2}}
diff --git a/tests/dokuwiki_external_images.native b/tests/dokuwiki_external_images.native
new file mode 100644
index 000000000..c2b8876d3
--- /dev/null
+++ b/tests/dokuwiki_external_images.native
@@ -0,0 +1 @@
+[Para [Image [Str "HTTPS",Space,Str "image"] ("https://cooluri.com/image.png",""),Space,Image [Str "HTTP",Space,Str "image"] ("http://cooluri.com/image.png",""),Space,Image [Str "FTP",Space,Str "image"] ("ftp://ftp.cooluri.com/image.png",""),Space,Image [Str "Filesystem",Space,Str "image"] ("file:///tmp/coolimage.png",""),Space,Image [Str "Relative",Space,Str "image",Space,Str "1"] ("/image.jpg",""),Space,Image [Str "Relative",Space,Str "image",Space,Str "2"] ("image.jpg","")]]