From 62f46b3995425c9a3ec87cba0eb8a4d736adec07 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 31 May 2021 21:34:51 -0600 Subject: Fix regression with commonmark/gfm yaml metdata block parsing. A regression in 2.14 led to the document body being omitted after YAML metadata in some cases. This is now fixed. Closes #7339. --- src/Text/Pandoc/Readers/CommonMark.hs | 10 +++++----- test/command/7339.md | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 test/command/7339.md diff --git a/src/Text/Pandoc/Readers/CommonMark.hs b/src/Text/Pandoc/Readers/CommonMark.hs index 228e65312..411d64278 100644 --- a/src/Text/Pandoc/Readers/CommonMark.hs +++ b/src/Text/Pandoc/Readers/CommonMark.hs @@ -30,7 +30,7 @@ import Text.Pandoc.Readers.Metadata (yamlMetaBlock) import Control.Monad.Except import Data.Functor.Identity (runIdentity) import Data.Typeable -import Text.Pandoc.Parsing (runParserT, getPosition, +import Text.Pandoc.Parsing (runParserT, getInput, runF, defaultParserState, option, many1, anyChar, Sources(..), ToSources(..), ParserT, Future, sourceName) @@ -44,14 +44,14 @@ readCommonMark opts s let sources = toSources s let toks = concatMap sourceToToks (unSources sources) res <- runParserT (do meta <- yamlMetaBlock (metaValueParser opts) - pos <- getPosition - return (meta, pos)) + rest <- getInput + return (meta, rest)) defaultParserState "YAML metadata" (toSources s) case res of Left _ -> readCommonMarkBody opts sources toks - Right (meta, pos) -> do + Right (meta, rest) -> do -- strip off metadata section and parse body - let body = dropWhile (\t -> tokPos t < pos) toks + let body = concatMap sourceToToks (unSources rest) Pandoc _ bs <- readCommonMarkBody opts sources body return $ Pandoc (runF meta defaultParserState) bs | otherwise = do diff --git a/test/command/7339.md b/test/command/7339.md new file mode 100644 index 000000000..9697c1c32 --- /dev/null +++ b/test/command/7339.md @@ -0,0 +1,11 @@ +``` +% pandoc -f gfm -s -t native +--- +title: Test +--- + +Hi +^D +Pandoc (Meta {unMeta = fromList [("title",MetaInlines [Str "Test"])]}) +[Para [Str "Hi"]] +``` -- cgit v1.2.3