aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authormb21 <mb21@users.noreply.github.com>2018-03-30 21:48:14 +0200
committermb21 <mb21@users.noreply.github.com>2018-09-15 16:48:04 +0200
commit6aa5fcac13ea702de19ee1a605631e3ac75d7e05 (patch)
treeaedc06346c0dd697077c3867862947506d2bccd5 /src/Text/Pandoc/Readers
parent73fa70c3974fa37aeb9a9d1535c1e09fb549bbcf (diff)
downloadpandoc-6aa5fcac13ea702de19ee1a605631e3ac75d7e05.tar.gz
introduce --metadata-file option
closes #1960 API change: Text.Pandoc.Readers.Markdown exports now `yamlToMeta`
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 50780b379..502abae9a 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -31,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Conversion of markdown-formatted plain text to 'Pandoc' document.
-}
-module Text.Pandoc.Readers.Markdown ( readMarkdown ) where
+module Text.Pandoc.Readers.Markdown ( readMarkdown, yamlToMeta ) where
import Prelude
import Control.Monad
@@ -246,11 +246,23 @@ yamlMetaBlock = try $ do
updateState $ \st -> st{ stateMeta' = (stateMeta' st) <> newMetaF }
return mempty
+-- | Read a YAML string and convert it to pandoc metadata.
+-- String scalars in the YAML are parsed as Markdown.
+yamlToMeta :: PandocMonad m => BS.ByteString -> m Meta
+yamlToMeta bstr = do
+ let parser = do
+ meta <- yamlBsToMeta bstr
+ return $ runF meta defaultParserState
+ parsed <- readWithM parser def ""
+ case parsed of
+ Right result -> return result
+ Left e -> throwError e
+
yamlBsToMeta :: PandocMonad m => BS.ByteString -> MarkdownParser m (F Meta)
yamlBsToMeta bstr = do
pos <- getPosition
case YAML.decodeNode' YAML.failsafeSchemaResolver False False bstr of
- Right [YAML.Doc (YAML.Mapping _ o)] -> (fmap Meta) <$> yamlMap o
+ Right ((YAML.Doc (YAML.Mapping _ o)):_) -> (fmap Meta) <$> yamlMap o
Right [] -> return . return $ mempty
Right [YAML.Doc (YAML.Scalar YAML.SNull)] -> return . return $ mempty
Right _ -> do