git.iko.soy/typeable/pandoc
on master help sign in
Updated DokuWiki code and tests to work with latest code from jgm.

The new code was got from inspecting changes in MediaWiki.hs This slightly changes the output of Div blocks, but I'm not convinced the original behaviour was really correct anyway. The code for handling Span does nothing for now, until I can work out the desired behaviour, and add tests for it.

commitfdbf52b1cca7d923924ef5d970d946ba6369d6c5 authorClare Macrae <github@cfmacrae.fastmail.co.uk> dateSun 29 Jun 2014, 21:15 (12 years ago) parent717e166
2 files changed+25−15
src/Text/Pandoc/Writers/DokuWiki.hs+22−6 tests/writer.dokuwiki+3−9
src/Text/Pandoc/Writers/DokuWiki.hs+22−6
@@ -31,6 +31,7 @@ DokuWiki: <https://www.dokuwiki.org/dokuwiki>
3131-}
3232
3333{-
34+ [ ] Correct handling of Span
3435 [ ] Don't generate <blockquote>...
3536 [ ] Don't generate lists using <ol> and <ul>
3637 [ ] Don't generate <div>
@@ -46,6 +47,7 @@ import Text.Pandoc.Definition
4647import Text.Pandoc.Options
4748import Text.Pandoc.Shared
4849import Text.Pandoc.Writers.Shared
50+import Text.Pandoc.Pretty (render)
4951import Text.Pandoc.Templates (renderTemplate')
5052import Data.List ( intersect, intercalate )
5153import Network.URI ( isURI )
@@ -95,6 +97,11 @@ blockToDokuWiki :: WriterOptions -- ^ Options
9597
9698blockToDokuWiki _ Null = return ""
9799
100+blockToDokuWiki opts (Div attrs bs) = do
101+ contents <- blockListToDokuWiki opts bs
102+ return $ render Nothing (tagWithAttrs "div" attrs) ++ "\n" ++
103+ contents ++ "\n" ++ "</div>"
104+
98105blockToDokuWiki opts (Plain inlines) =
99106 inlineListToDokuWiki opts inlines
100107
@@ -117,9 +124,10 @@ blockToDokuWiki opts (Para inlines) = do
117124 then "<p>" ++ contents ++ "</p>"
118125 else contents ++ if null indent then "\n" else ""
119126
120−blockToDokuWiki _ (RawBlock "mediawiki" str) = return str
121−blockToDokuWiki _ (RawBlock "html" str) = return str
122−blockToDokuWiki _ (RawBlock _ _) = return ""
127+blockToDokuWiki _ (RawBlock f str)
128+ | f == Format "mediawiki" = return str
129+ | f == Format "html" = return str
130+ | otherwise = return ""
123131
124132blockToDokuWiki _ HorizontalRule = return "\n----\n"
125133
@@ -370,6 +378,13 @@ inlineListToDokuWiki opts lst = mapM (inlineToDokuWiki opts) lst >>= return . co
370378-- | Convert Pandoc inline element to DokuWiki.
371379inlineToDokuWiki :: WriterOptions -> Inline -> State WriterState String
372380
381+inlineToDokuWiki opts (Span attrs ils) = do
382+ return ""
383+ {-
384+ contents <- inlineListToDokuWiki opts ils
385+ return $ render Nothing (tagWithAttrs "span" attrs) ++ contents ++ "</span>"
386+ -}
387+
373388inlineToDokuWiki opts (Emph lst) = do
374389 contents <- inlineListToDokuWiki opts lst
375390 return $ "//" ++ contents ++ "//"
@@ -419,9 +434,10 @@ inlineToDokuWiki _ (Str str) = return $ escapeString str
419434inlineToDokuWiki _ (Math _ str) = return $ "<math>" ++ str ++ "</math>"
420435 -- note: str should NOT be escaped
421436
422−inlineToDokuWiki _ (RawInline "mediawiki" str) = return str
423−inlineToDokuWiki _ (RawInline "html" str) = return str
424−inlineToDokuWiki _ (RawInline _ _) = return ""
437+inlineToDokuWiki _ (RawInline f str)
438+ | f == Format "mediawiki" = return str
439+ | f == Format "html" = return str
440+ | otherwise = return ""
425441
426442inlineToDokuWiki _ (LineBreak) = return "\\\\ "
427443
tests/writer.dokuwiki+3−9
@@ -277,7 +277,6 @@ Simple block on one line:
277277<div>
278278foo
279279</div>
280−
281280And nested without indentation:
282281
283282<div>
@@ -290,7 +289,6 @@ foo
290289bar
291290</div>
292291</div>
293−
294292Interpreted markdown in a table:
295293
296294<table>
@@ -309,10 +307,8 @@ And this is **strong**
309307Here’s a simple block:
310308
311309<div>
312−
313310foo
314311</div>
315−
316312This should be a code block, though:
317313
318314<code><div>
@@ -324,14 +320,12 @@ As should this:
324320Now, nested:
325321
326322<div>
327− <div>
328− <div>
329−
323+<div>
324+<div>
330325foo
331326</div>
332− </div>
333327</div>
334−
328+</div>
335329This should just be an HTML comment:
336330
337331<!-- Comment -->