From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29978 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.text.pandoc Subject: section ids disappear with lua filter Date: Sat, 15 Jan 2022 13:26:06 +0000 Message-ID: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="_000_fbcc804201f74110818df9ab10d70635unibech_" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27385"; mail-complaints-to="usenet@ciao.gmane.io" To: Original-X-From: pandoc-discuss+bncBCZ27W53TUFBB4MWROHQMGQEAEVROAQ-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Jan 15 14:26:12 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wm1-f58.google.com ([209.85.128.58]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n8j4N-0006w2-Ay for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 15 Jan 2022 14:26:11 +0100 Original-Received: by mail-wm1-f58.google.com with SMTP id p7-20020a05600c1d8700b0034a0c77dad6sf7397521wms.7 for ; Sat, 15 Jan 2022 05:26:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1642253170; cv=pass; d=google.com; s=arc-20160816; b=SojiwRN6aogld4TQvNM1ekUPMwXt0C7sOLf8mkYM0mvtP4XIjV5vDMDaPA1cx45JdA wINRFqecXj2YIc9qRUlZJ+Bq54gwqVTiluGJ9OKNWWCoZqSiHnNp1iPyfIdPgxld3rAO leuizZ8ES4ZCFDz/ugqT+e6Qhg7VOsvzayTOiN9/vf5DmxLE4MDj7Su1U34kmASTIekh nCjiSWDalJlEMlfAq+aVrpQmrBEDI9xbcjGKFlH+1WOVcVCHX8fnBw0YLIpMAWgeEmJP 1f+7iyFE+COry524As9affJ8wLpO6dYPf6PzXd1MYBwB+Vi4DtFb6vkIHXjX5K+gw36B 7xpg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:mime-version :content-language:accept-language:message-id:date:thread-index :thread-topic:subject:to:from:sender:dkim-signature; bh=DnSh9vcWCcQXSZ46sCLT35aAzEActsD7r1oKAVS9iAc=; b=Qdjtay2yKOiHghK77wS47FJiSol/9DExMpsmWaMWaFAWgUC9B8f17CIgv240xBHJPp dbXAB2yXMpOJf7TzYQk385GN65JLRJCttUw/8jBnA0h1VVkocsMoNg956E6HN10QBXGg RSZg0hkpO4KN7/q0cxaO6GEoyNc1lsivCiuUz/VULhFnHJMiCMBnGMc+SbqaEc7Q5H+w 7CGFQh6yrNfAUtPZiBKTS8lpqoml9wTovnOjTPPu9ETXbPgc3EOWT3GSGUevLZ1AITGX bB0sI2gWQErXYipQSnJGYr1p5UsTDDyZ1pzukSn+b/IzkfJASNHPA1QM97qcwkiaoxuV OivQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of denis.maier-NSENcxR/0n0@public.gmane.org designates 130.92.0.82 as permitted sender) smtp.mailfrom=denis.maier-NSENcxR/0n0@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=unibe.ch DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:from:to:subject:thread-topic:thread-index:date:message-id :accept-language:content-language:mime-version:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=DnSh9vcWCcQXSZ46sCLT35aAzEActsD7r1oKAVS9iAc=; b=Y2HG/3z1zRNs40TIfu8ceXsh6exRM/FeYXXulZmYq/amxN7HAQ6El23cGeDdolg4nb 1ojZDB/uut8qFkwuj2Tfdw1JVyKyexCfdDwcynClSmWPoWybZr3avpGKm9wH+l2g/GNw cSVg7wcJpH+sqBDThBL30GOArLsYlDQ+UirnYrWJeMUyRtTZExGKWSHjGsFeAm98oOFQ 6C5fDMXtJ5K/ZTz/h0Sws3R7WV7qtC76+9NxZpdk2Clv1f/3uBpsAcJz13daPIQ7jE+I Rbi1aLrKon0YJ2jkAX+0Gg28jl+x8uiJ7OCHet7pSmG+PnrfZm/u2EfodMjS1IFZlrYo 1+YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:from:to:subject:thread-topic:thread-index :date:message-id:accept-language:content-language:mime-version :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=DnSh9vcWCcQXSZ46sCLT35aAzEActsD7r1oKAVS9iAc=; b=rycgvs095pb+bb403NG2zwzGCRM84n0YVbmxZpYymBlXh39cHeDslsDQbuuVCtZ/Uv y3bPiqxAdV9UpHh9Ldoy0dMyaepnQ/FF880BFwL/KSco6nlfCisaSgcknA2RinDcVZIW 2rEcYvjG9wJNcJWz1VRCFLk+LeNp9uOkLV4bX+rYbAvMCbrs55zYcvcMX63kwA2eFK8B TwHyYStckQ5L/xg3KbfOO6/ZozDpC4UmR6nlROu6ju+RCfwTbGW563zqSZ/8o/YfcexK GgsR80vWyplKlLb2M1nqR9tHak+rlqOTaZMZBiC2PUTof4zZoiTLmEsLWg7y+cdq Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM5336IsgJP6+qb3/jWX/Yaiwg45GRc2Inv5gGg6+1dMtIaO3TTcdc IKdasd9hK2eaokyVLKq82+g= X-Google-Smtp-Source: ABdhPJwrwijAkXssiVJsIIMgiSYvI6vNKLnyXDzSHBEBZb6oB8xWhNLSt5LyLbo+tQlU7zXVG67RbA== X-Received: by 2002:a7b:cb8a:: with SMTP id m10mr19819611wmi.165.1642253170768; Sat, 15 Jan 2022 05:26:10 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a5d:53d2:: with SMTP id a18ls85538wrw.1.gmail; Sat, 15 Jan 2022 05:26:08 -0800 (PST) X-Received: by 2002:a5d:6102:: with SMTP id v2mr12230634wrt.222.1642253168611; Sat, 15 Jan 2022 05:26:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642253168; cv=none; d=google.com; s=arc-20160816; b=Ow8PKYWK8eNNpYQIht7XDZdZhVLiq1OGfRU0kaGcvnu8KgLkLIeSU5SkkYjQ6K0/uL 0UuGp5zUFoQF+lpmlY5ylX5iHLjQo3qNk0BvDUFazxtPQyhkSxC7K8In5cvq//nygTvs h2UObl9huiUlweHzV8/w4pu8cpS0d/YHj3zQDceow4gdGN4K/8DDwlwtFA7h+SLcbVUO zwQrs66g0eNFi994+ElrEbTFHh3MufPZPQdpXFYR2N1d6tRVU01NItP9iO9XYynyaW0E 1hWwWA1riOtpcMgudLl1jMK6sSa7siJqmM2Fay/Xqb99vnmkb47ngqlydsUuiR2TFnIn /o2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:content-language:accept-language:message-id:date :thread-index:thread-topic:subject:to:from; bh=afZoikJHtTpjBHXU9fsdxx5F4H7v4I/Qr2c+JjgRj0c=; b=K2Ol928YNCC/e2x8+e9IFCe6rMifVDoId6k8jqk4KWS58nlNQM+VlrIDL2ZJRfwPej TbnTnHov5spfdHR2vazckQEypOuarAYE7AcOfBa8GpmGYaPpYBqYzYAPxZ54jlDm72Nh DQZ2tx9iEYp3nZw5LuO9nQuBS6/BGMUMAcX8FT8Enb1w/auh+OH08KRo9rE+21GX8MeC aDAeZ9S1TZtWv/jZUTBtq2Ya9QmbFwf9ZNyT0nY0BDNAfb/jbhStiSes+/kiRiQ3+Swe Q8P0nPKsgLSlJ+gAjvXiouVOc6EPUg8LBbttWf2OWKsdMxfGsYzKgkDP4pydWTEPIDDg bCQg== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of denis.maier-NSENcxR/0n0@public.gmane.org designates 130.92.0.82 as permitted sender) smtp.mailfrom=denis.maier-NSENcxR/0n0@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=unibe.ch Original-Received: from mailhub-lb1.unibe.ch (mailhub-lb1.unibe.ch. [130.92.0.82]) by gmr-mx.google.com with ESMTPS id bi17si384742wmb.0.2022.01.15.05.26.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Jan 2022 05:26:08 -0800 (PST) Received-SPF: pass (google.com: domain of denis.maier-NSENcxR/0n0@public.gmane.org designates 130.92.0.82 as permitted sender) client-ip=130.92.0.82; X-Virus-Scanned: By University of Bern - MGW Original-Received: from mail.campus.unibe.ch (aai-edge-01.campus.unibe.ch [130.92.13.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mailhub-lb1.unibe.ch (Postfix) with ESMTPS id 5F56550009C for ; Sat, 15 Jan 2022 14:26:07 +0100 (CET) Thread-Topic: section ids disappear with lua filter Thread-Index: AdgKEhJAzZYVI3jvTPayZ8nkBND3gQ== Accept-Language: de-CH, en-US Content-Language: de-DE x-originating-ip: [130.92.13.161] X-Original-Sender: denis.maier-NSENcxR/0n0@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of denis.maier-NSENcxR/0n0@public.gmane.org designates 130.92.0.82 as permitted sender) smtp.mailfrom=denis.maier-NSENcxR/0n0@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=unibe.ch Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.io gmane.text.pandoc:29978 Archived-At: --_000_fbcc804201f74110818df9ab10d70635unibech_ Content-Type: text/plain; charset="UTF-8" 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 ```

