git.iko.soy/typeable/pandoc
on master help sign in
DokuWiki writer: Use raw HTML for complex lists...
8108828John MacFarlane
src/Text/Pandoc/Writers/DokuWiki.hs+40−13
@@ -113,11 +113,11 @@ blockToDokuWiki opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do
113 return $ "{{:" ++ src ++ opt ++ "}}\n"
113 return $ "{{:" ++ src ++ opt ++ "}}\n"
114
114
115blockToDokuWiki opts (Para inlines) = do
115blockToDokuWiki opts (Para inlines) = do
116+ indent <- gets stIndent
116− useTags <- get >>= return . stUseTags
117+ useTags <- gets stUseTags
117− indent <- get >>= return . stIndent
118 contents <- inlineListToDokuWiki opts inlines
118 contents <- inlineListToDokuWiki opts inlines
119 return $ if useTags
119 return $ if useTags
120− then "<p>" ++ contents ++ "</p>"
120+ then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
121 else contents ++ if null indent then "\n" else ""
121 else contents ++ if null indent then "\n" else ""
122
122
123blockToDokuWiki _ (RawBlock f str)
123blockToDokuWiki _ (RawBlock f str)
@@ -180,7 +180,7 @@ blockToDokuWiki opts x@(BulletList items) = do
180 modify $ \s -> s { stUseTags = True }
180 modify $ \s -> s { stUseTags = True }
181 contents <- mapM (listItemToDokuWiki opts) items
181 contents <- mapM (listItemToDokuWiki opts) items
182 modify $ \s -> s { stUseTags = oldUseTags }
182 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"
184 else do
184 else do
185 modify $ \s -> s { stIndent = stIndent s ++ " " }
185 modify $ \s -> s { stIndent = stIndent s ++ " " }
186 contents <- mapM (listItemToDokuWiki opts) items
186 contents <- mapM (listItemToDokuWiki opts) items
@@ -196,7 +196,7 @@ blockToDokuWiki opts x@(OrderedList attribs items) = do
196 modify $ \s -> s { stUseTags = True }
196 modify $ \s -> s { stUseTags = True }
197 contents <- mapM (orderedListItemToDokuWiki opts) items
197 contents <- mapM (orderedListItemToDokuWiki opts) items
198 modify $ \s -> s { stUseTags = oldUseTags }
198 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"
200 else do
200 else do
201 modify $ \s -> s { stIndent = stIndent s ++ " " }
201 modify $ \s -> s { stIndent = stIndent s ++ " " }
202 contents <- mapM (orderedListItemToDokuWiki opts) items
202 contents <- mapM (orderedListItemToDokuWiki opts) items
@@ -215,7 +215,7 @@ blockToDokuWiki opts x@(DefinitionList items) = do
215 modify $ \s -> s { stUseTags = True }
215 modify $ \s -> s { stUseTags = True }
216 contents <- mapM (definitionListItemToDokuWiki opts) items
216 contents <- mapM (definitionListItemToDokuWiki opts) items
217 modify $ \s -> s { stUseTags = oldUseTags }
217 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"
219 else do
219 else do
220 modify $ \s -> s { stIndent = stIndent s ++ " " }
220 modify $ \s -> s { stIndent = stIndent s ++ " " }
221 contents <- mapM (definitionListItemToDokuWiki opts) items
221 contents <- mapM (definitionListItemToDokuWiki opts) items
@@ -241,7 +241,7 @@ listItemToDokuWiki opts items = do
241 contents <- blockListToDokuWiki opts items
241 contents <- blockListToDokuWiki opts items
242 useTags <- get >>= return . stUseTags
242 useTags <- get >>= return . stUseTags
243 if useTags
243 if useTags
244− then return $ "<li>" ++ contents ++ "</li>"
244+ then return $ "<HTML><li></HTML>" ++ contents ++ "<HTML></li></HTML>"
245 else do
245 else do
246 indent <- get >>= return . stIndent
246 indent <- get >>= return . stIndent
247 return $ indent ++ "* " ++ contents
247 return $ indent ++ "* " ++ contents
@@ -253,7 +253,7 @@ orderedListItemToDokuWiki opts items = do
253 contents <- blockListToDokuWiki opts items
253 contents <- blockListToDokuWiki opts items
254 useTags <- get >>= return . stUseTags
254 useTags <- get >>= return . stUseTags
255 if useTags
255 if useTags
256− then return $ "<li>" ++ contents ++ "</li>"
256+ then return $ "<HTML><li></HTML>" ++ contents ++ "<HTML></li></HTML>"
257 else do
257 else do
258 indent <- get >>= return . stIndent
258 indent <- get >>= return . stIndent
259 return $ indent ++ "- " ++ contents
259 return $ indent ++ "- " ++ contents
@@ -267,8 +267,8 @@ definitionListItemToDokuWiki opts (label, items) = do
267 contents <- mapM (blockListToDokuWiki opts) items
267 contents <- mapM (blockListToDokuWiki opts) items
268 useTags <- get >>= return . stUseTags
268 useTags <- get >>= return . stUseTags
269 if useTags
269 if useTags
270− then return $ "<dt>" ++ labelText ++ "</dt>\n" ++
270+ then return $ "<HTML><dt></HTML>" ++ labelText ++ "<HTML></dt></HTML>\n" ++
271− (intercalate "\n" $ map (\d -> "<dd>" ++ d ++ "</dd>") contents)
271+ (intercalate "\n" $ map (\d -> "<HTML><dd></HTML>" ++ d ++ "<HTML></dd></HTML>") contents)
272 else do
272 else do
273 indent <- get >>= return . stIndent
273 indent <- get >>= return . stIndent
274 return $ indent ++ "* **" ++ labelText ++ "** " ++ concat contents
274 return $ indent ++ "* **" ++ labelText ++ "** " ++ concat contents
@@ -277,11 +277,38 @@ definitionListItemToDokuWiki opts (label, items) = do
277isSimpleList :: Block -> Bool
277isSimpleList :: Block -> Bool
278isSimpleList x =
278isSimpleList x =
279 case x of
279 case x of
280− BulletList _ -> True
280+ BulletList items -> all isSimpleListItem items
281− OrderedList _ _ -> True
281+ OrderedList (num, sty, _) items -> all isSimpleListItem items &&
282− DefinitionList _ -> True
282+ num == 1 && sty `elem` [DefaultStyle, Decimal]
283+ DefinitionList items -> all isSimpleListItem $ concatMap snd items
283 _ -> False
284 _ -> False
284
285
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+
285-- | Concatenates strings with line breaks between them.
312-- | Concatenates strings with line breaks between them.
286vcat :: [String] -> String
313vcat :: [String] -> String
287vcat = intercalate "\n"
314vcat = intercalate "\n"
tests/writer.dokuwiki+35−19
@@ -157,10 +157,11 @@ and using spaces:
157
157
158Multiple paragraphs:
158Multiple paragraphs:
159
159
160+<HTML><ol style="list-style-type: decimal;"></HTML>
160− - Item 1, graf one.
161+<HTML><li></HTML><HTML><p></HTML>Item 1, graf one.<HTML></p></HTML>
161−Item 1. graf two. The quick brown fox jumped over the lazy dog’s back.
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>
162− - Item 2.
163+<HTML><li></HTML><HTML><p></HTML>Item 2.<HTML></p></HTML><HTML></li></HTML>
163− - Item 3.
164+<HTML><li></HTML><HTML><p></HTML>Item 3.<HTML></p></HTML><HTML></li></HTML><HTML></ol></HTML>
164
165
165===== Nested =====
166===== Nested =====
166
167
@@ -195,20 +196,32 @@ Same thing but with paragraphs:
195
196
196===== Fancy list markers =====
197===== Fancy list markers =====
197
198
199+<HTML><ol start="2" style="list-style-type: decimal;"></HTML>
198− - begins with 2
200+<HTML><li></HTML>begins with 2<HTML></li></HTML>
199− - and now 3
201+<HTML><li></HTML><HTML><p></HTML>and now 3<HTML></p></HTML>
200−with a continuation
202+<HTML><p></HTML>with a continuation<HTML></p></HTML>
203+<HTML><ol start="4" style="list-style-type: lower-roman;"></HTML>
201− - sublist with roman numerals, starting with 4
204+<HTML><li></HTML>sublist with roman numerals, starting with 4<HTML></li></HTML>
202− - more items
205+<HTML><li></HTML>more items
206+<HTML><ol style="list-style-type: upper-alpha;"></HTML>
203− - a subsublist
207+<HTML><li></HTML>a subsublist<HTML></li></HTML>
204− - a subsublist
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>
205
211
206Nesting:
212Nesting:
207
213
214+<HTML><ol style="list-style-type: upper-alpha;"></HTML>
208− - Upper Alpha
215+<HTML><li></HTML>Upper Alpha
216+<HTML><ol style="list-style-type: upper-roman;"></HTML>
209− - Upper Roman.
217+<HTML><li></HTML>Upper Roman.
218+<HTML><ol start="6" style="list-style-type: decimal;"></HTML>
210− - Decimal start with 6
219+<HTML><li></HTML>Decimal start with 6
220+<HTML><ol start="3" style="list-style-type: lower-alpha;"></HTML>
211− - Lower alpha with paren
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>
212
225
213Autonumbering:
226Autonumbering:
214
227
@@ -247,11 +260,14 @@ Loose:
247
260
248Multiple blocks with italics:
261Multiple blocks with italics:
249
262
250− * **//apple//** red 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>
251−contains seeds, crisp, pleasant to taste
266+<HTML><p></HTML>contains seeds, crisp, pleasant to taste<HTML></p></HTML><HTML></dd></HTML>
252− * **//orange//** orange fruit
267+<HTML><dt></HTML>//orange//<HTML></dt></HTML>
268+<HTML><dd></HTML><HTML><p></HTML>orange fruit<HTML></p></HTML>
253<code>{ orange code block }</code>
269<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>
255
271
256Multiple definitions, tight:
272Multiple definitions, tight:
257
273