From 81088281dea1283159f7e0cf3d9c2a5082e06d8a Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 13 Jul 2014 16:04:29 -0700 Subject: 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) --- src/Text/Pandoc/Writers/DokuWiki.hs | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Writers/DokuWiki.hs b/src/Text/Pandoc/Writers/DokuWiki.hs index c7b723a21..aef247164 100644 --- a/src/Text/Pandoc/Writers/DokuWiki.hs +++ b/src/Text/Pandoc/Writers/DokuWiki.hs @@ -113,11 +113,11 @@ blockToDokuWiki opts (Para [Image txt (src,'f':'i':'g':':':tit)]) = do return $ "{{:" ++ src ++ opt ++ "}}\n" blockToDokuWiki opts (Para inlines) = do - useTags <- get >>= return . stUseTags - indent <- get >>= return . stIndent + indent <- gets stIndent + useTags <- gets stUseTags contents <- inlineListToDokuWiki opts inlines return $ if useTags - then "

" ++ contents ++ "

" + then "

" ++ contents ++ "

" else contents ++ if null indent then "\n" else "" blockToDokuWiki _ (RawBlock f str) @@ -180,7 +180,7 @@ blockToDokuWiki opts x@(BulletList items) = do modify $ \s -> s { stUseTags = True } contents <- mapM (listItemToDokuWiki opts) items modify $ \s -> s { stUseTags = oldUseTags } - return $ "\n" + return $ "\n" else do modify $ \s -> s { stIndent = stIndent s ++ " " } contents <- mapM (listItemToDokuWiki opts) items @@ -196,7 +196,7 @@ blockToDokuWiki opts x@(OrderedList attribs items) = do modify $ \s -> s { stUseTags = True } contents <- mapM (orderedListItemToDokuWiki opts) items modify $ \s -> s { stUseTags = oldUseTags } - return $ "\n" ++ vcat contents ++ "\n" + return $ "\n" ++ vcat contents ++ "\n" else do modify $ \s -> s { stIndent = stIndent s ++ " " } contents <- mapM (orderedListItemToDokuWiki opts) items @@ -215,7 +215,7 @@ blockToDokuWiki opts x@(DefinitionList items) = do modify $ \s -> s { stUseTags = True } contents <- mapM (definitionListItemToDokuWiki opts) items modify $ \s -> s { stUseTags = oldUseTags } - return $ "
\n" ++ vcat contents ++ "
\n" + return $ "
\n" ++ vcat contents ++ "
\n" else do modify $ \s -> s { stIndent = stIndent s ++ " " } contents <- mapM (definitionListItemToDokuWiki opts) items @@ -241,7 +241,7 @@ listItemToDokuWiki opts items = do contents <- blockListToDokuWiki opts items useTags <- get >>= return . stUseTags if useTags - then return $ "
  • " ++ contents ++ "
  • " + then return $ "
  • " ++ contents ++ "
  • " else do indent <- get >>= return . stIndent return $ indent ++ "* " ++ contents @@ -253,7 +253,7 @@ orderedListItemToDokuWiki opts items = do contents <- blockListToDokuWiki opts items useTags <- get >>= return . stUseTags if useTags - then return $ "
  • " ++ contents ++ "
  • " + then return $ "
  • " ++ contents ++ "
  • " else do indent <- get >>= return . stIndent return $ indent ++ "- " ++ contents @@ -267,8 +267,8 @@ definitionListItemToDokuWiki opts (label, items) = do contents <- mapM (blockListToDokuWiki opts) items useTags <- get >>= return . stUseTags if useTags - then return $ "
    " ++ labelText ++ "
    \n" ++ - (intercalate "\n" $ map (\d -> "
    " ++ d ++ "
    ") contents) + then return $ "
    " ++ labelText ++ "
    \n" ++ + (intercalate "\n" $ map (\d -> "
    " ++ d ++ "
    ") contents) else do indent <- get >>= return . stIndent return $ indent ++ "* **" ++ labelText ++ "** " ++ concat contents @@ -277,11 +277,38 @@ definitionListItemToDokuWiki opts (label, items) = do isSimpleList :: Block -> Bool isSimpleList x = case x of - BulletList _ -> True - OrderedList _ _ -> True - DefinitionList _ -> True + BulletList items -> all isSimpleListItem items + OrderedList (num, sty, _) items -> all isSimpleListItem items && + num == 1 && sty `elem` [DefaultStyle, Decimal] + DefinitionList items -> all isSimpleListItem $ concatMap snd items _ -> False +-- | True if list item can be handled with the simple wiki syntax. False if +-- HTML tags will be needed. +isSimpleListItem :: [Block] -> Bool +isSimpleListItem [] = True +isSimpleListItem [x] = + case x of + Plain _ -> True + Para _ -> True + BulletList _ -> isSimpleList x + OrderedList _ _ -> isSimpleList x + DefinitionList _ -> isSimpleList x + _ -> False +isSimpleListItem [x, y] | isPlainOrPara x = + case y of + BulletList _ -> isSimpleList y + OrderedList _ _ -> isSimpleList y + DefinitionList _ -> isSimpleList y + _ -> False +isSimpleListItem _ = False + +isPlainOrPara :: Block -> Bool +isPlainOrPara (Plain _) = True +isPlainOrPara (Para _) = True +isPlainOrPara _ = False + + -- | Concatenates strings with line breaks between them. vcat :: [String] -> String vcat = intercalate "\n" -- cgit v1.2.3