public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: Oliver <news-WPTjrydoUPgeaOpM6FAJmQkbCANdLtlA@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: How to add to header-includes?
Date: Thu, 25 May 2023 21:37:13 +1000	[thread overview]
Message-ID: <268B495E-B1FD-41C8-A58E-65D468B59E1A@halloleo.hailmail.net> (raw)
In-Reply-To: <87y1lgqvuz.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>

Thanks Albert

I will try it out.

Cool that you can do something like that in a filter! I had thought filters can only change the AST - or is the metadata part of the AST?

Happy pandocing,
Olli

On 23 May 2023, at 0:27, Albert Krewinkel wrote:

> oliver <news-WPTjrydoUPgeaOpM6FAJmQkbCANdLtlA@public.gmane.org> writes:
>
>> When I use header-includes: in a metadata-file I can not add more
>> header lines to it, neither via document YAML nor via -H <file> on
>> the command line. The previous includes are always forgotten.
>>
>> How can I add header stuff from a file and in the documents YAML?
>
> Bit crude, but here's a Lua filter that can help with this. The
> `--include-in-header`/`-H` option must be replaced with `-M
> include-in-header=...`, and the default includes must be specified in
> the `default-includes` field.
>
>
> ``` lua
> -- file: includes.lua
> local function ensure_list (x)
>   return pandoc.utils.type(x) == 'List' and x or pandoc.List{x}
> end
>
> local function read_file (filename)
>   return pandoc.RawBlock(FORMAT, io.open(filename, 'rb'):read('a'))
> end
>
> function Meta (meta)
>   -- Add to header-includes
>   meta['header-includes'] = ensure_list(meta['header-includes'])
>   meta['header-includes']:extend(ensure_list(meta['default-includes']))
>   meta['header-includes']:insert(read_file(meta['include-in-header']))
>
>   -- unset custom include fields
>   meta['extra-includes'] = nil
>   meta['default-in-header'] = nil
>
>   return meta
> end
> ```
>
> -- 
> Albert Krewinkel
> GPG: 8eed e3e2 e8c5 6f18 81fe  e836 388d c0b2 1f63 1124
>
> -- 
> 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/87y1lgqvuz.fsf%40zeitkraut.de.


  parent reply	other threads:[~2023-05-25 11:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22  8:25 oliver
     [not found] ` <6D8F810C-361A-44A1-AA2E-FA22B318A2C2-WPTjrydoUPgeaOpM6FAJmQkbCANdLtlA@public.gmane.org>
2023-05-22  8:59   ` Bastien DUMONT
2023-05-22 13:53     ` news-WPTjrydoUPgeaOpM6FAJmQkbCANdLtlA
2023-05-22 14:27   ` Albert Krewinkel
     [not found]     ` <87y1lgqvuz.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-05-25 11:37       ` Oliver [this message]
2023-07-03  8:46       ` Oliver
     [not found]         ` <CDCA3285-4D99-40FE-B54D-603494C2B62D-WPTjrydoUPgeaOpM6FAJmQkbCANdLtlA@public.gmane.org>
2023-07-03 21:45           ` John MacFarlane
     [not found]             ` <441446FF-9399-4E3C-959B-12C98167C63D-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-07-04  1:57               ` Oliver

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=268B495E-B1FD-41C8-A58E-65D468B59E1A@halloleo.hailmail.net \
    --to=news-wptjrydoupgeaopm6fajmqkbcandltla@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).