From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29829 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org" Newsgroups: gmane.text.pandoc Subject: Re: Lua filter for section numbers in internal references Date: Wed, 22 Dec 2021 04:07:49 -0800 (PST) Message-ID: <503bf9a0-73f8-49f4-a9a6-abbf01a24650n@googlegroups.com> References: <186dfc25-8ebd-43ef-8a5b-0fae22106712n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_5398_1146287456.1640174869983" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31632"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDQ6N25ANMIJNKUMRYDBUBFGVELJS-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Dec 22 13:07:54 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ot1-f55.google.com ([209.85.210.55]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n00PR-00083i-N3 for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 22 Dec 2021 13:07:53 +0100 Original-Received: by mail-ot1-f55.google.com with SMTP id o59-20020a9d2241000000b0058f1de3cfe7sf753856ota.5 for ; Wed, 22 Dec 2021 04:07:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=hY4POG+jbEPRiYyuZqiKD7nmqUitprpA/6EmWnfdpCA=; b=JIFHDEA/OV9uVtMmvwOqA1LqiXuNvfpjX8MKFEC54gYbuSKwcuutO2+AziQqoD8wgK h79FWfUeKuY3bfsvNP3YsxOFG/GBpCx9CWsxPvr8jUIE1lF/9LiSfOfgb+LuXSyCfSKW TGgSAsWHiU3P7Kutf15gwrQ3cHuV7Knf8ammafkN1SRSwA9XzhI8K1N01eKeUP9xHGmv 9fb/x+YRGf4T03gFFZHNp7bnfhcuFJtgmr+jDJE+TRirFhHuaVtdlLsUJWRxsMJ6Iu7V vOtFbNHi144o+yTmR7aymJwYM1snB8i2/sSNbT9SxyONYyY4oS6z1wy86QvURFU+Nf8e KQLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=hY4POG+jbEPRiYyuZqiKD7nmqUitprpA/6EmWnfdpCA=; b=X1zGva/0YOKFq8UJho4rcxZ2RXVZfrlXjgQZVSYTotYmlC539IrUnuw7sS6PmLRA3i EuWl8/6hMp2Gvaoj4VMxjVfpfiZXtuKEG98usUWVYYrwrznU26xiVyC+XmmfcZxqR57L x+V2KcUJuwWvAllw/GZ2qRqtGww8hg85GffeVB9SXsyTi42iPv/9zShgymq6AUu94Uw9 jCzeKkhg7XBAoi3LoHgRwl8toUhLzI2riYY9KgtU6+EjTUQlVR7n1JCtNs4aiw0n+VcE gXEUSF0iDE2LGrd/Fac0evc+ZlIa3xZh9Qn4Oo7QjKsCKSFfbMLSDTzLv+zl/lZIUc/O y4Tg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM530rSGjPxiZPRpVIVHxmFnN0OTaRsCOuC1NYoPebPsLKG0tjGEHh LCQs73M7Rj2hJBCIhm+VC6E= X-Google-Smtp-Source: ABdhPJwzDL7BNmV7FDWqdDTEL7JeGqel9ANHCtWYTnixbAMYO19DICCNR9fhwOQuU3HHgqU29rWOkQ== X-Received: by 2002:a4a:e288:: with SMTP id k8mr1636867oot.23.1640174872080; Wed, 22 Dec 2021 04:07:52 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6808:18aa:: with SMTP id bi42ls387958oib.11.gmail; Wed, 22 Dec 2021 04:07:50 -0800 (PST) X-Received: by 2002:aca:bd89:: with SMTP id n131mr551158oif.64.1640174870511; Wed, 22 Dec 2021 04:07:50 -0800 (PST) In-Reply-To: X-Original-Sender: berg-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org 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:29829 Archived-At: ------=_Part_5398_1146287456.1640174869983 Content-Type: multipart/alternative; boundary="----=_Part_5399_64341358.1640174869983" ------=_Part_5399_64341358.1640174869983 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for your ideas. I had considered pandoc-crossref also but didn't=20 want to introduce a new dependency without a real need. If it can be=20 accomplished using a simple and small Lua filter, I would prefer this. I also observed that the native output creates a normal string. However,=20 using Pandoc's make_section function, the references are delivered as DIVs= =20 with a number attribute. This is easy=20 On Wednesday, December 22, 2021 at 12:13:38 PM UTC+1 Bastien Dumont wrote: > It seems that you can use pandoc-crossref for such case: see the manual= =20 > here ( > https://github.com/lierdakil/pandoc-crossref/blob/master/docs/index.md). > > To answer the technical part of the question, `pandoc -t native <<< 'See= =20 > the [Quick introduction].'` shows that "[Quick introduction]" is parsed a= s=20 > a normal string. You can create a span instead by adding a class: [Quick= =20 > introduction]{.sectionref}. But even then, it will be simplier to parse i= ts=20 > content if it is limited to one string (like "Quick-introduction"). > > Le Wednesday 22 December 2021 =C3=A0 01:16:01AM, be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org a= =20 > =C3=A9crit : > > Hi, > >=20 > > I am trying to make a Lua filter that will replace the normal link text= =20 > in > > internal links with section numbers. I want to use internal links in my > > markdown document like this: > >=20 > > See the [Quick introduction]. > >=20 > > So, the links are given by the full title of the respective section the= y=20 > refer > > to. I found a recipe at stackoverflow ( > https://stackoverflow.com/questions/ > > 54128461/how-to-use-latex-section-numbers-in-pandoc-cross-reference)=20 > which does > > this if the link is given like this: > >=20 > > See the [](#quick-introduction) > >=20 > > This is the Lua code: > >=20 > > local make_sections =3D (require 'pandoc.utils').make_sections > > local section_numbers =3D {} > >=20 > > function populate_section_numbers (doc) > > function populate (elements) > > for _, el in pairs(elements) do > > if el.t =3D=3D 'Div' and el.attributes.number then > > section_numbers['#' .. el.attr.identifier] =3D el.attributes.number > > populate(el.content) > > end > > end > > end > > populate(make_sections(true, nil, doc.blocks))=20 > > end > >=20 > > function resolve_section_ref (link) > > if #link.content > 0 or link.target:sub(1, 1) ~=3D '#' then > > return nil > > end > > local section_number =3D pandoc.Str(section_numbers[link.target]) > > return pandoc.Link({section_number}, link.target, link.title, link.attr= ) > > end > >=20 > > return { > > {Pandoc =3D populate_section_numbers}, > > {Link =3D resolve_section_ref} > > } > >=20 > >=20 > >=20 > > While I do understand what it does, I cannot find out how to change it= =20 > to my > > case. How can I retrieve the part written in [] instead of the=20 > attributes when > > scanning the document for those internal links? Or is the not even=20 > possible?=20 > >=20 > > Any idea is appreciated. > >=20 > >=20 > > Torsten > >=20 > > -- > > You received this message because you are subscribed to the Google Grou= ps > > "pandoc-discuss" group. > > To unsubscribe from this group and stop receiving emails from it, send= =20 > an email > > to [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2] > https://groups.google.com/d/msgid/ > > pandoc-discuss/186dfc25-8ebd-43ef-8a5b-0fae22106712n%40googlegroups.com= . > >=20 > > References: > >=20 > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2]=20 > https://groups.google.com/d/msgid/pandoc-discuss/186dfc25-8ebd-43ef-8a5b-= 0fae22106712n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > > --=20 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 e= mail 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/503bf9a0-73f8-49f4-a9a6-abbf01a24650n%40googlegroups.com. ------=_Part_5399_64341358.1640174869983 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks for your ideas. I had considered pandoc-crossref also but didn't wan= t to introduce a new dependency without a real need. If it can be accomplis= hed using a simple and small Lua filter, I would prefer this.

