aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Krewinkel <[email protected]>2022-08-17 16:29:55 +0200
committerAlbert Krewinkel <[email protected]>2022-08-17 16:49:37 +0200
commitf294acff381f3a5c6027e5b0c4082e8255ec64e6 (patch)
tree72760187b20552da8e167f4d88acff3fbcee809e
parent90d8205e174c8b734423e81ada5a5f0b59755f6d (diff)
Org reader: treat "abstract" block as metadata
A block of type "abstract" is assumed to define the document's abstract. It is transferred from the main text to the metadata. Closes: #8204
-rw-r--r--src/Text/Pandoc/Readers/Org/Blocks.hs11
-rw-r--r--test/command/8204.md23
2 files changed, 34 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Blocks.hs b/src/Text/Pandoc/Readers/Org/Blocks.hs
index 1a97a07b4..dd79cc289 100644
--- a/src/Text/Pandoc/Readers/Org/Blocks.hs
+++ b/src/Text/Pandoc/Readers/Org/Blocks.hs
@@ -191,6 +191,7 @@ orgBlock = try $ do
"quote" -> parseBlockLines (fmap B.blockQuote)
"verse" -> verseBlock
"src" -> codeBlock blockAttrs
+ "abstract"-> metadataBlock
_ -> parseBlockLines $
let (ident, classes, kv) = attrFromBlockAttributes blockAttrs
in fmap $ B.divWith (ident, classes ++ [blkType], kv)
@@ -290,6 +291,16 @@ verseBlock blockType = try $ do
line <- parseFromString inlines (indentedLine <> "\n")
return (trimInlinesF $ pure nbspIndent <> line)
+-- | Parses an environment of the given name and adds the result to the document
+-- metadata under a key of the same name.
+metadataBlock :: PandocMonad m => Text -> OrgParser m (F Blocks)
+metadataBlock blockType = try $ do
+ content <- parseBlockLines id blockType
+ meta' <- orgStateMeta <$> getState
+ updateState $ \st ->
+ st { orgStateMeta = B.setMeta blockType <$> content <*> meta' }
+ return mempty
+
-- | Read a code block and the associated results block if present. Which of
-- the blocks is included in the output is determined using the "exports"
-- argument in the block header.
diff --git a/test/command/8204.md b/test/command/8204.md
index 80a21564d..8e30e9543 100644
--- a/test/command/8204.md
+++ b/test/command/8204.md
@@ -1,3 +1,4 @@
+Include abstract in Org output.
```
% pandoc --to=org --standalone
---
@@ -14,3 +15,25 @@ It has multiple paragraphs.
#+end_abstract
```
+
+Parse abstract environment as *abstract* metadata field.
+```
+% pandoc --from=org --to=markdown --standalone
+#+begin_abstract
+
+This is an /abstract/.
+
+It has multiple paragraphs.
+#+end_abstract
+
+Main text
+^D
+---
+abstract: |
+ This is an *abstract*.
+
+ It has multiple paragraphs.
+---
+
+Main text
+```