git.iko.soy/typeable/pandoc
on master help sign in
Merge branch 'dokuwiki' of https://github.com/claremacrae/pandoc into claremacrae-dokuwiki
616cf6cJohn MacFarlane
data/templates+1−1

Submodule changed.

pandoc.cabal+2−1
@@ -19,7 +19,7 @@ Description: Pandoc is a Haskell library for converting from one markup
19 reStructuredText, LaTeX, DocBook, MediaWiki markup, Haddock
19 reStructuredText, LaTeX, DocBook, MediaWiki markup, Haddock
20 markup, OPML, Emacs Org-Mode, and Textile, and it can write
20 markup, OPML, Emacs Org-Mode, and Textile, and it can write
21 markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OPML,
21 markdown, reStructuredText, HTML, LaTeX, ConTeXt, Docbook, OPML,
22− OpenDocument, ODT, Word docx, RTF, MediaWiki, Textile,
22+ OpenDocument, ODT, Word docx, RTF, MediaWiki, DokuWiki, Textile,
23 groff man pages, plain text, Emacs Org-Mode, AsciiDoc,
23 groff man pages, plain text, Emacs Org-Mode, AsciiDoc,
24 Haddock markup, EPUB (v2 and v3), FictionBook2,
24 Haddock markup, EPUB (v2 and v3), FictionBook2,
25 InDesign ICML, and several kinds of HTML/javascript
25 InDesign ICML, and several kinds of HTML/javascript
@@ -315,6 +315,7 @@ Library
315 Text.Pandoc.Writers.Custom,
315 Text.Pandoc.Writers.Custom,
316 Text.Pandoc.Writers.Textile,
316 Text.Pandoc.Writers.Textile,
317 Text.Pandoc.Writers.MediaWiki,
317 Text.Pandoc.Writers.MediaWiki,
318+ Text.Pandoc.Writers.DokuWiki,
318 Text.Pandoc.Writers.RTF,
319 Text.Pandoc.Writers.RTF,
319 Text.Pandoc.Writers.ODT,
320 Text.Pandoc.Writers.ODT,
320 Text.Pandoc.Writers.Docx,
321 Text.Pandoc.Writers.Docx,
pandoc.hs+1
@@ -871,6 +871,7 @@ defaultReaderName fallback (x:xs) =
871 ".db" -> "docbook"
871 ".db" -> "docbook"
872 ".opml" -> "opml"
872 ".opml" -> "opml"
873 ".wiki" -> "mediawiki"
873 ".wiki" -> "mediawiki"
874+ ".dokuwiki" -> "dokuwiki"
874 ".textile" -> "textile"
875 ".textile" -> "textile"
875 ".native" -> "native"
876 ".native" -> "native"
876 ".json" -> "json"
877 ".json" -> "json"
src/Text/Pandoc.hs+3
@@ -94,6 +94,7 @@ module Text.Pandoc
94 , writeOpenDocument
94 , writeOpenDocument
95 , writeMan
95 , writeMan
96 , writeMediaWiki
96 , writeMediaWiki
97+ , writeDokuWiki
97 , writeTextile
98 , writeTextile
98 , writeRTF
99 , writeRTF
99 , writeODT
100 , writeODT
@@ -147,6 +148,7 @@ import Text.Pandoc.Writers.OpenDocument
147import Text.Pandoc.Writers.Man
148import Text.Pandoc.Writers.Man
148import Text.Pandoc.Writers.RTF
149import Text.Pandoc.Writers.RTF
149import Text.Pandoc.Writers.MediaWiki
150import Text.Pandoc.Writers.MediaWiki
151+import Text.Pandoc.Writers.DokuWiki
150import Text.Pandoc.Writers.Textile
152import Text.Pandoc.Writers.Textile
151import Text.Pandoc.Writers.Org
153import Text.Pandoc.Writers.Org
152import Text.Pandoc.Writers.AsciiDoc
154import Text.Pandoc.Writers.AsciiDoc
@@ -277,6 +279,7 @@ writers = [
277 ,("plain" , PureStringWriter writePlain)
279 ,("plain" , PureStringWriter writePlain)
278 ,("rst" , PureStringWriter writeRST)
280 ,("rst" , PureStringWriter writeRST)
279 ,("mediawiki" , PureStringWriter writeMediaWiki)
281 ,("mediawiki" , PureStringWriter writeMediaWiki)
282+ ,("dokuwiki" , PureStringWriter writeDokuWiki)
280 ,("textile" , PureStringWriter writeTextile)
283 ,("textile" , PureStringWriter writeTextile)
281 ,("rtf" , IOStringWriter writeRTFWithEmbeddedImages)
284 ,("rtf" , IOStringWriter writeRTFWithEmbeddedImages)
282 ,("org" , PureStringWriter writeOrg)
285 ,("org" , PureStringWriter writeOrg)
src/Text/Pandoc/Writers/DokuWiki.hsnew file+435
@@ -0,0 +1,435 @@
1+{-
2+Copyright (C) 2008-2014 John MacFarlane <jgm@berkeley.edu>
3+
4+This program is free software; you can redistribute it and/or modify
5+it under the terms of the GNU General Public License as published by
6+the Free Software Foundation; either version 2 of the License, or
7+(at your option) any later version.
8+
9+This program is distributed in the hope that it will be useful,
10+but WITHOUT ANY WARRANTY; without even the implied warranty of
11+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+GNU General Public License for more details.
13+
14+You should have received a copy of the GNU General Public License
15+along with this program; if not, write to the Free Software
16+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17+-}
18+
19+{- |
20+ Module : Text.Pandoc.Writers.DokuWiki
21+ Copyright : Copyright (C) 2008-2014 John MacFarlane
22+ License : GNU GPL, version 2 or above
23+
24+ Maintainer : John MacFarlane <jgm@berkeley.edu>
25+ Stability : alpha
26+ Portability : portable
27+
28+Conversion of 'Pandoc' documents to DokuWiki markup.
29+
30+DokuWiki: <https://www.dokuwiki.org/dokuwiki>
31+-}
32+
33+{-
34+ [ ] Implement nested blockquotes (currently only ever does one level)
35+ [ ] Implement alignment of text in tables
36+ [ ] Implement comments
37+ [ ] Work through the Dokuwiki spec, and check I've not missed anything out
38+ [ ] Remove dud/duplicate code
39+-}
40+
41+module Text.Pandoc.Writers.DokuWiki ( writeDokuWiki ) where
42+import Text.Pandoc.Definition
43+import Text.Pandoc.Options
44+import Text.Pandoc.Shared
45+import Text.Pandoc.Writers.Shared
46+import Text.Pandoc.Templates (renderTemplate')
47+import Data.List ( intersect, intercalate )
48+import Network.URI ( isURI )
49+import Control.Monad.State
50+
51+data WriterState = WriterState {
52+ stNotes :: Bool -- True if there are notes
53+ , stIndent :: String -- Indent after the marker at the beginning of list items
54+ , stUseTags :: Bool -- True if we should use HTML tags because we're in a complex list
55+ }
56+
57+-- | Convert Pandoc to DokuWiki.
58+writeDokuWiki :: WriterOptions -> Pandoc -> String
59+writeDokuWiki opts document =
60+ evalState (pandocToDokuWiki opts document)
61+ (WriterState { stNotes = False, stIndent = "", stUseTags = False })
62+
63+-- | Return DokuWiki representation of document.
64+pandocToDokuWiki :: WriterOptions -> Pandoc -> State WriterState String
65+pandocToDokuWiki opts (Pandoc meta blocks) = do
66+ metadata <- metaToJSON opts
67+ (fmap trimr . blockListToDokuWiki opts)
68+ (inlineListToDokuWiki opts)
69+ meta
70+ body <- blockListToDokuWiki opts blocks
71+ notesExist <- get >>= return . stNotes
72+ let notes = if notesExist
73+ then "" -- TODO Was "\n<references />" Check whether I can really remove this:
74+ -- if it is definitely to do with footnotes, can remove this whole bit
75+ else ""
76+ let main = body ++ notes
77+ let context = defField "body" main
78+ $ defField "toc" (writerTableOfContents opts)
79+ $ metadata
80+ if writerStandalone opts
81+ then return $ renderTemplate' (writerTemplate opts) context
82+ else return main
83+
84+-- | Escape special characters for MediaWiki.
85+escapeString :: String -> String
86+escapeString str = substitute "__" "%%__%%" ( substitute "**" "%%**%%" ( substitute "//" "%%//%%" str ) )
87+
88+-- | Convert Pandoc block element to DokuWiki.
89+blockToDokuWiki :: WriterOptions -- ^ Options
90+ -> Block -- ^ Block element
91+ -> State WriterState String
92+
93+blockToDokuWiki _ Null = return ""
94+
95+blockToDokuWiki opts (Div _attrs bs) = do
96+ contents <- blockListToDokuWiki opts bs
97+ return $ contents ++ "\n"
98+
99+blockToDokuWiki opts (Plain inlines) =
100+ inlineListToDokuWiki opts inlines
101+
102+-- title beginning with fig: indicates that the image is a figure
103+-- dokuwiki doesn't support captions - so combine together alt and caption into alt
104+blockToDokuWiki opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
105+ capt <- if null txt
106+ then return ""
107+ else (" " ++) `fmap` inlineListToDokuWiki opts txt
108+ let opt = if null txt
109+ then ""
110+ else "|" ++ if null tit then capt else tit ++ capt
111+ return $ "{{:" ++ src ++ opt ++ "}}\n"
112+
113+blockToDokuWiki opts (Para inlines) = do
114+ useTags <- get >>= return . stUseTags
115+ indent <- get >>= return . stIndent
116+ contents <- inlineListToDokuWiki opts inlines
117+ return $ if useTags
118+ then "<p>" ++ contents ++ "</p>"
119+ else contents ++ if null indent then "\n" else ""
120+
121+blockToDokuWiki _ (RawBlock f str)
122+ | f == Format "mediawiki" = return str
123+ | f == Format "html" = return $ "<html>\n" ++ str ++ "</html>"
124+ | otherwise = return str
125+
126+blockToDokuWiki _ HorizontalRule = return "\n----\n"
127+
128+blockToDokuWiki opts (Header level _ inlines) = do
129+ contents <- inlineListToDokuWiki opts inlines
130+ let eqs = replicate ( 7 - level ) '='
131+ return $ eqs ++ " " ++ contents ++ " " ++ eqs ++ "\n"
132+
133+blockToDokuWiki _ (CodeBlock (_,classes,_) str) = do
134+ let at = classes `intersect` ["actionscript", "ada", "apache", "applescript", "asm", "asp",
135+ "autoit", "bash", "blitzbasic", "bnf", "c", "c_mac", "caddcl", "cadlisp", "cfdg", "cfm",
136+ "cpp", "cpp-qt", "csharp", "css", "d", "delphi", "diff", "div", "dos", "eiffel", "fortran",
137+ "freebasic", "gml", "groovy", "html4strict", "idl", "ini", "inno", "io", "java", "java5",
138+ "javascript", "latex", "lisp", "lua", "matlab", "mirc", "mpasm", "mysql", "nsis", "objc",
139+ "ocaml", "ocaml-brief", "oobas", "oracle8", "pascal", "perl", "php", "php-brief", "plsql",
140+ "python", "qbasic", "rails", "reg", "robots", "ruby", "sas", "scheme", "sdlbasic",
141+ "smalltalk", "smarty", "sql", "tcl", "", "thinbasic", "tsql", "vb", "vbnet", "vhdl",
142+ "visualfoxpro", "winbatch", "xml", "xpp", "z80"]
143+ let (beg, end) = if null at
144+ then ("<code" ++ if null classes then ">" else " class=\"" ++ unwords classes ++ "\">", "</code>")
145+ else ("<source lang=\"" ++ head at ++ "\">", "</source>")
146+ return $ beg ++ str ++ end
147+
148+blockToDokuWiki opts (BlockQuote blocks) = do
149+ contents <- blockListToDokuWiki opts blocks
150+ return $ "> " ++ contents
151+
152+blockToDokuWiki opts (Table capt aligns _ headers rows') = do
153+ let alignStrings = map alignmentToString aligns
154+ captionDoc <- if null capt
155+ then return ""
156+ else do
157+ c <- inlineListToDokuWiki opts capt
158+ return $ "" ++ c ++ "\n"
159+ head' <- if all null headers
160+ then return ""
161+ else do
162+ hs <- tableHeaderToDokuWiki opts alignStrings 0 headers
163+ return $ hs ++ "\n"
164+ body' <- zipWithM (tableRowToDokuWiki opts alignStrings) [1..] rows'
165+ return $ captionDoc ++ head' ++
166+ unlines body'
167+
168+blockToDokuWiki opts x@(BulletList items) = do
169+ oldUseTags <- get >>= return . stUseTags
170+ indent <- get >>= return . stIndent
171+ let useTags = oldUseTags || not (isSimpleList x)
172+ if useTags
173+ then do
174+ modify $ \s -> s { stUseTags = True }
175+ contents <- mapM (listItemToDokuWiki opts) items
176+ modify $ \s -> s { stUseTags = oldUseTags }
177+ return $ "<ul>\n" ++ vcat contents ++ "</ul>\n"
178+ else do
179+ modify $ \s -> s { stIndent = stIndent s ++ " " }
180+ contents <- mapM (listItemToDokuWiki opts) items
181+ modify $ \s -> s { stIndent = indent }
182+ return $ vcat contents ++ if null indent then "\n" else ""
183+
184+blockToDokuWiki opts x@(OrderedList attribs items) = do
185+ oldUseTags <- get >>= return . stUseTags
186+ indent <- get >>= return . stIndent
187+ let useTags = oldUseTags || not (isSimpleList x)
188+ if useTags
189+ then do
190+ modify $ \s -> s { stUseTags = True }
191+ contents <- mapM (orderedListItemToDokuWiki opts) items
192+ modify $ \s -> s { stUseTags = oldUseTags }
193+ return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++ "</ol>\n"
194+ else do
195+ modify $ \s -> s { stIndent = stIndent s ++ " " }
196+ contents <- mapM (orderedListItemToDokuWiki opts) items
197+ modify $ \s -> s { stIndent = indent }
198+ return $ vcat contents ++ if null indent then "\n" else ""
199+
200+-- TODO Need to decide how to make definition lists work on dokuwiki - I don't think there
201+-- is a specific representation of them.
202+-- TODO This creates double '; ; ' if there is a bullet or ordered list inside a definition list
203+blockToDokuWiki opts x@(DefinitionList items) = do
204+ oldUseTags <- get >>= return . stUseTags
205+ indent <- get >>= return . stIndent
206+ let useTags = oldUseTags || not (isSimpleList x)
207+ if useTags
208+ then do
209+ modify $ \s -> s { stUseTags = True }
210+ contents <- mapM (definitionListItemToDokuWiki opts) items
211+ modify $ \s -> s { stUseTags = oldUseTags }
212+ return $ "<dl>\n" ++ vcat contents ++ "</dl>\n"
213+ else do
214+ modify $ \s -> s { stIndent = stIndent s ++ " " }
215+ contents <- mapM (definitionListItemToDokuWiki opts) items
216+ modify $ \s -> s { stIndent = indent }
217+ return $ vcat contents ++ if null indent then "\n" else ""
218+
219+-- Auxiliary functions for lists:
220+
221+-- | Convert ordered list attributes to HTML attribute string
222+listAttribsToString :: ListAttributes -> String
223+listAttribsToString (startnum, numstyle, _) =
224+ let numstyle' = camelCaseToHyphenated $ show numstyle
225+ in (if startnum /= 1
226+ then " start=\"" ++ show startnum ++ "\""
227+ else "") ++
228+ (if numstyle /= DefaultStyle
229+ then " style=\"list-style-type: " ++ numstyle' ++ ";\""
230+ else "")
231+
232+-- | Convert bullet list item (list of blocks) to DokuWiki.
233+listItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
234+listItemToDokuWiki opts items = do
235+ contents <- blockListToDokuWiki opts items
236+ useTags <- get >>= return . stUseTags
237+ if useTags
238+ then return $ "<li>" ++ contents ++ "</li>"
239+ else do
240+ indent <- get >>= return . stIndent
241+ return $ indent ++ "* " ++ contents
242+
243+-- | Convert ordered list item (list of blocks) to DokuWiki.
244+-- | TODO Emiminate dreadful duplication of text from listItemToDokuWiki
245+orderedListItemToDokuWiki :: WriterOptions -> [Block] -> State WriterState String
246+orderedListItemToDokuWiki opts items = do
247+ contents <- blockListToDokuWiki opts items
248+ useTags <- get >>= return . stUseTags
249+ if useTags
250+ then return $ "<li>" ++ contents ++ "</li>"
251+ else do
252+ indent <- get >>= return . stIndent
253+ return $ indent ++ "- " ++ contents
254+
255+-- | Convert definition list item (label, list of blocks) to DokuWiki.
256+definitionListItemToDokuWiki :: WriterOptions
257+ -> ([Inline],[[Block]])
258+ -> State WriterState String
259+definitionListItemToDokuWiki opts (label, items) = do
260+ labelText <- inlineListToDokuWiki opts label
261+ contents <- mapM (blockListToDokuWiki opts) items
262+ useTags <- get >>= return . stUseTags
263+ if useTags
264+ then return $ "<dt>" ++ labelText ++ "</dt>\n" ++
265+ (intercalate "\n" $ map (\d -> "<dd>" ++ d ++ "</dd>") contents)
266+ else do
267+ indent <- get >>= return . stIndent
268+ return $ indent ++ "* **" ++ labelText ++ "** " ++ concat contents
269+
270+-- | True if the list can be handled by simple wiki markup, False if HTML tags will be needed.
271+isSimpleList :: Block -> Bool
272+isSimpleList x =
273+ case x of
274+ BulletList _ -> True
275+ OrderedList _ _ -> True
276+ DefinitionList _ -> True
277+ _ -> False
278+
279+-- | Concatenates strings with line breaks between them.
280+vcat :: [String] -> String
281+vcat = intercalate "\n"
282+
283+-- Auxiliary functions for tables:
284+
285+-- TODO Eliminate copy-and-pasted code in tableHeaderToDokuWiki and tableRowToDokuWiki
286+tableHeaderToDokuWiki :: WriterOptions
287+ -> [String]
288+ -> Int
289+ -> [[Block]]
290+ -> State WriterState String
291+tableHeaderToDokuWiki opts alignStrings rownum cols' = do
292+ let celltype = if rownum == 0 then "" else ""
293+ cols'' <- sequence $ zipWith
294+ (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
295+ alignStrings cols'
296+ return $ "^ " ++ "" ++ joinHeaders cols'' ++ " ^"
297+
298+tableRowToDokuWiki :: WriterOptions
299+ -> [String]
300+ -> Int
301+ -> [[Block]]
302+ -> State WriterState String
303+tableRowToDokuWiki opts alignStrings rownum cols' = do
304+ let celltype = if rownum == 0 then "" else ""
305+ cols'' <- sequence $ zipWith
306+ (\alignment item -> tableItemToDokuWiki opts celltype alignment item)
307+ alignStrings cols'
308+ return $ "| " ++ "" ++ joinColumns cols'' ++ " |"
309+
310+alignmentToString :: Alignment -> [Char]
311+alignmentToString alignment = case alignment of
312+ AlignLeft -> ""
313+ AlignRight -> ""
314+ AlignCenter -> ""
315+ AlignDefault -> ""
316+
317+tableItemToDokuWiki :: WriterOptions
318+ -> String
319+ -> String
320+ -> [Block]
321+ -> State WriterState String
322+-- TODO Fix celltype and align' defined but not used
323+tableItemToDokuWiki opts _celltype _align' item = do
324+ let mkcell x = "" ++ x ++ ""
325+ contents <- blockListToDokuWiki opts item
326+ return $ mkcell contents
327+
328+-- | Concatenates columns together.
329+joinColumns :: [String] -> String
330+joinColumns = intercalate " | "
331+
332+-- | Concatenates headers together.
333+joinHeaders :: [String] -> String
334+joinHeaders = intercalate " ^ "
335+
336+-- | Convert list of Pandoc block elements to DokuWiki.
337+blockListToDokuWiki :: WriterOptions -- ^ Options
338+ -> [Block] -- ^ List of block elements
339+ -> State WriterState String
340+blockListToDokuWiki opts blocks =
341+ mapM (blockToDokuWiki opts) blocks >>= return . vcat
342+
343+-- | Convert list of Pandoc inline elements to DokuWiki.
344+inlineListToDokuWiki :: WriterOptions -> [Inline] -> State WriterState String
345+inlineListToDokuWiki opts lst = mapM (inlineToDokuWiki opts) lst >>= return . concat
346+
347+-- | Convert Pandoc inline element to DokuWiki.
348+inlineToDokuWiki :: WriterOptions -> Inline -> State WriterState String
349+
350+inlineToDokuWiki opts (Span _attrs ils) = do
351+ contents <- inlineListToDokuWiki opts ils
352+ return contents
353+
354+inlineToDokuWiki opts (Emph lst) = do
355+ contents <- inlineListToDokuWiki opts lst
356+ return $ "//" ++ contents ++ "//"
357+
358+inlineToDokuWiki opts (Strong lst) = do
359+ contents <- inlineListToDokuWiki opts lst
360+ return $ "**" ++ contents ++ "**"
361+
362+inlineToDokuWiki opts (Strikeout lst) = do
363+ contents <- inlineListToDokuWiki opts lst
364+ return $ "<del>" ++ contents ++ "</del>"
365+
366+inlineToDokuWiki opts (Superscript lst) = do
367+ contents <- inlineListToDokuWiki opts lst
368+ return $ "<sup>" ++ contents ++ "</sup>"
369+
370+inlineToDokuWiki opts (Subscript lst) = do
371+ contents <- inlineListToDokuWiki opts lst
372+ return $ "<sub>" ++ contents ++ "</sub>"
373+
374+inlineToDokuWiki opts (SmallCaps lst) = inlineListToDokuWiki opts lst
375+
376+inlineToDokuWiki opts (Quoted SingleQuote lst) = do
377+ contents <- inlineListToDokuWiki opts lst
378+ return $ "\8216" ++ contents ++ "\8217"
379+
380+inlineToDokuWiki opts (Quoted DoubleQuote lst) = do
381+ contents <- inlineListToDokuWiki opts lst
382+ return $ "\8220" ++ contents ++ "\8221"
383+
384+inlineToDokuWiki opts (Cite _ lst) = inlineListToDokuWiki opts lst
385+
386+inlineToDokuWiki _ (Code _ str) =
387+ -- In dokuwiki, text surrounded by '' is really just a font statement, i.e. <tt>,
388+ -- and so other formatting can be present inside.
389+ -- However, in pandoc, and markdown, inlined code doesn't contain formatting.
390+ -- So I have opted for using %% to disable all formatting inside inline code blocks.
391+ -- This gives the best results when converting from other formats to dokuwiki, even if
392+ -- the resultand code is a little ugly, for short strings that don't contain formatting
393+ -- characters.
394+ -- It does mean that if pandoc could ever read dokuwiki, and so round-trip the format,
395+ -- any formatting inside inlined code blocks would be lost, or presented incorrectly.
396+ return $ "''%%" ++ str ++ "%%''"
397+
398+inlineToDokuWiki _ (Str str) = return $ escapeString str
399+
400+inlineToDokuWiki _ (Math _ str) = return $ "<math>" ++ str ++ "</math>"
401+ -- note: str should NOT be escaped
402+
403+inlineToDokuWiki _ (RawInline f str)
404+ | f == Format "mediawiki" = return str
405+ | f == Format "html" = return str
406+ | otherwise = return str
407+
408+inlineToDokuWiki _ (LineBreak) = return "\\\\ "
409+
410+inlineToDokuWiki _ Space = return " "
411+
412+inlineToDokuWiki opts (Link txt (src, _)) = do
413+ label <- inlineListToDokuWiki opts txt
414+ case txt of
415+ [Str s] | escapeURI s == src -> return src
416+ _ -> if isURI src
417+ then return $ "[[" ++ src ++ "|" ++ label ++ "]]"
418+ else return $ "[[" ++ src' ++ "|" ++ label ++ "]]"
419+ where src' = case src of
420+ '/':xs -> xs -- with leading / it's a
421+ _ -> src -- link to a help page
422+inlineToDokuWiki opts (Image alt (source, tit)) = do
423+ alt' <- inlineListToDokuWiki opts alt
424+ let txt = if (null tit)
425+ then if null alt
426+ then ""
427+ else "|" ++ alt'
428+ else "|" ++ tit
429+ return $ "{{:" ++ source ++ txt ++ "}}"
430+
431+inlineToDokuWiki opts (Note contents) = do
432+ contents' <- blockListToDokuWiki opts contents
433+ modify (\s -> s { stNotes = True })
434+ return $ "((" ++ contents' ++ "))"
435+ -- note - may not work for notes with multiple blocks
tests/Tests/Old.hs+7
@@ -124,6 +124,13 @@ tests = [ testGroup "markdown"
124 , test "reader" ["-r", "mediawiki", "-w", "native", "-s"]
124 , test "reader" ["-r", "mediawiki", "-w", "native", "-s"]
125 "mediawiki-reader.wiki" "mediawiki-reader.native"
125 "mediawiki-reader.wiki" "mediawiki-reader.native"
126 ]
126 ]
127+ , testGroup "dokuwiki"
128+ [ testGroup "writer" $ writerTests "dokuwiki"
129+ , test "writer-more" ["-r", "native", "-w", "dokuwiki", "-s"]
130+ "dokuwiki-writer.native" "dokuwiki-writer.dokuwiki"
131+ , test "writer-inline_formatting" ["-r", "native", "-w", "dokuwiki", "-s"]
132+ "dokuwiki.inline_formatting.native" "dokuwiki.inline_formatting.dokuwiki"
133+ ]
127 , testGroup "opml"
134 , testGroup "opml"
128 [ test "basic" ["-r", "native", "-w", "opml", "--columns=78", "-s"]
135 [ test "basic" ["-r", "native", "-w", "opml", "--columns=78", "-s"]
129 "testsuite.native" "writer.opml"
136 "testsuite.native" "writer.opml"
tests/dokuwiki-writer.dokuwikinew file+3
@@ -0,0 +1,3 @@
1+hello %%//%% world %%**%% from %%__%% me
2+
3+''%%hello // world ** from __ me%%''
tests/dokuwiki-writer.nativenew file+2
@@ -0,0 +1,2 @@
1+[Para [Str "hello",Space,Str "//",Space,Str "world",Space,Str "**",Space,Str "from",Space,Str "__",Space,Str "me"]
2+,Para [Code ("",[],[]) "hello // world ** from __ me"]]
tests/dokuwiki.inline_formatting.dokuwikinew file+9
@@ -0,0 +1,9 @@
1+Regular text //italics// **bold //bold italics//**.
2+
3+This is Small Caps, and this is <del>strikethrough</del>.
4+
5+Some people use single underlines for //emphasis//.
6+
7+Above the line is <sup>superscript</sup> and below the line is <sub>subscript</sub>.
8+
9+A line\\ break.
tests/dokuwiki.inline_formatting.nativenew file+5
@@ -0,0 +1,5 @@
1+[Para [Str "Regular",Space,Str "text",Space,Emph [Str "italics"],Space,Strong [Str "bold",Space,Emph [Str "bold",Space,Str "italics"]],Str "."]
2+,Para [Str "This",Space,Str "is",Space,SmallCaps [Str "Small",Space,Str "Caps"],Str ",",Space,Str "and",Space,Str "this",Space,Str "is",Space,Strikeout [Str "strikethrough"],Str "."]
3+,Para [Str "Some",Space,Str "people",Space,Str "use",Space,Span ("",[],[("underline","single")]) [Str "single",Space,Str "underlines",Space,Str "for",Space,Emph [Str "emphasis"]],Str "."]
4+,Para [Str "Above",Space,Str "the",Space,Str "line",Space,Str "is",Space,Superscript [Str "superscript"],Space,Str "and",Space,Str "below",Space,Str "the",Space,Str "line",Space,Str "is",Space,Subscript [Str "subscript"],Str "."]
5+,Para [Str "A",Space,Str "line",LineBreak,Str "break."]]
tests/tables.dokuwikinew file+47
@@ -0,0 +1,47 @@
1+Simple table with caption:
2+
3+Demonstration of simple table syntax.
4+^ Right ^ Left ^ Center ^ Default ^
5+| 12 | 12 | 12 | 12 |
6+| 123 | 123 | 123 | 123 |
7+| 1 | 1 | 1 | 1 |
8+
9+Simple table without caption:
10+
11+^ Right ^ Left ^ Center ^ Default ^
12+| 12 | 12 | 12 | 12 |
13+| 123 | 123 | 123 | 123 |
14+| 1 | 1 | 1 | 1 |
15+
16+Simple table indented two spaces:
17+
18+Demonstration of simple table syntax.
19+^ Right ^ Left ^ Center ^ Default ^
20+| 12 | 12 | 12 | 12 |
21+| 123 | 123 | 123 | 123 |
22+| 1 | 1 | 1 | 1 |
23+
24+Multiline table with caption:
25+
26+Here's the caption. It may span multiple lines.
27+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
28+| First | row | 12.0 | Example of a row that spans multiple lines. |
29+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
30+
31+Multiline table without caption:
32+
33+^ Centered Header ^ Left Aligned ^ Right Aligned ^ Default aligned ^
34+| First | row | 12.0 | Example of a row that spans multiple lines. |
35+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
36+
37+Table without column headers:
38+
39+| 12 | 12 | 12 | 12 |
40+| 123 | 123 | 123 | 123 |
41+| 1 | 1 | 1 | 1 |
42+
43+Multiline table without column headers:
44+
45+| First | row | 12.0 | Example of a row that spans multiple lines. |
46+| Second | row | 5.0 | Here's another one. Note the blank line between rows. |
47+
tests/writer.dokuwikinew file+611
@@ -0,0 +1,611 @@
1+This is a set of tests for pandoc. Most of them are adapted from John Gruber’s markdown test suite.
2+
3+
4+----
5+
6+====== Headers ======
7+
8+===== Level 2 with an [[url|embedded link]] =====
9+
10+==== Level 3 with //emphasis// ====
11+
12+=== Level 4 ===
13+
14+== Level 5 ==
15+
16+====== Level 1 ======
17+
18+===== Level 2 with //emphasis// =====
19+
20+==== Level 3 ====
21+
22+with no blank line
23+
24+===== Level 2 =====
25+
26+with no blank line
27+
28+
29+----
30+
31+====== Paragraphs ======
32+
33+Here’s a regular paragraph.
34+
35+In Markdown 1.0.0 and earlier. Version 8. This line turns into a list item. Because a hard-wrapped line in the middle of a paragraph looked like a list item.
36+
37+Here’s one with a bullet. * criminey.
38+
39+There should be a hard line break\\ here.
40+
41+
42+----
43+
44+====== Block Quotes ======
45+
46+E-mail style:
47+
48+> This is a block quote. It is pretty short.
49+
50+> Code in a block quote:
51+
52+<code>sub status {
53+ print "working";
54+}</code>
55+A list:
56+
57+ - item one
58+ - item two
59+
60+Nested block quotes:
61+
62+> nested
63+
64+> nested
65+
66+This should not be a block quote: 2 > 1.
67+
68+And a following paragraph.
69+
70+
71+----
72+
73+====== Code Blocks ======
74+
75+Code:
76+
77+<code>---- (should be four hyphens)
78+
79+sub status {
80+ print "working";
81+}
82+
83+this code block is indented by one tab</code>
84+And:
85+
86+<code> this code block is indented by two tabs
87+
88+These should not be escaped: \$ \\ \> \[ \{</code>
89+
90+----
91+
92+====== Lists ======
93+
94+===== Unordered =====
95+
96+Asterisks tight:
97+
98+ * asterisk 1
99+ * asterisk 2
100+ * asterisk 3
101+
102+Asterisks loose:
103+
104+ * asterisk 1
105+ * asterisk 2
106+ * asterisk 3
107+
108+Pluses tight:
109+
110+ * Plus 1
111+ * Plus 2
112+ * Plus 3
113+
114+Pluses loose:
115+
116+ * Plus 1
117+ * Plus 2
118+ * Plus 3
119+
120+Minuses tight:
121+
122+ * Minus 1
123+ * Minus 2
124+ * Minus 3
125+
126+Minuses loose:
127+
128+ * Minus 1
129+ * Minus 2
130+ * Minus 3
131+
132+===== Ordered =====
133+
134+Tight:
135+
136+ - First
137+ - Second
138+ - Third
139+
140+and:
141+
142+ - One
143+ - Two
144+ - Three
145+
146+Loose using tabs:
147+
148+ - First
149+ - Second
150+ - Third
151+
152+and using spaces:
153+
154+ - One
155+ - Two
156+ - Three
157+
158+Multiple paragraphs:
159+
160+ - Item 1, graf one.
161+Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
162+ - Item 2.
163+ - Item 3.
164+
165+===== Nested =====
166+
167+ * Tab
168+ * Tab
169+ * Tab
170+
171+Here’s another:
172+
173+ - First
174+ - Second:
175+ * Fee
176+ * Fie
177+ * Foe
178+ - Third
179+
180+Same thing but with paragraphs:
181+
182+ - First
183+ - Second:
184+ * Fee
185+ * Fie
186+ * Foe
187+ - Third
188+
189+===== Tabs and spaces =====
190+
191+ * this is a list item indented with tabs
192+ * this is a list item indented with spaces
193+ * this is an example list item indented with tabs
194+ * this is an example list item indented with spaces
195+
196+===== Fancy list markers =====
197+
198+ - begins with 2
199+ - and now 3
200+with a continuation
201+ - sublist with roman numerals, starting with 4
202+ - more items
203+ - a subsublist
204+ - a subsublist
205+
206+Nesting:
207+
208+ - Upper Alpha
209+ - Upper Roman.
210+ - Decimal start with 6
211+ - Lower alpha with paren
212+
213+Autonumbering:
214+
215+ - Autonumber.
216+ - More.
217+ - Nested.
218+
219+Should not be a list item:
220+
221+M.A. 2007
222+
223+B. Williams
224+
225+
226+----
227+
228+====== Definition Lists ======
229+
230+Tight using spaces:
231+
232+ * **apple** red fruit
233+ * **orange** orange fruit
234+ * **banana** yellow fruit
235+
236+Tight using tabs:
237+
238+ * **apple** red fruit
239+ * **orange** orange fruit
240+ * **banana** yellow fruit
241+
242+Loose:
243+
244+ * **apple** red fruit
245+ * **orange** orange fruit
246+ * **banana** yellow fruit
247+
248+Multiple blocks with italics:
249+
250+ * **//apple//** red fruit
251+contains seeds, crisp, pleasant to taste
252+ * **//orange//** orange fruit
253+<code>{ orange code block }</code>
254+> orange block quote
255+
256+Multiple definitions, tight:
257+
258+ * **apple** red fruitcomputer
259+ * **orange** orange fruitbank
260+
261+Multiple definitions, loose:
262+
263+ * **apple** red fruitcomputer
264+ * **orange** orange fruitbank
265+
266+Blank line after term, indented marker, alternate markers:
267+
268+ * **apple** red fruitcomputer
269+ * **orange** orange fruit
270+ - sublist
271+ - sublist
272+
273+====== HTML Blocks ======
274+
275+Simple block on one line:
276+
277+foo
278+
279+And nested without indentation:
280+
281+foo
282+
283+
284+bar
285+
286+
287+Interpreted markdown in a table:
288+
289+<html>
290+<table>
291+<tr>
292+<td></html>
293+This is //emphasized//
294+<html>
295+</td>
296+<td></html>
297+And this is **strong**
298+<html>
299+</td>
300+</tr>
301+</table>
302+
303+<script type="text/javascript">document.write('This *should not* be interpreted as markdown');</script>
304+</html>
305+Here’s a simple block:
306+
307+foo
308+
309+This should be a code block, though:
310+
311+<code><div>
312+ foo
313+</div></code>
314+As should this:
315+
316+<code><div>foo</div></code>
317+Now, nested:
318+
319+foo
320+
321+
322+
323+This should just be an HTML comment:
324+
325+<html>
326+<!-- Comment -->
327+</html>
328+Multiline:
329+
330+<html>
331+<!--
332+Blah
333+Blah
334+-->
335+
336+<!--
337+ This is another comment.
338+-->
339+</html>
340+Code block:
341+
342+<code><!-- Comment --></code>
343+Just plain comment, with trailing spaces on the line:
344+
345+<html>
346+<!-- foo -->
347+</html>
348+Code:
349+
350+<code><hr /></code>
351+Hr’s:
352+
353+<html>
354+<hr>
355+
356+<hr />
357+
358+<hr />
359+
360+<hr>
361+
362+<hr />
363+
364+<hr />
365+
366+<hr class="foo" id="bar" />
367+
368+<hr class="foo" id="bar" />
369+
370+<hr class="foo" id="bar">
371+</html>
372+
373+----
374+
375+====== Inline Markup ======
376+
377+This is //emphasized//, and so //is this//.
378+
379+This is **strong**, and so **is this**.
380+
381+An //[[url|emphasized link]]//.
382+
383+**//This is strong and em.//**
384+
385+So is **//this//** word.
386+
387+**//This is strong and em.//**
388+
389+So is **//this//** word.
390+
391+This is code: ''%%>%%'', ''%%$%%'', ''%%\%%'', ''%%\$%%'', ''%%<html>%%''.
392+
393+<del>This is //strikeout//.</del>
394+
395+Superscripts: a<sup>bc</sup>d a<sup>//hello//</sup> a<sup>hello there</sup>.
396+
397+Subscripts: H<sub>2</sub>O, H<sub>23</sub>O, H<sub>many of them</sub>O.
398+
399+These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.
400+
401+
402+----
403+
404+====== Smart quotes, ellipses, dashes ======
405+
406+“Hello,” said the spider. “‘Shelob’ is my name.”
407+
408+‘A’, ‘B’, and ‘C’ are letters.
409+
410+‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. So is ‘pine.’
411+
412+‘He said, “I want to go.”’ Were you alive in the 70’s?
413+
414+Here is some quoted ‘''%%code%%''’ and a “[[http://example.com/?foo=1&bar=2|quoted link]]”.
415+
416+Some dashes: one—two — three—four — five.
417+
418+Dashes between numbers: 5–7, 255–66, 1987–1999.
419+
420+Ellipses…and…and….
421+
422+
423+----
424+
425+====== LaTeX ======
426+
427+ * \cite[22-23]{smith.1899}
428+ * <math>2+2=4</math>
429+ * <math>x \in y</math>
430+ * <math>\alpha \wedge \omega</math>
431+ * <math>223</math>
432+ * <math>p</math>-Tree
433+ * Here’s some display math: <math>\frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h}</math>
434+ * Here’s one that has a line break in it: <math>\alpha + \omega \times x^2</math>.
435+
436+These shouldn’t be math:
437+
438+ * To get the famous equation, write ''%%$e = mc^2$%%''.
439+ * $22,000 is a //lot// of money. So is $34,000. (It worked if “lot” is emphasized.)
440+ * Shoes ($20) and socks ($5).
441+ * Escaped ''%%$%%'': $73 //this should be emphasized// 23$.
442+
443+Here’s a LaTeX table:
444+
445+\begin{tabular}{|l|l|}\hline
446+Animal & Number \\ \hline
447+Dog & 2 \\
448+Cat & 1 \\ \hline
449+\end{tabular}
450+
451+----
452+
453+====== Special Characters ======
454+
455+Here is some unicode:
456+
457+ * I hat: Î
458+ * o umlaut: ö
459+ * section: §
460+ * set membership: ∈
461+ * copyright: ©
462+
463+AT&T has an ampersand in their name.
464+
465+AT&T is another way to write it.
466+
467+This & that.
468+
469+4 < 5.
470+
471+6 > 5.
472+
473+Backslash: \
474+
475+Backtick: `
476+
477+Asterisk: *
478+
479+Underscore: _
480+
481+Left brace: {
482+
483+Right brace: }
484+
485+Left bracket: [
486+
487+Right bracket: ]
488+
489+Left paren: (
490+
491+Right paren: )
492+
493+Greater-than: >
494+
495+Hash: #
496+
497+Period: .
498+
499+Bang: !
500+
501+Plus: +
502+
503+Minus: -
504+
505+
506+----
507+
508+====== Links ======
509+
510+===== Explicit =====
511+
512+Just a [[url/|URL]].
513+
514+[[url/|URL and title]].
515+
516+[[url/|URL and title]].
517+
518+[[url/|URL and title]].
519+
520+[[url/|URL and title]]
521+
522+[[url/|URL and title]]
523+
524+[[url/with_underscore|with_underscore]]
525+
526+[[mailto:nobody@nowhere.net|Email link]]
527+
528+[[|Empty]].
529+
530+===== Reference =====
531+
532+Foo [[url/|bar]].
533+
534+Foo [[url/|bar]].
535+
536+Foo [[url/|bar]].
537+
538+With [[url/|embedded [brackets]]].
539+
540+[[url/|b]] by itself should be a link.
541+
542+Indented [[url|once]].
543+
544+Indented [[url|twice]].
545+
546+Indented [[url|thrice]].
547+
548+This should [not][] be a link.
549+
550+<code>[not]: /url</code>
551+Foo [[url/|bar]].
552+
553+Foo [[url/|biz]].
554+
555+===== With ampersands =====
556+
557+Here’s a [[http://example.com/?foo=1&bar=2|link with an ampersand in the URL]].
558+
559+Here’s a link with an amersand in the link text: [[http://att.com/|AT&T]].
560+
561+Here’s an [[script?foo=1&bar=2|inline link]].
562+
563+Here’s an [[script?foo=1&bar=2|inline link in pointy braces]].
564+
565+===== Autolinks =====
566+
567+With an ampersand: http://example.com/?foo=1&bar=2
568+
569+ * In a list?
570+ * http://example.com/
571+ * It should.
572+
573+An e-mail address: [[mailto:nobody@nowhere.net|nobody@nowhere.net]]
574+
575+> Blockquoted: http://example.com/
576+
577+Auto-links should not occur here: ''%%<http://example.com/>%%''
578+
579+<code>or here: <http://example.com/></code>
580+
581+----
582+
583+====== Images ======
584+
585+From “Voyage dans la Lune” by Georges Melies (1902):
586+
587+{{:lalune.jpg|Voyage dans la Lune lalune}}
588+
589+Here is a movie {{:movie.jpg|movie}} icon.
590+
591+
592+----
593+
594+====== Footnotes ======
595+
596+Here is a footnote reference,((Here is the footnote. It can go anywhere after the footnote reference. It need not be placed at the end of the document.
597+)) and another.((Here’s the long note. This one contains multiple blocks.
598+
599+Subsequent blocks are indented to show that they belong to the footnote (as with list items).
600+
601+<code> { <code> }</code>
602+If you want, you can indent every line, but you can also be lazy and just indent the first line of each block.
603+)) This should //not// be a footnote reference, because it contains a space.[^my note] Here is an inline note.((This is //easier// to type. Inline notes may contain [[http://google.com|links]] and ''%%]%%'' verbatim characters, as well as [bracketed text].
604+))
605+
606+> Notes can go in quotes.((In quote.
607+))
608+
609+ - And in list items.((In list.))
610+
611+This paragraph should not be part of the note, as it is not indented.