I also observed that the native output creates a normal string. Howev= er, using Pandoc's make_section function, the references are delivered as D= IVs with a number attribute. This is easy 

On Wednesday, December = 22, 2021 at 12:13:38 PM UTC+1 Bastien Dumont wrote:
It seems that you can use pandoc-cro= ssref for such case: see the manual here (https://github.com/lierdakil/pandoc-crossref/blob/master/do= cs/index.md).

To answer the technical part of the question, `pandoc -t native <<= ;< 'See the [Quick introduction].'` shows that "[Quick intr= oduction]" is parsed as a normal string. You can create a span instead= by adding a class: [Quick introduction]{.sectionref}. But even then, it wi= ll be simplier to parse its content if it is limited to one string (like &q= uot;Quick-introduction").

Le Wednesday 22 December 2021 =C3=A0 01:16:01AM, be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org a =C3=A9crit :
> Hi,
>=20
> I am trying to make a Lua filter that will replace the normal link= text in
> internal links with section numbers. I want to use internal links = in my
> markdown document like this:
>=20
> See the [Quick introduction].
>=20
> So, the links are given by the full title of the respective sectio= n they refer
> to. I found a recipe at stackoverflow (https://stackoverflow.com/questions/
> 54128461/how-to-use-latex-section-numbers-in-pandoc-cross-referenc= e) which does
> this if the link is given like this:
>=20
> See the [](#quick-introduction)
>=20
> This is the Lua code:
>=20
> local make_sections =3D (require 'pandoc.utils').make_sect= ions
> local section_numbers =3D {}
>=20
> function populate_section_numbers (doc)
> function populate (elements)
> for _, el in pairs(elements) do
> if el.t =3D=3D 'Div' and el.attributes.number then
> section_numbers['#' .. el.attr.identifier] =3D el.= attributes.number
> populate(el.content)
> end
> end
> end
> populate(make_sections(true, nil, doc.blocks)) =20
> end
>=20
> function resolve_section_ref (link)
> if #link.content > 0 or link.target:sub(1, 1) ~=3D '#'= ; then
> return nil
> end
> local section_number =3D pandoc.Str(section_numbers[link.target]= )
> return pandoc.Link({section_number}, link.target, link.title, li= nk.attr)
> end
>=20
> return {
> {Pandoc =3D populate_section_numbers},
> {Link =3D resolve_section_ref}
> }
>=20
>=20
>=20
> While I do understand what it does, I cannot find out how to chang= e it to my
> case. How can I retrieve the part written in [] instead of the att= ributes when
> scanning the document for those internal links? Or is the not even= possible?=20
>=20
> Any idea is appreciated.
>=20
>=20
> Torsten
>=20
> --
> 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 [1]pandoc-discus...@= googlegroups.com.
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/186dfc25-8ebd-43ef-8a5b-0fae22106712n%40googlegroups.com.
>=20
> References:
>=20
> [1] mailto:pandoc-discu= s...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://= groups.google.com/d/msgid/pandoc-discuss/186dfc25-8ebd-43ef-8a5b-0fae221067= 12n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter

--
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/503bf9a0-73f8-49f4-a9a6-abbf01a24650n%40googlegroups.= com.
------=_Part_5399_64341358.1640174869983-- ------=_Part_5398_1146287456.1640174869983--