@@ -1,4 +1,5 @@
1{-# LANGUAGE FlexibleContexts #-}
1{-# LANGUAGE FlexibleContexts #-}
2+{-# LANGUAGE TupleSections #-}
3Copyright (C) 2014-2016 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
4Copyright (C) 2014-2016 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
@@ -56,9 +57,9 @@ metaLine = mempty <$ metaLineStart <* (optionLine <|> declarationLine)
56declarationLine :: OrgParser ()
57declarationLine :: OrgParser ()
57declarationLine = try $ do
58declarationLine = try $ do
58 key <- map toLower <$> metaKey
59 key <- map toLower <$> metaKey
59− value <- metaValue key
60+ (key', value) <- metaValue key
60 updateState $ \st ->
61 updateState $ \st ->
61− let meta' = B.setMeta key <$> value <*> pure nullMeta
62+ let meta' = B.setMeta key' <$> value <*> pure nullMeta
62 in st { orgStateMeta = meta' <> orgStateMeta st }
63 in st { orgStateMeta = meta' <> orgStateMeta st }
64metaKey :: OrgParser String
65metaKey :: OrgParser String
@@ -66,13 +67,17 @@ metaKey = map toLower <$> many1 (noneOf ": \n\r")
66 <* char ':'
67 <* char ':'
67 <* skipSpaces
68 <* skipSpaces
69−metaValue :: String -> OrgParser (F MetaValue)
70+metaValue :: String -> OrgParser (String, (F MetaValue))
70−metaValue key = do
71+metaValue key =
72+ let inclKey = "header-includes"
71− case key of
73+ in case key of
72− "author" -> metaInlinesCommaSeparated
74+ "author" -> (key,) <$> metaInlinesCommaSeparated
73− "title" -> metaInlines
75+ "title" -> (key,) <$> metaInlines
74− "date" -> metaInlines
76+ "date" -> (key,) <$> metaInlines
77+ "header-includes" -> (key,) <$> accumulatingList key metaInlines
78+ "latex_header" -> (inclKey,) <$>
79+ accumulatingList inclKey (metaExportSnippet "latex")
75− _ -> metaString
80+ _ -> (key,) <$> metaString
77metaInlines :: OrgParser (F MetaValue)
82metaInlines :: OrgParser (F MetaValue)
78metaInlines = fmap (MetaInlines . B.toList) <$> inlinesTillNewline
83metaInlines = fmap (MetaInlines . B.toList) <$> inlinesTillNewline
@@ -88,6 +93,23 @@ metaInlinesCommaSeparated = do
88metaString :: OrgParser (F MetaValue)
93metaString :: OrgParser (F MetaValue)
89metaString = return . MetaString <$> anyLine
94metaString = return . MetaString <$> anyLine
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
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
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
93-- export options
115-- export options