public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* How to read/parse metadata in a custom reader
@ 2023-02-17 15:18 Abhishek Ulayil
  0 siblings, 0 replies; only message in thread
From: Abhishek Ulayil @ 2023-02-17 15:18 UTC (permalink / raw)
  To: pandoc-discuss


[-- 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 --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-17 15:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-17 15:18 How to read/parse metadata in a custom reader Abhishek Ulayil

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