@@ -1,4 +1,5 @@
11{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE TupleSections #-}
23{-
34Copyright (C) 2014-2016 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
45
@@ -56,9 +57,9 @@ metaLine = mempty <$ metaLineStart <* (optionLine <|> declarationLine)
5657declarationLine :: OrgParser ()
5758declarationLine = try $ do
5859 key <- map toLower <$> metaKey
59− value <- metaValue key
60+ (key', value) <- metaValue key
6061 updateState $ \st ->
61− let meta' = B.setMeta key <$> value <*> pure nullMeta
62+ let meta' = B.setMeta key' <$> value <*> pure nullMeta
6263 in st { orgStateMeta = meta' <> orgStateMeta st }
6364
6465metaKey :: OrgParser String
@@ -66,13 +67,17 @@ metaKey = map toLower <$> many1 (noneOf ": \n\r")
6667 <* char ':'
6768 <* skipSpaces
6869
69−metaValue :: String -> OrgParser (F MetaValue)
70−metaValue key = do
71− case key of
72− "author" -> metaInlinesCommaSeparated
73− "title" -> metaInlines
74− "date" -> metaInlines
75− _ -> metaString
70+metaValue :: String -> OrgParser (String, (F MetaValue))
71+metaValue key =
72+ let inclKey = "header-includes"
73+ in case key of
74+ "author" -> (key,) <$> metaInlinesCommaSeparated
75+ "title" -> (key,) <$> metaInlines
76+ "date" -> (key,) <$> metaInlines
77+ "header-includes" -> (key,) <$> accumulatingList key metaInlines
78+ "latex_header" -> (inclKey,) <$>
79+ accumulatingList inclKey (metaExportSnippet "latex")
80+ _ -> (key,) <$> metaString
7681
7782metaInlines :: OrgParser (F MetaValue)
7883metaInlines = fmap (MetaInlines . B.toList) <$> inlinesTillNewline
@@ -88,6 +93,23 @@ metaInlinesCommaSeparated = do
8893metaString :: OrgParser (F MetaValue)
8994metaString = return . MetaString <$> anyLine
9095
96+-- | Read an format specific meta definition
97+metaExportSnippet :: String -> OrgParser (F MetaValue)
98+metaExportSnippet format =
99+ return . MetaInlines . B.toList . B.rawInline format <$> anyLine
100+
101+-- | Accumulate the result of the @parser@ in a list under @key@.
102+accumulatingList :: String
103+ -> OrgParser (F MetaValue)
104+ -> OrgParser (F MetaValue)
105+accumulatingList key p = do
106+ value <- p
107+ meta' <- orgStateMeta <$> getState
108+ return $ (\m v -> MetaList (curList m ++ [v])) <$> meta' <*> value
109+ where curList m = case lookupMeta key m of
110+ Just (MetaList ms) -> ms
111+ Just x -> [x]
112+ _ -> []
91113
92114--
93115-- export options