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
This commit is contained in:
Albert Krewinkel 2022-08-17 16:29:55 +02:00
parent 90d8205e17
commit f294acff38
No known key found for this signature in database
GPG key ID: 388DC0B21F631124
2 changed files with 34 additions and 0 deletions

View file

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

View file

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