From 3876f15b453b6fd7a256e41d914fa26a580969e9 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Wed, 22 Jun 2022 23:09:51 -0700 Subject: [PATCH] Ensure that metadata values w/o trailing newlines are... parsed as inlines, as the manual states. Previously, they were parsed as inlines if they would otherwise have been a single Plain or Para, but otherwise left unchanged. This led to some quirky results (e.g. #8143). We now use the general function `blocksToInlines` from T.P.Shared. --- src/Text/Pandoc/Readers/Docx.hs | 2 +- src/Text/Pandoc/Readers/Metadata.hs | 10 ++++------ test/command/3755.md | 2 +- test/command/yaml-with-chomp.md | 8 +++++++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs index 5f20477d2..2ac529b87 100644 --- a/src/Text/Pandoc/Readers/Docx.hs +++ b/src/Text/Pandoc/Readers/Docx.hs @@ -228,7 +228,7 @@ isCodeCharStyle :: CharStyle -> Bool isCodeCharStyle = isInheritedFromStyles ["Verbatim Char"] isCodeDiv :: ParagraphStyle -> Bool -isCodeDiv = hasStylesInheritedFrom ["Source Code"] +isCodeDiv = hasStylesInheritedFrom ["Source Code", "SourceCode", "source_code"] isBlockQuote :: ParStyle -> Bool isBlockQuote = diff --git a/src/Text/Pandoc/Readers/Metadata.hs b/src/Text/Pandoc/Readers/Metadata.hs index 276933770..15f981c25 100644 --- a/src/Text/Pandoc/Readers/Metadata.hs +++ b/src/Text/Pandoc/Readers/Metadata.hs @@ -26,13 +26,12 @@ import qualified Data.Text as T import qualified Data.Yaml as Yaml import Data.Aeson (Value(..), Object, Result(..), fromJSON, (.:?), withObject) import Data.Aeson.Types (parse) -import Text.Pandoc.Shared (tshow) +import Text.Pandoc.Shared (tshow, blocksToInlines) import Text.Pandoc.Class.PandocMonad (PandocMonad (..)) import Text.Pandoc.Definition hiding (Null) import Text.Pandoc.Error import Text.Pandoc.Parsing hiding (tableWith, parse) - import qualified Text.Pandoc.UTF8 as UTF8 yamlBsToMeta :: (PandocMonad m, HasLastStrPosition st) @@ -82,13 +81,12 @@ normalizeMetaValue pMetaValue x = -- Note: a standard quoted or unquoted YAML value will -- not end in a newline, but a "block" set off with -- `|` or `>` will. - if "\n" `T.isSuffixOf` T.dropWhileEnd isSpaceChar x -- see #6823 + if "\n" `T.isSuffixOf` (T.dropWhileEnd isSpaceChar x) -- see #6823 then parseFromString' pMetaValue (x <> "\n") else parseFromString' asInlines x where asInlines = fmap b2i <$> pMetaValue - b2i (MetaBlocks [Plain ils]) = MetaInlines ils - b2i (MetaBlocks [Para ils]) = MetaInlines ils - b2i bs = bs + b2i (MetaBlocks bs) = MetaInlines (blocksToInlines bs) + b2i y = y isSpaceChar ' ' = True isSpaceChar '\t' = True isSpaceChar _ = False diff --git a/test/command/3755.md b/test/command/3755.md index e89eaec35..a6e473162 100644 --- a/test/command/3755.md +++ b/test/command/3755.md @@ -22,7 +22,7 @@ Pandoc ``` % pandoc -t native -s --- -title: '<div>foo</div>' +title: "<div>foo</div>\n" date: | 22. Juni 2017 --- diff --git a/test/command/yaml-with-chomp.md b/test/command/yaml-with-chomp.md index 98cc76e18..70551f37b 100644 --- a/test/command/yaml-with-chomp.md +++ b/test/command/yaml-with-chomp.md @@ -12,7 +12,13 @@ Pandoc { unMeta = fromList [ ( "ml" - , MetaBlocks [ Para [ Str "TEST" ] , Plain [ Str "BLOCK" ] ] + , MetaInlines + [ Str "TEST" + , Space + , Str "\182" + , Space + , Str "BLOCK" + ] ) ] }