From: ss2 <okubo.peyton-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Reading yaml metadata
Date: Mon, 11 Dec 2023 17:27:56 -0800 (PST) [thread overview]
Message-ID: <c1b6d4fe-8cd5-482c-b351-be20a658b8d3n@googlegroups.com> (raw)
In-Reply-To: <dac9ab6e-b3ad-4645-912e-a7f72f5c7429n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
[-- Attachment #1.1: Type: text/plain, Size: 3014 bytes --]
Maybe attaching the files was inconvenient.
Haskell code
```
import qualified Data.Text as T
import Text.Pandoc
import Text.Pandoc.Walk (query)
-- Extract YAML metadata from document
getMetaData :: Pandoc -> Meta
getMetaData (Pandoc meta _) = meta
-- Read an org document with a yaml metadata block and print it
printDocWithMetaData :: IO ()
printDocWithMetaData = do
input <- readFile "root.org"
let readerOpts = def {
readerStandalone = True,
readerExtensions = enableExtension Ext_yaml_metadata_block
(getDefaultExtensions $ T.pack "org")
}
eitherDoc <- runIO $ readOrg readerOpts (T.pack input)
doc <- handleError eitherDoc
let metaData = getMetaData doc
print metaData
```
Input file (root.org):
```
---
title: Hello, World!
author:
- name: Your Name
affiliation: Your Affiliation
---
* Introduction
Hello, World! This is a simple org-mode document with a YAML header.
* Conclusion
Thank you for reading!
```
Std out:
```Meta {unMeta = fromList []}```
The input file contains a yaml metadata block yet the pandoc reader isn't
extracting it.
On Sunday, December 10, 2023 at 11:03:41 PM UTC-6 ss2 wrote:
> Hello Everyone,
>
> I'm simply trying to read a markup file (org in this case). I'm able to
> read its contents but not the metadata. I've tried reading the
> documentation and looking at a few examples and I'm not sure what I'm doing
> wrong. The code snippet and file I'm reading are attached below. Here is
> the output when calling the function:
>
> Right (Pandoc (Meta {unMeta = fromList []}) [Para [Str
> "\8212",SoftBreak,Str "title:",Space,Str "The",Space,Str
> "document",Space,Str "title",SoftBreak,Str "author:"],BulletList [[Plain
> [Str "name:",Space,Str "Author",Space,Str "One",SoftBreak,Str
> "affiliation:",Space,Str "University",Space,Str "of",Space,Str
> "Somewhere"]],[Plain [Str "name:",Space,Str "Author",Space,Str
> "Two",SoftBreak,Str "affiliation:",Space,Str "University",Space,Str
> "of",Space,Str "Nowhere"]]],Para [Str "\8230"],Header 1 ("",[],[]) [Str
> "Root"],Header 1 ("",[],[]) [Str "Nav"],BulletList [[Plain [Link ("",[],[])
> [Str "posts"] ("posts/hello-world.org","")]],[Plain [Link ("",[],[]) [Str
> "stream"] ("stream.org","")]]],Para [Str "About",Space,Str "me."]])
>
> As you can see the metadata is empty even though there is a yaml metadata
> block in the source file.
>
> My build depends on pandoc >= 3.1 && < 3.2 and pandoc-types >= 1.23.
>
> Any help would be greatly appreciated!!
>
> Best,
> P
>
--
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/c1b6d4fe-8cd5-482c-b351-be20a658b8d3n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 4861 bytes --]
next prev parent reply other threads:[~2023-12-12 1:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-11 5:03 ss2
[not found] ` <dac9ab6e-b3ad-4645-912e-a7f72f5c7429n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-12 1:27 ` ss2 [this message]
[not found] ` <c1b6d4fe-8cd5-482c-b351-be20a658b8d3n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-12-12 10:22 ` 'William Lupton' via pandoc-discuss
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c1b6d4fe-8cd5-482c-b351-be20a658b8d3n@googlegroups.com \
--to=okubo.peyton-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).