Introduction

Bla Bla

Bla Bla

Bibliography

Test Test

Test Test

``` pandoc input.md -L heading-refs-to-meta.lua ```

Introduction

Bla Bla

Bla Bla

``` 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. --_000_fbcc804201f74110818df9ab10d70635unibech_ Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi,

 

I use this lua filter to move r= eferences after a special heading to the document metadata :

 

```lua

-- local pprint =3D require('pp= rint')

 

references =3D {}

 

function getRefsFromDiv (div)

    if div.identifier =3D=3D 'literat= ur' then

        pandoc.walk_block(div, {

     &= nbsp;      Para =3D function(el)=

     &= nbsp;          table.insert(re= ferences, el.content)

     &= nbsp;      end})

     &= nbsp;  return {} -- remove from main body

    end

end

 

function addRefsToMeta (meta)

        &nbs= p;       if not next(references) then

        &nbs= p;          return meta<= /p>

        &nbs= p;       else

        &nbs= p;            &= nbsp;         meta.biblio =3D refer= ences

        &nbs= p;            &= nbsp;         if not meta.bibliotit= le then

        &nbs= p;            &= nbsp;           &nbs= p;             = if pandoc.utils.stringify(meta['lang']) =3D=3D 'en'  then

        &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;    meta.bibliotitle =3D "References"=

     &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;    else

     &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;            &= nbsp;       meta.bibliotitle =3D "Litera= tur"

     &= nbsp;           &nbs= p;            &= nbsp;           &nbs= p;    end

     &= nbsp;           &nbs= p;             = end

     &= nbsp;           &nbs= p;             = -- pprint(references)

     &= nbsp;           &nbs= p;             = return meta

     &= nbsp;          end<= /span>

end

 

function put_in_divs(doc)<= /o:p>

    local blocks= =3D {}

    for i,el in = pairs(doc.blocks) do

     &= nbsp;  table.insert(blocks, el)  

    end

    local newblo= cks =3D pandoc.utils.make_sections(nil, 1, blocks)

    return pando= c.Pandoc(newblocks, doc.meta)

end

 

function flatten_divs(div)

    if div.class= es[1] =3D=3D 'section' then

     &= nbsp;  return div.content   

    = end

end

 

return {

    { Pandoc =3D put_in_divs },<= /o:p>

    { Div =3D getRefsFromDiv },<= /o:p>

    { Meta =3D addRefsToMeta },<= /o:p>

    { Div =3D 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=3D"introduction&= quot;>Introduction</h1>

<p>Bla Bla</p>=

<p>Bla Bla</p>=

<h1 id=3D"literatur&quo= t;>Bibliography</h1>

<p>Test Test</p>

<p>Test Test</p>```=

 

pandoc input.md -L heading-refs= -to-meta.lua

 

```

<h1>Introduction</h1&g= t;

<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 &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc= -discuss/fbcc804201f74110818df9ab10d70635%40unibe.ch.
--_000_fbcc804201f74110818df9ab10d70635unibech_--