Skip to content

Commit a7e0e30

Browse files
committed
use lookupMeta* functions wherever possible
1 parent 4f60db1 commit a7e0e30

File tree

4 files changed

+7
-38
lines changed

4 files changed

+7
-38
lines changed

src/Text/Pandoc/Readers/Org/DocumentTree.hs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ import Text.Pandoc.Readers.Org.BlockStarts
4343
import Text.Pandoc.Readers.Org.ParserState
4444
import Text.Pandoc.Readers.Org.Parsing
4545

46-
import qualified Data.Map as Map
4746
import qualified Text.Pandoc.Builder as B
4847

4948
--
@@ -58,7 +57,7 @@ documentTree :: PandocMonad m
5857
documentTree blocks inline = do
5958
initialBlocks <- blocks
6059
headlines <- sequence <$> manyTill (headline blocks inline 1) eof
61-
title <- fmap (getTitle . unMeta) . orgStateMeta <$> getState
60+
title <- fmap docTitle . orgStateMeta <$> getState
6261
return $ do
6362
headlines' <- headlines
6463
initialBlocks' <- initialBlocks
@@ -73,12 +72,6 @@ documentTree blocks inline = do
7372
, headlineContents = initialBlocks'
7473
, headlineChildren = headlines'
7574
}
76-
where
77-
getTitle :: Map.Map String MetaValue -> [Inline]
78-
getTitle metamap =
79-
case Map.lookup "title" metamap of
80-
Just (MetaInlines inlns) -> inlns
81-
_ -> []
8275

8376
newtype Tag = Tag { fromTag :: String }
8477
deriving (Show, Eq)

src/Text/Pandoc/Writers/Docx.hs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import Text.Pandoc.Readers.Docx.StyleMap
6666
import Text.Pandoc.Shared hiding (Element)
6767
import Text.Pandoc.Walk
6868
import Text.Pandoc.Writers.Math
69-
import Text.Pandoc.Writers.Shared (isDisplayMath, fixDisplayMath, lookupMetaInlines)
69+
import Text.Pandoc.Writers.Shared
7070
import Text.Printf (printf)
7171
import Text.TeXMath
7272
import Text.XML.Light as XML
@@ -760,24 +760,9 @@ writeOpenXML opts (Pandoc meta blocks) = do
760760
let tit = docTitle meta
761761
let auths = docAuthors meta
762762
let dat = docDate meta
763-
let abstract' = case lookupMeta "abstract" meta of
764-
Just (MetaBlocks bs) -> bs
765-
Just (MetaInlines ils) -> [Plain ils]
766-
Just (MetaString s) -> [Plain [Str s]]
767-
_ -> []
768-
let subtitle' = case lookupMeta "subtitle" meta of
769-
Just (MetaBlocks [Plain xs]) -> xs
770-
Just (MetaBlocks [Para xs]) -> xs
771-
Just (MetaInlines xs) -> xs
772-
Just (MetaString s) -> [Str s]
773-
_ -> []
774-
let includeTOC = writerTableOfContents opts ||
775-
case lookupMeta "toc" meta of
776-
Just (MetaBlocks _) -> True
777-
Just (MetaInlines _) -> True
778-
Just (MetaString (_:_)) -> True
779-
Just (MetaBool True) -> True
780-
_ -> False
763+
let abstract' = lookupMetaBlocks "abstract" meta
764+
let subtitle' = lookupMetaInlines "subtitle" meta
765+
let includeTOC = writerTableOfContents opts || lookupMetaBool "toc" meta
781766
title <- withParaPropM (pStyleM "Title") $ blocksToOpenXML opts [Para tit | not (null tit)]
782767
subtitle <- withParaPropM (pStyleM "Subtitle") $ blocksToOpenXML opts [Para subtitle' | not (null subtitle')]
783768
authors <- withParaProp (pCustomStyle "Author") $ blocksToOpenXML opts $

src/Text/Pandoc/Writers/Powerpoint/Presentation.hs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -744,13 +744,7 @@ getMetaSlide :: Pres (Maybe Slide)
744744
getMetaSlide = do
745745
meta <- asks envMetadata
746746
title <- inlinesToParElems $ docTitle meta
747-
subtitle <- inlinesToParElems $
748-
case lookupMeta "subtitle" meta of
749-
Just (MetaString s) -> [Str s]
750-
Just (MetaInlines ils) -> ils
751-
Just (MetaBlocks [Plain ils]) -> ils
752-
Just (MetaBlocks [Para ils]) -> ils
753-
_ -> []
747+
subtitle <- inlinesToParElems $ lookupMetaInlines "subtitle" meta
754748
authors <- mapM inlinesToParElems $ docAuthors meta
755749
date <- inlinesToParElems $ docDate meta
756750
if null title && null subtitle && null authors && null date

src/Text/Pandoc/Writers/RST.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,7 @@ pandocToRST (Pandoc meta blocks) = do
8282
else Nothing
8383
let render' :: Doc -> Text
8484
render' = render colwidth
85-
let subtit = case lookupMeta "subtitle" meta of
86-
Just (MetaBlocks [Plain xs]) -> xs
87-
Just (MetaInlines xs) -> xs
88-
_ -> []
85+
let subtit = lookupMetaInlines "subtitle" meta
8986
title <- titleToRST (docTitle meta) subtit
9087
metadata <- metaToJSON opts
9188
(fmap render' . blockListToRST)

0 commit comments

Comments
 (0)