git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1746 from shelf/dw-ext-images

DokuWiki writer: fix external images

commit48e2586ec80dd883d83cd57bffcad9c97c1e7599 authorMatthew Pickering <matthewtpickering@gmail.com> dateMon 8 Dec 2014, 23:55 (12 years ago) parentdd9cb2c98161af
5 files changed+12−2
pandoc.cabal+2 src/Text/Pandoc/Writers/DokuWiki.hs+6−2 tests/Tests/Old.hs+2 tests/dokuwiki_external_images.dokuwiki+1 tests/dokuwiki_external_images.native+1
pandoc.cabal+2
@@ -170,6 +170,8 @@ Extra-Source-Files:
170170 tests/lhs-test.html+lhs
171171 tests/lhs-test.fragment.html+lhs
172172 tests/pipe-tables.txt
173+ tests/dokuwiki_external_images.dokuwiki
174+ tests/dokuwiki_external_images.native
173175 tests/dokuwiki_multiblock_table.dokuwiki
174176 tests/dokuwiki_multiblock_table.native
175177 tests/fb2/*.markdown
src/Text/Pandoc/Writers/DokuWiki.hs+6−2
@@ -134,7 +134,9 @@ blockToDokuWiki opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
134134 let opt = if null txt
135135 then ""
136136 else "|" ++ if null tit then capt else tit ++ capt
137− return $ "{{:" ++ src ++ opt ++ "}}\n"
137+ -- Relative links fail isURI and receive a colon
138+ prefix = if isURI src then "" else ":"
139+ return $ "{{" ++ prefix ++ src ++ opt ++ "}}\n"
138140
139141blockToDokuWiki opts (Para inlines) = do
140142 indent <- stIndent <$> ask
@@ -478,7 +480,9 @@ inlineToDokuWiki opts (Image alt (source, tit)) = do
478480 ("", []) -> ""
479481 ("", _ ) -> "|" ++ alt'
480482 (_ , _ ) -> "|" ++ tit
481− return $ "{{:" ++ source ++ txt ++ "}}"
483+ -- Relative links fail isURI and receive a colon
484+ prefix = if isURI source then "" else ":"
485+ return $ "{{" ++ prefix ++ source ++ txt ++ "}}"
482486
483487inlineToDokuWiki opts (Note contents) = do
484488 contents' <- blockListToDokuWiki opts contents
tests/Tests/Old.hs+2
@@ -130,6 +130,8 @@ tests = [ testGroup "markdown"
130130 "dokuwiki_inline_formatting.native" "dokuwiki_inline_formatting.dokuwiki"
131131 , test "multiblock table" ["-r", "native", "-w", "dokuwiki", "-s"]
132132 "dokuwiki_multiblock_table.native" "dokuwiki_multiblock_table.dokuwiki"
133+ , test "external images" ["-r", "native", "-w", "dokuwiki", "-s"]
134+ "dokuwiki_external_images.native" "dokuwiki_external_images.dokuwiki"
133135 ]
134136 , testGroup "opml"
135137 [ test "basic" ["-r", "native", "-w", "opml", "--columns=78", "-s"]
tests/dokuwiki_external_images.dokuwikinew file+1
@@ -0,0 +1 @@
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}}
tests/dokuwiki_external_images.nativenew file+1
@@ -0,0 +1 @@
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","")]]