From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29831 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bastien DUMONT Newsgroups: gmane.text.pandoc Subject: Re: Lua filter for section numbers in internal references Date: Wed, 22 Dec 2021 13:46:56 +0000 Message-ID: References: <186dfc25-8ebd-43ef-8a5b-0fae22106712n@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4189"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBDCINCES2QJRBKOZRSHAMGQEOUE4CQA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Dec 22 14:48:28 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lf1-f57.google.com ([209.85.167.57]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n01ym-0000wp-8p for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 22 Dec 2021 14:48:28 +0100 Original-Received: by mail-lf1-f57.google.com with SMTP id w18-20020a194912000000b004254e83978csf1262974lfa.3 for ; Wed, 22 Dec 2021 05:48:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1640180907; cv=pass; d=google.com; s=arc-20160816; b=PtUC6xjkm42VSpwBojAX3101z3MXQRfX0bvdiKxIFJBsGln9mmVL6wZQi2jQKXpZtA +Qqg6AI9uFOTOVHgxegm7BaED3SaSSGPFXuqtaSvoS6jlsGF54Q2WjEVjVps8c4PXhgW HDCyFean0698TkeHd/cVvwbalrVhQzxvsYuOy+JLbRAVLue7PVuxyw3hcYnV8aLnszaW RQ0wUaWAh0xwwTOOIHYU0zGJnSW/xmOyRLCqrVn1oSETWrC0YylJnVFjZBlOfFJ+gzli 0hip2n+vYovy/Juoo952sCv5Qf0AYk5WQZfwEKxOJ82r0l7cwBjsSjDaIxzmClrm0mk6 Frhg== 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:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:dkim-signature; bh=rIy2LbJyFbAZGiOLyF4fiFfmA3jVmb2l5U7RU2qJxog=; b=DUe43FJHfe2hSEYGcjggzJuHtZjKcMMWRhlzIILiRuXYgaxtGP0XMFHnUhhoS8Y1Ay WuZxShPOTCXfQg8bwEtehWbWZqlSXlf0I6Dkhx6kG/lHQkYbRaC+UrX0TVChW91qItP8 jwR2qaH015wwyhV/C1iwuMxzwHx2zwZco/IjPDpxogKBrAEvIw+AtUuV4XkA91EDTZLR 5HcgfyD9UejRXhhevGYALz9eATuOhvnKSu4lOBfw1LQZCL8SZR5FrnuOxEAkxzZJa02O rROw6H6K3EgA0jf/Q/XgLEFAv2I7fULPKl4uzWdYEJb/AxLJQdpwoCAJaO5/CNp5fQ8A Lc9A== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=c7dsLYVB; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :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=rIy2LbJyFbAZGiOLyF4fiFfmA3jVmb2l5U7RU2qJxog=; b=fCl/QaG7YcAc0W8XuX0m9UnnSNvpCGvpw4HkEpzR+PxAhZMGhrIfJlrxGQ8J1SQ6W/ UqMlyPh6Kz3UPkXQVyIvhzaGjoPa8zfF41BZOXfE0f/iT4Lg9fMFdAsOrcVEDpyUDVfG 2BaiHMgYlxpn6fAGLFacTNOzKCCBBB0rlNBUCZ2KqFBbNPBZ48RcQFloRblRccDBVsRQ pi44kAzIpdmGgbw6fMVH1zfrlVyCkjoEgqBlgq1rKRtjbGzFnpH4w4gZ6H1DaVDs1wHI BFwRJ14ikkNJwGi59bLkjPAMc8ZD/42QxzNNsVyW4T2+L2Z3IJZywKSYiNvdoru7p/Xn MJgw== 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:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to: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=rIy2LbJyFbAZGiOLyF4fiFfmA3jVmb2l5U7RU2qJxog=; b=bGTJK6EKLtp9Kn1CZC/0oVmQ4Em5Lj4r/Y5w8svxQ9gTaQylUAnfo06FkHIBChZcEA N54CXMecGYIrfy2iKoNGZErg6N2oNICIdQLLSSRNDrkv038RdtdNKjwchnqceO0etgBf 1vBSUazqSinC2DQLngtkosE9gWLyj3DZZcsQLzCcKmwSwU3vcZ8RWzn/csmPQm9hLtaL smygL6HbLbd1akTHNc8/veYbs8UDVfAVM00UqiD+Ulc2TbXwbK8uTSgnM4dTol0QhSDp derdhGWbBJ0hByTDYhcbSKPiusN+w5THA4H9gPXoT1BS Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533cdDBBkvacxyu3+s1nz8b2pP7sbU0hpaHZUL4iV046wI+DFFj6 NFobhoxsL38rsPH+2pI0778= X-Google-Smtp-Source: ABdhPJz8EgRFNAcQ2ie8ytet2Hrljoo3CwO/M38lsDM4iGyNZHwAFeMr6ZyDvc/HkTGQ8loXRp2Oow== X-Received: by 2002:a05:6512:2601:: with SMTP id bt1mr2488602lfb.400.1640180907719; Wed, 22 Dec 2021 05:48:27 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:651c:514:: with SMTP id o20ls272944ljp.4.gmail; Wed, 22 Dec 2021 05:48:25 -0800 (PST) X-Received: by 2002:a05:651c:1689:: with SMTP id bd9mr2247120ljb.192.1640180905049; Wed, 22 Dec 2021 05:48:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640180905; cv=none; d=google.com; s=arc-20160816; b=HLnAmX0D8kVoGPzUfjg7pI4B3k2wBojSQZeC3iKms3RPHpMTcrfk7U1X2J/ENe0lak Jc+9U49QSq58d14+2XXGg5GICAIYABrakPic+xr939SPw6rGga5u6ya4Sz45HKbgZeLR BfNiZaSfTPv/48eKWjHw5hG6XGZ9fjW+x2F1GH2wUvJ1gcMPAiTNC+NoTomD7G+k/urd WNHgTBoSLjpBf6ql0lU+a8mX/OU0+HRfztJx2YBfLmAKoybFJ6MFvKC1lNaYMQN15arO /dky9EyzCPKIFz8VgC1L9CqHFvRwSuw8IxvKIdVEmd3H3z53I3VTmAUSJs2BtHsv5Cdn x/6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=XeMi+Bpjt0fx6JyYz3GBpqZ8IquW+2UqVRoub6wAGPQ=; b=Akgh02QhJRMhqey1VVXGRrmONYrdXSXtQfaQKyxgP9fNGsE5lNH/dcmWSLjHFaCiun iYuJjbBZkkkHsiDpDU0b8tI46I2XgTAEC8y33FUtX+m6Nzrb1VyGF6qpHUe3CED4TCo1 Jo22ibffrPcWDM7w3oxfOVpjBAdAQPTJPvXJT+SGrvJlEtR2u1iHLMWu2HesEWGlgfR5 2fXaXE9MP/6J5Pu7l8J9oX5EOkVTwNbfCbLNl8Hb1C9pbm2Z9Wog4wbu/a5ZLsX79Hbg xNJTXjFYe4P0gewbZ9ajBsx0uEtBSBKG6f7ho2jQ/xdRDjLypmVItivGBkplEX1NP2zA wz7A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=c7dsLYVB; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Original-Received: from mout01.posteo.de (mout01.posteo.de. [185.67.36.65]) by gmr-mx.google.com with ESMTPS id x32si104810lfu.8.2021.12.22.05.48.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 05:48:24 -0800 (PST) Received-SPF: pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) client-ip=185.67.36.65; Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 3190A240026 for ; Wed, 22 Dec 2021 14:48:24 +0100 (CET) Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4JJvmR5nVYz9rxP for ; Wed, 22 Dec 2021 14:48:23 +0100 (CET) Content-Disposition: inline In-Reply-To: X-Original-Sender: bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=c7dsLYVB; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.65 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net 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:29831 Archived-At: Have you looked at this? https://pandoc.org/lua-filters.html#type-div Le Wednesday 22 December 2021 =C3=A0 04:12:29AM, be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org a = =C3=A9crit : > Thanks for your ideas. I had considered pandoc-crossref also but didn't w= ant to > introduce a new dependency without a real need. If it can be accomplished= using > a simple and small Lua filter, I would prefer this. >=20 > I also observed that the native output creates a normal string. However, = using > Pandoc's make_section function, the references are delivered as DIVs with= a > number attribute. This is easy to process. I just need access to the text > string inside the square brackets. So, how to access the text within a DI= V? I > think this is the thing I need to know ... >=20 > On Wednesday, December 22, 2021 at 12:13:38 PM UTC+1 Bastien Dumont wrote= : >=20 > It seems that you can use pandoc-crossref for such case: see the manu= al > here ([1]https://github.com/lierdakil/pandoc-crossref/blob/master/doc= s/ > index.md). >=20 > To answer the technical part of the question, `pandoc -t native <<< '= See > the [Quick introduction].'` shows that "[Quick introduction]" is pars= ed as > a normal string. You can create a span instead by adding a class: [Qu= ick > introduction]{.sectionref}. But even then, it will be simplier to par= se its > content if it is limited to one string (like "Quick-introduction"). >=20 > Le Wednesday 22 December 2021 =C3=A0 01:16:01AM, be...@typoscriptics.= de a =C3=A9crit > : > > Hi, > > > > 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 i= n my > > markdown document like this: > > > > See the [Quick introduction]. > > > > So, the links are given by the full title of the respective section= they > refer > > to. I found a recipe at stackoverflow ([2]https://stackoverflow.com= / > questions/ > > 54128461/how-to-use-latex-section-numbers-in-pandoc-cross-reference= ) > which does > > this if the link is given like this: > > > > See the [](#quick-introduction) > > > > This is the Lua code: > > > > local make_sections =3D (require 'pandoc.utils').make_sections > > local section_numbers =3D {} > > > > 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)) > > end > > > > 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 > > > > return { > > {Pandoc =3D populate_section_numbers}, > > {Link =3D resolve_section_ref} > > } > > > > > > > > While I do understand what it does, I cannot find out how to change= it to > my > > case. How can I retrieve the part written in [] instead of the attr= ibutes > when > > scanning the document for those internal links? Or is the not even > possible? > > > > Any idea is appreciated. > > > > > > Torsten > > > > -- > > 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, s= end an > email > > to [1]pandoc-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To view this discussion on the web visit [2][3]https://groups.googl= e.com/ > d/msgid/ > > pandoc-discuss/186dfc25-8ebd-43ef-8a5b-0fae22106712n%[4] > 40googlegroups.com. > > > > References: > > > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2] [5]https://groups.google.com/d/msgid/pandoc-discuss/ > 186dfc25-8ebd-43ef-8a5b-0fae22106712n%40googlegroups.com?utm_medium= =3Demail& > utm_source=3Dfooter >=20 >=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 [6]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To view this discussion on the web visit [7]https://groups.google.com/d/m= sgid/ > pandoc-discuss/c8df6f45-5119-4d7c-b95c-ce1ecfc57a64n%40googlegroups.com. >=20 > References: >=20 > [1] https://github.com/lierdakil/pandoc-crossref/blob/master/docs/index.m= d > [2] https://stackoverflow.com/questions/ > [3] https://groups.google.com/d/msgid/ > [4] http://40googlegroups.com/ > [5] https://groups.google.com/d/msgid/pandoc-discuss/186dfc25-8ebd-43ef-8= a5b-0fae22106712n%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > [6] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > [7] https://groups.google.com/d/msgid/pandoc-discuss/c8df6f45-5119-4d7c-b= 95c-ce1ecfc57a64n%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/YcMsUFst47Y3iiza%40localhost.