public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* section ids disappear with lua filter
@ 2022-01-15 13:26 denis.maier-NSENcxR/0n0
       [not found] ` <fbcc804201f74110818df9ab10d70635-NSENcxR/0n0@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2022-01-15 13:26 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- 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 --]

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

end of thread, other threads:[~2022-01-15 14:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-15 13:26 section ids disappear with lua filter denis.maier-NSENcxR/0n0
     [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

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