Thanks very much. I will create GitHub issues as you suggest (and will also cover the comment in the next paragraph).

One comment re the lua writer Doc() function's 'variables' argument: This seems by default to contain the curdir, outputfile and sourcefile variables, which are three of the https://pandoc.org/MANUAL.html#variables-set-automatically. I understand that not all of these variables could be set at this point (e.g., body couldn't, and meta-json probably shouldn't), but arguably most of the rest of these variables could be set, including toc?

On Sun, 4 Oct 2020 at 19:41, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:

You can specify a template.  However, I don't think there's
a way to _set_ template variables from within a custom writer,
though your writer can see the variables that were set on
the command line via the 'variables' parameter.

If you want to propose modifying the custom writing code
so writers can set variables, that would be a reasonable
request to make at the pandoc bug tracker.

The only thing from the command line the custom writer
will see is the variables, so the writer can't tell
if --table-of-contents was specified.  Making writer
options available to the custom writers would be another
reasonable enhanchement.

William Lupton <wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org> writes:

> Also, I specified --table-of-contents on the command line, but didn't see
> it set in the writer's Doc() function. Should I have expected to see it?
>
> On Sun, 4 Oct 2020, 16:54 William Lupton, <wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org>
> wrote:
>
>> Great. Thanks. I can do this.
>>
>> But can I then use a template? I didn't mention this earlier, but I tried
>> setting some variables in the Doc() function (e.g. 'toc') and they didn't
>> seem to be seen by the template.
>>
>> On Sun, 4 Oct 2020, 16:12 John MacFarlane, <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
>>
>>>
>>> The table of contents is generated by the HTML writer.
>>> So, if you create a custom writer, you'll have to reproduce
>>> this functionality in your writer.
>>>
>>> William Lupton <wlupton-QSt+ys/nuMyEUIsrzH9SikB+6BGkLq7r@public.gmane.org> writes:
>>>
>>> > Hello,
>>> >
>>> > % pandoc --version
>>> > pandoc 2.9.2.1
>>> >
>>> > I want to generate modified HTML for headers (to be specific, I want to
>>> add
>>> > a link to each header, like Sphinx does), so I decided to create a
>>> custom
>>> > lua writer.
>>> >
>>> > I started with the supplied sample.lua and modified the Header()
>>> function,
>>> > but I find (when I run with --standalone --table-of-contents) that I
>>> don't
>>> > get a ToC. And when I look at the variables in the Doc() function I
>>> don't
>>> > see 'toc' or 'table-of-contents'.
>>> >
>>> > Should I be able do this, or do I have to use my custom writer to
>>> generate
>>> > a fragment and then run pandoc again to process the fragment and
>>> generate
>>> > the ToC (I've tried this and it works)?
>>> >
>>> > Note: I tried to parse this comment in sample.lua Doc(), but am not
>>> clear
>>> > whether it's saying that I can use --template in the _same_ pandoc
>>> > invocation or whether I need to use a separate invocation:
>>> > * You could use the metadata table to fill variables in a custom lua
>>> > template.  Or, pass `--template=...` to pandoc, and pandoc will do the
>>> > template processing as usual.
>>> >
>>> > I can supply more detailed info on request.
>>> >
>>> > Thanks,
>>> > William Lupton
>>> >
>>> > --
>>> > 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-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm.
>>> > To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/pandoc-discuss/66e3e0f4-a77c-4ff6-b71e-68182d95ac2an%40googlegroups.com
>>> .
>>>
>>

--
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/CAEe_xxinvW1OkUm8QGTuFU_yoitz97XqYmdQO4pyUhKSL%3DdWCQ%40mail.gmail.com.