From 243c56a880054bc11ee2007f9ab77174fff1d40f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 25 Jun 2013 22:32:11 -0700 Subject: Fixed 'authors' metadata parsing in reST. Semicolons separate different authors. --- src/Text/Pandoc/Readers/RST.hs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Text/Pandoc/Readers/RST.hs') diff --git a/src/Text/Pandoc/Readers/RST.hs b/src/Text/Pandoc/Readers/RST.hs index 0829996a7..34962b553 100644 --- a/src/Text/Pandoc/Readers/RST.hs +++ b/src/Text/Pandoc/Readers/RST.hs @@ -109,8 +109,29 @@ titleTransform (bs, meta) = _ -> (bs', meta') metaFromDefList :: [([Inline], [[Block]])] -> Meta -> Meta -metaFromDefList ds meta = foldr f meta ds +metaFromDefList ds meta = adjustAuthors $ foldr f meta ds where f (k,v) = setMeta (map toLower $ stringify k) (mconcat $ map fromList v) + adjustAuthors (Meta metamap) = Meta $ M.adjust toPlain "author" + $ M.adjust toPlain "date" + $ M.adjust toPlain "title" + $ M.adjust splitAuthors "authors" + $ metamap + toPlain (MetaBlocks [Para xs]) = MetaInlines xs + toPlain x = x + splitAuthors (MetaBlocks [Para xs]) = MetaList $ map MetaInlines + $ splitAuthors' xs + splitAuthors x = x + splitAuthors' = map normalizeSpaces . + splitOnSemi . concatMap factorSemi + splitOnSemi = splitBy (==Str ";") + factorSemi (Str []) = [] + factorSemi (Str s) = case break (==';') s of + (xs,[]) -> [Str xs] + (xs,';':ys) -> Str xs : Str ";" : + factorSemi (Str ys) + (xs,ys) -> Str xs : + factorSemi (Str ys) + factorSemi x = [x] parseRST :: RSTParser Pandoc parseRST = do -- cgit v1.2.3