From: Albert Krewinkel <albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: How to add to header-includes?
Date: Mon, 22 May 2023 16:27:40 +0200 [thread overview]
Message-ID: <87y1lgqvuz.fsf@zeitkraut.de> (raw)
In-Reply-To: <6D8F810C-361A-44A1-AA2E-FA22B318A2C2-WPTjrydoUPgeaOpM6FAJmQkbCANdLtlA@public.gmane.org>
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
next prev parent reply other threads:[~2023-05-22 14:27 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 [this message]
[not found] ` <87y1lgqvuz.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2023-05-25 11:37 ` Oliver
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=87y1lgqvuz.fsf@zeitkraut.de \
--to=albert+pandoc-9eawchwdxg8hfhg+jk9f0w@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).