From: Abhishek Ulayil <abhiman2000-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: How to read/parse metadata in a custom reader
Date: Fri, 17 Feb 2023 07:18:50 -0800 (PST) [thread overview]
Message-ID: <33b147cf-936b-419d-9ca0-417e2f9e36edn@googlegroups.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 2365 bytes --]
Hi everyone,hope you all are doing well,
I am currently exploring lpeg as well as custom readers in pandoc. With the
given documentation available online, I was able to briefly understand the
mechanics of custom reader, Grammar and capture groups.
However I was confused as to how should I read data so as to classify them
in meta block of pandoc AST.
here is an example code where I am trying to read abstract using latex
style commands.
```
local P, S, R, Cf, Cc, Ct, V, Cs, Cg, Cb, B, C, Cmt =
lpeg.P, lpeg.S, lpeg.R, lpeg.Cf, lpeg.Cc, lpeg.Ct, lpeg.V,
lpeg.Cs, lpeg.Cg, lpeg.Cb, lpeg.B, lpeg.C, lpeg.Cmt
local whitespacechar = S(" \t\r\n")
local specialchar = S("/*~[]\\{}|")
local wordchar = (1 - (whitespacechar + specialchar ))
local spacechar = S(" \t")
local newline = P"\r"^-1 * P"\n"
local blankline = spacechar^0 * newline
local blanklines = newline * (spacechar^0 * newline)^1
local endline = newline - blanklines
local function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
-- Grammar
G = P{ "Pandoc",
Pandoc = Ct(V"Block"^0) / pandoc.Pandoc;
Block = blanklines^0 * V"Para" ;
Para = Ct(V"Inline"^1) / pandoc.Para;
Meta = V"MetaList" / pandoc.MetaBlocks;
MetaList = Ct(V"Abstract"^0) / pandoc.MetaList;
Inline = V"Str" + V"Space" + V"SoftBreak" ;
Abstract = P"\\abstract{"
* C((1-S"}")^1)
* P"}"
/ pandoc.Str;
Str = wordchar^1 / pandoc.Str;
Space = spacechar^1 / pandoc.Space;
SoftBreak = endline / pandoc.SoftBreak;
}
function Reader(input)
return lpeg.match(G, tostring(input))
end
```
pandoc command :
```
pandoc -f reader.lua -t native -s
\abstract{
hello
}
^d
```
But I am unable to add the abstract group into the meta data
Also I want to know how to add custom labels to the metaInlines.
It might sound like reinventing the wheel a bit but it is my curiosity that
wants to explore implementing custom readers.
Thanks in advance,
Best wishes.
Abhishek U.
--
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/33b147cf-936b-419d-9ca0-417e2f9e36edn%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 8146 bytes --]
reply other threads:[~2023-02-17 15:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=33b147cf-936b-419d-9ca0-417e2f9e36edn@googlegroups.com \
--to=abhiman2000-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).