From: <denis.maier-NSENcxR/0n0@public.gmane.org>
To: <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: section ids disappear with lua filter
Date: Sat, 15 Jan 2022 13:26:06 +0000 [thread overview]
Message-ID: <fbcc804201f74110818df9ab10d70635@unibe.ch> (raw)
[-- Attachment #1: Type: text/plain, Size: 2626 bytes --]
Hi,
I use this lua filter to move references after a special heading to the document metadata :
```lua
-- local pprint = require('pprint')
references = {}
function getRefsFromDiv (div)
if div.identifier == 'literatur' then
pandoc.walk_block(div, {
Para = function(el)
table.insert(references, el.content)
end})
return {} -- remove from main body
end
end
function addRefsToMeta (meta)
if not next(references) then
return meta
else
meta.biblio = references
if not meta.bibliotitle then
if pandoc.utils.stringify(meta['lang']) == 'en' then
meta.bibliotitle = "References"
else
meta.bibliotitle = "Literatur"
end
end
-- pprint(references)
return meta
end
end
function put_in_divs(doc)
local blocks = {}
for i,el in pairs(doc.blocks) do
table.insert(blocks, el)
end
local newblocks = pandoc.utils.make_sections(nil, 1, blocks)
return pandoc.Pandoc(newblocks, doc.meta)
end
function flatten_divs(div)
if div.classes[1] == 'section' then
return div.content
end
end
return {
{ Pandoc = put_in_divs },
{ Div = getRefsFromDiv },
{ Meta = addRefsToMeta },
{ Div = flatten_divs},
}
```
The filter works, but it has the side effect that it also removes all section ids.
Input:
```md
---
lang: en
---
# Introduction
Bla Bla
Bla Bla
# Bibliography {#literatur}
Test Test
Test Test
```
pandoc input.md
```
<h1 id="introduction">Introduction</h1>
<p>Bla Bla</p>
<p>Bla Bla</p>
<h1 id="literatur">Bibliography</h1>
<p>Test Test</p>
<p>Test Test</p>```
pandoc input.md -L heading-refs-to-meta.lua
```
<h1>Introduction</h1>
<p>Bla Bla</p>
<p>Bla Bla</p>
```
Any ideas how I can preserve the ids?
Best,
Denis
--
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/fbcc804201f74110818df9ab10d70635%40unibe.ch.
[-- Attachment #2: Type: text/html, Size: 13137 bytes --]
next reply other threads:[~2022-01-15 13:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-15 13:26 denis.maier-NSENcxR/0n0 [this message]
[not found] ` <fbcc804201f74110818df9ab10d70635-NSENcxR/0n0@public.gmane.org>
2022-01-15 13:33 ` Albert Krewinkel
[not found] ` <87fsppdsrf.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2022-01-15 14:12 ` AW: " denis.maier-NSENcxR/0n0
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=fbcc804201f74110818df9ab10d70635@unibe.ch \
--to=denis.maier-nsencxr/0n0@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).