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.
This commit is contained in:
John MacFarlane 2022-06-22 23:09:51 -07:00
parent e0dea96d6c
commit 3876f15b45
4 changed files with 13 additions and 9 deletions

View file

@ -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 =

View file

@ -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

View file

@ -22,7 +22,7 @@ Pandoc
```
% pandoc -t native -s
---
title: '<div>foo</div>'
title: "<div>foo</div>\n"
date: |
22. Juni 2017
---

View file

@ -12,7 +12,13 @@ Pandoc
{ unMeta =
fromList
[ ( "ml"
, MetaBlocks [ Para [ Str "TEST" ] , Plain [ Str "BLOCK" ] ]
, MetaInlines
[ Str "TEST"
, Space
, Str "\182"
, Space
, Str "BLOCK"
]
)
]
}