diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-10-22 22:10:25 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-10-22 22:10:25 -0700 |
commit | c712d13b67a92c887d5ef185064aecf0972d4496 (patch) | |
tree | bc0d865572ace48a63ece57560011fe3f5bb28f5 | |
parent | 64d55d5a7dae93dd9ba8f68c8e9acee9837af023 (diff) | |
download | pandoc-c712d13b67a92c887d5ef185064aecf0972d4496.tar.gz |
Org reader: allow an initial :PROPERTIES: drawer to add to metadata.
Closes #7520.
-rw-r--r-- | src/Text/Pandoc/Readers/Org/DocumentTree.hs | 12 | ||||
-rw-r--r-- | test/Tests/Readers/Org/Meta.hs | 2 | ||||
-rw-r--r-- | test/command/7520.md | 22 |
3 files changed, 33 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Org/DocumentTree.hs b/src/Text/Pandoc/Readers/Org/DocumentTree.hs index 2dcbecb1d..1c4f253cc 100644 --- a/src/Text/Pandoc/Readers/Org/DocumentTree.hs +++ b/src/Text/Pandoc/Readers/Org/DocumentTree.hs @@ -41,6 +41,7 @@ documentTree :: PandocMonad m -> OrgParser m (F Inlines) -> OrgParser m (F Headline) documentTree blocks inline = do + properties <- option mempty propertiesDrawer initialBlocks <- blocks headlines <- sequence <$> manyTill (headline blocks inline 1) eof title <- fmap docTitle . orgStateMeta <$> getState @@ -54,7 +55,7 @@ documentTree blocks inline = do , headlineText = B.fromList title' , headlineTags = mempty , headlinePlanning = emptyPlanning - , headlineProperties = mempty + , headlineProperties = properties , headlineContents = initialBlocks' , headlineChildren = headlines' } @@ -163,8 +164,15 @@ unprunedHeadlineToBlocks hdln st = in if not usingSelectedTags || any (`Set.member` orgStateSelectTags st) (headlineTags rootNode') then do headlineBlocks <- headlineToBlocks rootNode' + -- add metadata from root node :PROPERTIES: + updateState $ \s -> + s{ orgStateMeta = foldr + (\(PropertyKey k, PropertyValue v) m -> + B.setMeta k v <$> m) + (orgStateMeta s) + (headlineProperties rootNode') } -- ignore first headline, it's the document's title - return . drop 1 . B.toList $ headlineBlocks + return $ drop 1 $ B.toList headlineBlocks else do headlineBlocks <- mconcat <$> mapM headlineToBlocks (headlineChildren rootNode') return . B.toList $ headlineBlocks diff --git a/test/Tests/Readers/Org/Meta.hs b/test/Tests/Readers/Org/Meta.hs index 6363d84b0..41a41cb00 100644 --- a/test/Tests/Readers/Org/Meta.hs +++ b/test/Tests/Readers/Org/Meta.hs @@ -238,7 +238,7 @@ tests = , " :setting: foo" , " :END:" ] =?> - (mempty::Blocks) + (setMeta "setting" ("foo" :: T.Text) (doc mempty)) , "Logbook drawer" =: T.unlines [ " :LogBook:" diff --git a/test/command/7520.md b/test/command/7520.md new file mode 100644 index 000000000..0300a9e45 --- /dev/null +++ b/test/command/7520.md @@ -0,0 +1,22 @@ +``` +% pandoc -f org -t native -s +:PROPERTIES: +:ID: d5b18943-98a3-4b2a-a545-41d17bf50f3e +:END: +#+title: Common Ground +^D +Pandoc + Meta + { unMeta = + fromList + [ ( "id" + , MetaString "d5b18943-98a3-4b2a-a545-41d17bf50f3e" + ) + , ( "title" + , MetaInlines [ Str "Common" , Space , Str "Ground" ] + ) + ] + } + [] + +``` |