git.iko.soy/typeable/pandoc
on master help sign in
DokuWiki writer: Use raw HTML for complex lists...

as in the mediawiki writer. The dokuwiki markup isn't able to handle multiple block-level items within a list item, except in a few special cases (e.g. code blocks, and these must be started on the same line as the preceding paragraph). So we fall back to raw HTML for these. Perhaps there is a better solution. We can "fake" multiple paragraphs within list items using hard line breaks (`\\`), but we must keep everything on one line. (#1398)

commit81088281dea1283159f7e0cf3d9c2a5082e06d8a authorJohn MacFarlane <jgm@berkeley.edu> dateSun 13 Jul 2014, 16:04 (12 years ago) parent0ba2f0b
2 files changed+75−32
src/Text/Pandoc/Writers/DokuWiki.hs+40−13 tests/writer.dokuwiki+35−19
src/Text/Pandoc/Writers/DokuWiki.hs+40−13
@@ -113,11 +113,11 @@ blockToDokuWiki opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
113113 return $ "{{:" ++ src ++ opt ++ "}}\n"
114114
115115blockToDokuWiki opts (Para inlines) = do
116− useTags <- get >>= return . stUseTags
117− indent <- get >>= return . stIndent
116+ indent <- gets stIndent
117+ useTags <- gets stUseTags
118118 contents <- inlineListToDokuWiki opts inlines
119119 return $ if useTags
120− then "<p>" ++ contents ++ "</p>"
120+ then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
121121 else contents ++ if null indent then "\n" else ""
122122
123123blockToDokuWiki _ (RawBlock f str)
@@ -180,7 +180,7 @@ blockToDokuWiki opts x@(BulletList items) = do
180180 modify $ \s -> s { stUseTags = True }
181181 contents <- mapM (listItemToDokuWiki opts) items
182182 modify $ \s -> s { stUseTags = oldUseTags }
183− return $ "<ul>\n" ++ vcat contents ++ "</ul>\n"
183+ return $ "<HTML><ul></HTML>\n" ++ vcat contents ++ "<HTML></ul></HTML>\n"
184184 else do
185185 modify $ \s -> s { stIndent = stIndent s ++ " " }
186186 contents <- mapM (listItemToDokuWiki opts) items
@@ -196,7 +196,7 @@ blockToDokuWiki opts x@(OrderedList attribs items) = do
196196 modify $ \s -> s { stUseTags = True }
197197 contents <- mapM (orderedListItemToDokuWiki opts) items
198198 modify $ \s -> s { stUseTags = oldUseTags }
199− return $ "<ol" ++ listAttribsToString attribs ++ ">\n" ++ vcat contents ++ "</ol>\n"
199+ return $ "<HTML><ol" ++ listAttribsToString attribs ++ "></HTML>\n" ++ vcat contents ++ "<HTML></ol></HTML>\n"
200200 else do
201201 modify $ \s -> s { stIndent = stIndent s ++ " " }
202202 contents <- mapM (orderedListItemToDokuWiki opts) items
@@ -215,7 +215,7 @@ blockToDokuWiki opts x@(DefinitionList items) = do
215215 modify $ \s -> s { stUseTags = True }
216216 contents <- mapM (definitionListItemToDokuWiki opts) items
217217 modify $ \s -> s { stUseTags = oldUseTags }
218− return $ "<dl>\n" ++ vcat contents ++ "</dl>\n"
218+ return $ "<HTML><dl></HTML>\n" ++ vcat contents ++ "<HTML></dl></HTML>\n"
219219 else do
220220 modify $ \s -> s { stIndent = stIndent s ++ " " }
221221 contents <- mapM (definitionListItemToDokuWiki opts) items
@@ -241,7 +241,7 @@ listItemToDokuWiki opts items = do
241241 contents <- blockListToDokuWiki opts items
242242 useTags <- get >>= return . stUseTags
243243 if useTags
244− then return $ "<li>" ++ contents ++ "</li>"
244+ then return $ "<HTML><li></HTML>" ++ contents ++ "<HTML></li></HTML>"
245245 else do
246246 indent <- get >>= return . stIndent
247247 return $ indent ++ "* " ++ contents
@@ -253,7 +253,7 @@ orderedListItemToDokuWiki opts items = do
253253 contents <- blockListToDokuWiki opts items
254254 useTags <- get >>= return . stUseTags
255255 if useTags
256− then return $ "<li>" ++ contents ++ "</li>"
256+ then return $ "<HTML><li></HTML>" ++ contents ++ "<HTML></li></HTML>"
257257 else do
258258 indent <- get >>= return . stIndent
259259 return $ indent ++ "- " ++ contents
@@ -267,8 +267,8 @@ definitionListItemToDokuWiki opts (label, items) = do
267267 contents <- mapM (blockListToDokuWiki opts) items
268268 useTags <- get >>= return . stUseTags
269269 if useTags
270− then return $ "<dt>" ++ labelText ++ "</dt>\n" ++
271− (intercalate "\n" $ map (\d -> "<dd>" ++ d ++ "</dd>") contents)
270+ then return $ "<HTML><dt></HTML>" ++ labelText ++ "<HTML></dt></HTML>\n" ++
271+ (intercalate "\n" $ map (\d -> "<HTML><dd></HTML>" ++ d ++ "<HTML></dd></HTML>") contents)
272272 else do
273273 indent <- get >>= return . stIndent
274274 return $ indent ++ "* **" ++ labelText ++ "** " ++ concat contents
@@ -277,11 +277,38 @@ definitionListItemToDokuWiki opts (label, items) = do
277277isSimpleList :: Block -> Bool
278278isSimpleList x =
279279 case x of
280− BulletList _ -> True
281− OrderedList _ _ -> True
282− DefinitionList _ -> True
280+ BulletList items -> all isSimpleListItem items
281+ OrderedList (num, sty, _) items -> all isSimpleListItem items &&
282+ num == 1 && sty `elem` [DefaultStyle, Decimal]
283+ DefinitionList items -> all isSimpleListItem $ concatMap snd items
283284 _ -> False
284285
286+-- | True if list item can be handled with the simple wiki syntax. False if
287+-- HTML tags will be needed.
288+isSimpleListItem :: [Block] -> Bool
289+isSimpleListItem [] = True
290+isSimpleListItem [x] =
291+ case x of
292+ Plain _ -> True
293+ Para _ -> True
294+ BulletList _ -> isSimpleList x
295+ OrderedList _ _ -> isSimpleList x
296+ DefinitionList _ -> isSimpleList x
297+ _ -> False
298+isSimpleListItem [x, y] | isPlainOrPara x =
299+ case y of
300+ BulletList _ -> isSimpleList y
301+ OrderedList _ _ -> isSimpleList y
302+ DefinitionList _ -> isSimpleList y
303+ _ -> False
304+isSimpleListItem _ = False
305+
306+isPlainOrPara :: Block -> Bool
307+isPlainOrPara (Plain _) = True
308+isPlainOrPara (Para _) = True
309+isPlainOrPara _ = False
310+
311+
285312-- | Concatenates strings with line breaks between them.
286313vcat :: [String] -> String
287314vcat = intercalate "\n"
tests/writer.dokuwiki+35−19
@@ -157,10 +157,11 @@ and using spaces:
157157
158158Multiple paragraphs:
159159
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.
160+<HTML><ol style="list-style-type: decimal;"></HTML>
161+<HTML><li></HTML><HTML><p></HTML>Item 1, graf one.<HTML></p></HTML>
162+<HTML><p></HTML>Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.<HTML></p></HTML><HTML></li></HTML>
163+<HTML><li></HTML><HTML><p></HTML>Item 2.<HTML></p></HTML><HTML></li></HTML>
164+<HTML><li></HTML><HTML><p></HTML>Item 3.<HTML></p></HTML><HTML></li></HTML><HTML></ol></HTML>
164165
165166===== Nested =====
166167
@@ -195,20 +196,32 @@ Same thing but with paragraphs:
195196
196197===== Fancy list markers =====
197198
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
199+<HTML><ol start="2" style="list-style-type: decimal;"></HTML>
200+<HTML><li></HTML>begins with 2<HTML></li></HTML>
201+<HTML><li></HTML><HTML><p></HTML>and now 3<HTML></p></HTML>
202+<HTML><p></HTML>with a continuation<HTML></p></HTML>
203+<HTML><ol start="4" style="list-style-type: lower-roman;"></HTML>
204+<HTML><li></HTML>sublist with roman numerals, starting with 4<HTML></li></HTML>
205+<HTML><li></HTML>more items
206+<HTML><ol style="list-style-type: upper-alpha;"></HTML>
207+<HTML><li></HTML>a subsublist<HTML></li></HTML>
208+<HTML><li></HTML>a subsublist<HTML></li></HTML><HTML></ol></HTML>
209+<HTML></li></HTML><HTML></ol></HTML>
210+<HTML></li></HTML><HTML></ol></HTML>
205211
206212Nesting:
207213
208− - Upper Alpha
209− - Upper Roman.
210− - Decimal start with 6
211− - Lower alpha with paren
214+<HTML><ol style="list-style-type: upper-alpha;"></HTML>
215+<HTML><li></HTML>Upper Alpha
216+<HTML><ol style="list-style-type: upper-roman;"></HTML>
217+<HTML><li></HTML>Upper Roman.
218+<HTML><ol start="6" style="list-style-type: decimal;"></HTML>
219+<HTML><li></HTML>Decimal start with 6
220+<HTML><ol start="3" style="list-style-type: lower-alpha;"></HTML>
221+<HTML><li></HTML>Lower alpha with paren<HTML></li></HTML><HTML></ol></HTML>
222+<HTML></li></HTML><HTML></ol></HTML>
223+<HTML></li></HTML><HTML></ol></HTML>
224+<HTML></li></HTML><HTML></ol></HTML>
212225
213226Autonumbering:
214227
@@ -247,11 +260,14 @@ Loose:
247260
248261Multiple blocks with italics:
249262
250− * **//apple//** red fruit
251−contains seeds, crisp, pleasant to taste
252− * **//orange//** orange fruit
263+<HTML><dl></HTML>
264+<HTML><dt></HTML>//apple//<HTML></dt></HTML>
265+<HTML><dd></HTML><HTML><p></HTML>red fruit<HTML></p></HTML>
266+<HTML><p></HTML>contains seeds, crisp, pleasant to taste<HTML></p></HTML><HTML></dd></HTML>
267+<HTML><dt></HTML>//orange//<HTML></dt></HTML>
268+<HTML><dd></HTML><HTML><p></HTML>orange fruit<HTML></p></HTML>
253269<code>{ orange code block }</code>
254−> orange block quote
270+> <HTML><p></HTML>orange block quote<HTML></p></HTML><HTML></dd></HTML><HTML></dl></HTML>
255271
256272Multiple definitions, tight:
257273