public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Lua filters: file path as argument to pandoc.read()? (Especially to read YAML files into a (meta)data structure)
@ 2022-03-12 11:29 BPJ
       [not found] ` <CADAJKhASW-6XZ5cwUEerX3=O-vLCXhdAcQF=AbLU43WrMmxGRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: BPJ @ 2022-03-12 11:29 UTC (permalink / raw)
  To: pandoc-discuss

[-- Attachment #1: Type: text/plain, Size: 1149 bytes --]

Is it possible in some way to pass a file path as argument to pandoc.read()
in Lua filters or do you have to first get a string using Lua's io.open()
and file:read()? If no would it maybe be a good idea to allow passing a
table `{ file = 'path/to/file'}` instead of a string to read from a file?
This is assuming that the problems I am having opening files with Lua from
inside filters (I think the files are not found) may not be present from
Haskell.

Also is there some way to read a YAML file into a (meta)data structure
without manually making sure that the string starts/ends with
`---\n`/`\n...\n`? Using `yaml = yaml:gsub('^%s*%-%-%-%%s*', ''):gsub('^',
'---\n')` and its EOS counterpart is a rather blunt method.

-- 
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/CADAJKhASW-6XZ5cwUEerX3%3DO-vLCXhdAcQF%3DAbLU43WrMmxGRg%40mail.gmail.com.

[-- Attachment #2: Type: text/html, Size: 1616 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Lua filters: file path as argument to pandoc.read()? (Especially to read YAML files into a (meta)data structure)
       [not found] ` <CADAJKhASW-6XZ5cwUEerX3=O-vLCXhdAcQF=AbLU43WrMmxGRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-03-12 18:33   ` Albert Krewinkel
  0 siblings, 0 replies; 2+ messages in thread
From: Albert Krewinkel @ 2022-03-12 18:33 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Is it possible in some way to pass a file path as argument to
> pandoc.read() in Lua filters or do you have to first get a string using
> Lua's io.open() and file:read()? If no would it maybe be a good idea to
> allow passing a table `{ file = 'path/to/file'}` instead of a string to
> read from a file?

I had been contemplated something similar in the past: My idea was to
provide functions to generate 'Sources', which is the structure passed
to custom readers. A `Source` argument would be easy to distinguish from
a string, and `read` could be made to parse the source.

My conclusion was that it might be nice, but that it's not worth the
effort for the time being.

> This is assuming that the problems I am having
> opening files with Lua from inside filters (I think the files are not
> found) may not be present from Haskell.

Huh, quite weird. Might be an encoding issue. Possibly related:
https://github.com/jgm/pandoc/issues/6077

> Also is there some way to read a YAML file into a (meta)data structure
> without manually making sure that the string starts/ends with
> `---\n`/`\n...\n`?

That's the hack I'm using as well. The best would probably be to install
a Lua library that binds to libyaml and to use that.


-- 
Albert Krewinkel
GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-12 18:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-12 11:29 Lua filters: file path as argument to pandoc.read()? (Especially to read YAML files into a (meta)data structure) BPJ
     [not found] ` <CADAJKhASW-6XZ5cwUEerX3=O-vLCXhdAcQF=AbLU43WrMmxGRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-03-12 18:33   ` Albert Krewinkel

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