From e3a6d651e17b88df107bf2293dfc5e3e6dbf35d2 Mon Sep 17 00:00:00 2001
From: Albert Krewinkel <albert@zeitkraut.de>
Date: Sun, 28 Jun 2020 17:36:31 +0200
Subject: Org reader: update behavior of author, keywords export settings

The behavior of the `#+AUTHOR` and `#+KEYWORD` export settings has
changed: Org now allows multiple such lines and adds a space between the
contents of each line. Pandoc now always parses these settings as meta
inlines; setting values are no longer treated as comma-separated lists.
Note that a Lua filter can be used to restore the previous behavior.
---
 src/Text/Pandoc/Readers/Org/Meta.hs | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

(limited to 'src/Text/Pandoc/Readers/Org')

diff --git a/src/Text/Pandoc/Readers/Org/Meta.hs b/src/Text/Pandoc/Readers/Org/Meta.hs
index 7ee64c2e5..fdb7abe7c 100644
--- a/src/Text/Pandoc/Readers/Org/Meta.hs
+++ b/src/Text/Pandoc/Readers/Org/Meta.hs
@@ -74,11 +74,11 @@ metaKey = T.toLower <$> many1Char (noneOf ": \n\r")
 exportSettingHandlers :: PandocMonad m => Map Text (OrgParser m ())
 exportSettingHandlers = Map.fromList
   [ ("result"     , fmap pure anyLine `parseThen` discard)        -- RESULT is never an export setting
-  , ("author"     , commaSepInlines `parseThen` setField "author")
-  , ("keywords"   , commaSepInlines `parseThen` setField "keywords")
+  , ("author"     , lineOfInlines   `parseThen` collectLines "author")
+  , ("keywords"   , lineOfInlines   `parseThen` collectLines "keywords")
   , ("date"       , lineOfInlines   `parseThen` setField "date")
-  , ("description", lineOfInlines   `parseThen` collectSepBy B.SoftBreak "description")
-  , ("title"      , lineOfInlines   `parseThen` collectSepBy B.Space "title")
+  , ("description", lineOfInlines   `parseThen` collectLines "description")
+  , ("title"      , lineOfInlines   `parseThen` collectLines "title")
   , ("nocite"     , lineOfInlines   `parseThen` collectAsList "nocite")
   , ("latex_class", fmap pure anyLine `parseThen` setField "documentclass")
   , ("latex_class_options", (pure . T.filter (`notElem` ("[]" :: String)) <$> anyLine)
@@ -101,8 +101,8 @@ parseThen p modMeta = do
 discard :: a -> Meta -> Meta
 discard = const id
 
-collectSepBy :: Inline -> Text -> Inlines -> Meta -> Meta
-collectSepBy sep key value meta =
+collectLines :: Text -> Inlines -> Meta -> Meta
+collectLines key value meta =
   let value' = appendValue meta (B.toList value)
   in B.setMeta key value' meta
  where
@@ -117,7 +117,7 @@ collectSepBy sep key value meta =
   collectInlines :: MetaValue -> [Inline]
   collectInlines = \case
     MetaInlines inlns -> inlns
-    MetaList ml       -> intercalate [sep] $ map collectInlines ml
+    MetaList ml       -> intercalate [B.SoftBreak] $ map collectInlines ml
     MetaString s      -> [B.Str s]
     MetaBlocks blks   -> blocksToInlines blks
     MetaMap _map      -> []
@@ -138,16 +138,6 @@ collectAsList key value meta =
 setField :: ToMetaValue a => Text -> a -> Meta -> Meta
 setField field value meta = B.setMeta field (B.toMetaValue value) meta
 
-lineOfInlines :: PandocMonad m => OrgParser m (F Inlines)
-lineOfInlines = inlinesTillNewline
-
-commaSepInlines :: PandocMonad m => OrgParser m (F [Inlines])
-commaSepInlines = do
-  itemStrs <- many1Char (noneOf ",\n") `sepBy1` char ','
-  newline
-  items <- mapM (parseFromString inlinesTillNewline . (<> "\n")) itemStrs
-  return $ sequence items
-
 -- | Read an format specific meta definition
 metaExportSnippet :: Monad m => Text -> OrgParser m (F Inlines)
 metaExportSnippet format = pure . B.rawInline format <$> anyLine
@@ -233,8 +223,8 @@ emphChars = do
   skipSpaces
   safeRead <$> anyLine
 
-inlinesTillNewline :: PandocMonad m => OrgParser m (F Inlines)
-inlinesTillNewline = do
+lineOfInlines :: PandocMonad m => OrgParser m (F Inlines)
+lineOfInlines = do
   updateLastPreCharPos
   trimInlinesF . mconcat <$> manyTill inline newline
 
-- 
cgit v1.2.3