git.iko.soy/typeable/pandoc
on master help sign in
Move `compactify'DL` from Markdown reader into Shared
efebadeAlbert Krewinkel
src/Text/Pandoc/Readers/Markdown.hs−17
@@ -861,22 +861,6 @@ definitionList = do
861 items <- fmap sequence $ many1 definitionListItem
861 items <- fmap sequence $ many1 definitionListItem
862 return $ B.definitionList <$> fmap compactify'DL items
862 return $ B.definitionList <$> fmap compactify'DL items
863
863
864−compactify'DL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
865−compactify'DL items =
866− let defs = concatMap snd items
867− defBlocks = reverse $ concatMap B.toList defs
868− isPara (Para _) = True
869− isPara _ = False
870− in case defBlocks of
871− (Para x:_) -> if not $ any isPara (drop 1 defBlocks)
872− then let (t,ds) = last items
873− lastDef = B.toList $ last ds
874− ds' = init ds ++
875− [B.fromList $ init lastDef ++ [Plain x]]
876− in init items ++ [(t, ds')]
877− else items
878− _ -> items
879−
880--
864--
881-- paragraph block
865-- paragraph block
882--
866--
@@ -1892,4 +1876,3 @@ doubleQuoted = try $ do
1892 (withQuoteContext InDoubleQuote $ doubleQuoteEnd >> return
1876 (withQuoteContext InDoubleQuote $ doubleQuoteEnd >> return
1893 (fmap B.doubleQuoted . trimInlinesF $ contents))
1877 (fmap B.doubleQuoted . trimInlinesF $ contents))
1894 <|> (return $ return (B.str "\8220") <> contents)
1878 <|> (return $ return (B.str "\8220") <> contents)
1895−
src/Text/Pandoc/Shared.hs+17−3
@@ -56,6 +56,7 @@ module Text.Pandoc.Shared (
56 stringify,
56 stringify,
57 compactify,
57 compactify,
58 compactify',
58 compactify',
59+ compactify'DL,
59 Element (..),
60 Element (..),
60 hierarchicalize,
61 hierarchicalize,
61 uniqueIdent,
62 uniqueIdent,
@@ -82,7 +83,7 @@ module Text.Pandoc.Shared (
82import Text.Pandoc.Definition
83import Text.Pandoc.Definition
83import Text.Pandoc.Walk
84import Text.Pandoc.Walk
84import Text.Pandoc.Generic
85import Text.Pandoc.Generic
85−import Text.Pandoc.Builder (Blocks, ToMetaValue(..))
86+import Text.Pandoc.Builder (Inlines, Blocks, ToMetaValue(..))
86import qualified Text.Pandoc.Builder as B
87import qualified Text.Pandoc.Builder as B
87import qualified Text.Pandoc.UTF8 as UTF8
88import qualified Text.Pandoc.UTF8 as UTF8
88import System.Environment (getProgName)
89import System.Environment (getProgName)
@@ -435,6 +436,21 @@ compactify' items =
435 _ -> items
436 _ -> items
436 _ -> items
437 _ -> items
437
438
439+-- | Like @compactify'@, but akts on items of definition lists.
440+compactify'DL :: [(Inlines, [Blocks])] -> [(Inlines, [Blocks])]
441+compactify'DL items =
442+ let defs = concatMap snd items
443+ defBlocks = reverse $ concatMap B.toList defs
444+ in case defBlocks of
445+ (Para x:_) -> if not $ any isPara (drop 1 defBlocks)
446+ then let (t,ds) = last items
447+ lastDef = B.toList $ last ds
448+ ds' = init ds ++
449+ [B.fromList $ init lastDef ++ [Plain x]]
450+ in init items ++ [(t, ds')]
451+ else items
452+ _ -> items
453+
438isPara :: Block -> Bool
454isPara :: Block -> Bool
439isPara (Para _) = True
455isPara (Para _) = True
440isPara _ = False
456isPara _ = False
@@ -698,5 +714,3 @@ safeRead s = case reads s of
698 (d,x):_
714 (d,x):_
699 | all isSpace x -> return d
715 | all isSpace x -> return d
700 _ -> fail $ "Could not read `" ++ s ++ "'"
716 _ -> fail $ "Could not read `" ++ s ++ "'"
701−
702−