From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29832 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Albert Krewinkel Newsgroups: gmane.text.pandoc Subject: Re: Lua filter for section numbers in internal references Date: Wed, 22 Dec 2021 15:53:11 +0100 Message-ID: <87sfukn12g.fsf@zeitkraut.de> 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" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3927"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCZJF7XJTILRBXXXRSHAMGQETUS53UI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Dec 22 15:53:20 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-ed1-f63.google.com ([209.85.208.63]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1n02zY-0000oT-NN for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 22 Dec 2021 15:53:20 +0100 Original-Received: by mail-ed1-f63.google.com with SMTP id c19-20020a05640227d300b003f81c7154fbsf2051590ede.7 for ; Wed, 22 Dec 2021 06:53:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1640184799; cv=pass; d=google.com; s=arc-20160816; b=VQ8jpYCi2neZLNx/TPOsu8kMcRvscDe0URhDIfr6a1umayiqh/m9K7lPSwXPqY2WzT pObjWTW5umSACmxBKqCJPOXN4MGRkzXEDDmyPhRcXRWQgw9RZ0Eicd0i5qg2VXC2F/cH FWQvlAImCIV65jnHw1VJ40kWpZNFE8J9GCAV3SsytxV9W0WivnAJUpYHCxEdkW65KBgf 1yDWIaGjyc59fudS1Y8bBoE8VRXooVV8N/wJqsn5C/RXynBn3gsgEMJDrr/rpt58/ES8 9lyDekwTtB6LnJqytXVI1IynINY0TXkib76wfBpv4mBO0m8J+ubJv3Hn76MH73FSjsnJ 2WEQ== 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:message-id :date:in-reply-to:subject:to:from:references:sender:dkim-signature; bh=LUlSVCcHpzLLkMuWSPConUp81rhy5WvzEA1SJ3i/K+Q=; b=ECux787ayOP2N9vQyYcASDZC1/3NJdO+hq2iFDcusDosQobXifJAStF7PNi1ht8W3/ JRAtoiwoeJVKB7UUmVtPTyZbUjStZb5+r9ECcRQP5EcePh5pt0mC18qtd6taUNvwEzv8 dXPwZ7n6lBV/qAxWNeBaUtL0uK4fg4DW0UGD++WSPj48/yuB3eCe8ie54yC3Y+ilbpkE j7D9qLHWJZLK9C7yM8zL5LSnu8SV/iVRbh1CcE0WABWiz03qbA6r8sGuw2CF1Bg+8K/8 n5ovAjUapLyx4vdHMm9iP5slC3McTnPrcSrRwVDZ2ttMtkHmgHTug8Stom+1STnXgq4t Db1w== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.152 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:references:from:to:subject:in-reply-to:date:message-id :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=LUlSVCcHpzLLkMuWSPConUp81rhy5WvzEA1SJ3i/K+Q=; b=JhiWhxm3R4ZO5mcpkFoN9miYs3S3r3/+0MBKli5Io6fFSrsU8Jkoe49dAjnvH8FOJE TJJrPGoyxXg/k2YC9d7jDq9OcgDDQoa38Bmp3jCdMo0LjjZ/wDWspEjRLAEjwbokydMH jIFxykeKhjXU3lLFbP9V/xmaRwSGpleggC6uBItqH6YyP6YOHFoj8lVMLbw+5BWHsUm/ kZOJdGMuLKrsYNjFEVflhGm0rCT2v00Sp6m61r0joBu48fo/FGIpl1OhtDuvlGIUt70H Xe+HESm5n/FIFhR2MiABv85ibowwtGDgj9bhIhXrSzG5PyKY/6BxEv1y02vWERxb937l hcdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=sender:x-gm-message-state:references:from:to:subject:in-reply-to :date:message-id: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=LUlSVCcHpzLLkMuWSPConUp81rhy5WvzEA1SJ3i/K+Q=; b=j1C3wj423FPbEasz2NCxy8fiAx6pJFxDn4oA2A37t0a8uLPdBButKeqx5c64tGNEmE k9hFYZGr8HmwqDl7wl/v+MYQ7dcghI69PGGSF1a2GVuAREgA8UHuiFDdPyISgwk8CKb4 Z53/ZBBgVVDead4ISftWs+yASqLpA8fsZzJdLjYus09CSx5KQSS9UFuKmuoilfwabkJ1 suODJmlJC9J0YX7v/5eQd6pABddWpY5oIWsyG5V6lj8RnHKYZDts/xtmnAH1PVJoBcQJ yZZAa8E10S9LyU9GDH+Iu13W5MUNjMHn7QxdFNijV2/la82mz34mCtJEIVKkTljkcHB9 9yPQ== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM533psSocOA+IA/M/cnZVfw5a7I36UQmahwQs5/Mb3nPWdY3IlndQ X4al3y4ptqwF1nUWPSYgBPU= X-Google-Smtp-Source: ABdhPJy0TNR7tNzKNTYv341ciOnmzWQXY2fV/8lu19gGEh3cWwtRMdPtdtfF4/FjP0RKxSuAJzD8lA== X-Received: by 2002:a05:6402:8:: with SMTP id d8mr3296455edu.61.1640184799844; Wed, 22 Dec 2021 06:53:19 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:6402:2750:: with SMTP id z16ls1038801edd.2.gmail; Wed, 22 Dec 2021 06:53:17 -0800 (PST) X-Received: by 2002:a50:9510:: with SMTP id u16mr3213389eda.134.1640184797225; Wed, 22 Dec 2021 06:53:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1640184797; cv=none; d=google.com; s=arc-20160816; b=JXTKKbTHVd0suck6pmZ78PM13wq6mjgFGsbbJkgvBB5QolR2H6W5AcS0/YO4yRPVxs FKwn5UKt4y6e1mcYKzJwETmi2wmRj80RX3KP6nQSkjxITGTRCIqK9NmKLwbM0Z4lgAbf QeSshvruR6p3p0C1NVjyOm9As2p3YIU6HIrjVuZHKXKauwA+oRNwzKPXAQQZj+oB8n2n k0qoUYNlIQpN2kOm5FI+QRWRQMmHo8/qI/0zipJQtdViQnhhgCay8RqI1PPWW5PPd2/f GOrbhU7R2QY79MJl83XWQ/CUWi1IaBUFzof8aRPxxrBHY+SONA4kkt5hFVOcpFPkbAuc Qz1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:message-id:date:in-reply-to:subject:to:from:references; bh=M1miQf80GcSyAX449ZzLc6NBWv9qG8HImdosvQoXJ+Y=; b=SyIRLwwKh8Hin0nsRoBLFn/2Jo2Qn/1JwVaiNDs0u2wu2Gxgy6/mA5I2M8ym4tVxSd wSTdNfKi4C/8k7keOSzJwcnlzqa6VQYFYVRFlQCe8cap6jHJlLUGJBXVnnuZsP1XDpO3 uPi++kOzqyTStp4IMRcKPl18VcFlx618pYBpwTOTfEUMnNwab+PiQx9j7Cue+43Fxy1r yjvM69xeAIFzCv4IQaxgMP+Yt1qf2gwo79pIVutpWQOIxrkJCWYfB4B2GbTG17riy6n1 jxZN03nFpRv/PYHuo3KU1WzMdDR9Lh8kXPdzde8Pw+u4vrTyfGIXLZpuK3XsJtuwQKv3 P1XQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.152 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org Original-Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org. [80.241.56.152]) by gmr-mx.google.com with ESMTPS id eb8si118542edb.0.2021.12.22.06.53.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Dec 2021 06:53:17 -0800 (PST) Received-SPF: pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.152 as permitted sender) client-ip=80.241.56.152; Original-Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:105:465:1:4:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4JJxCJ2hmpzQk6x for ; Wed, 22 Dec 2021 15:53:16 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de In-reply-to: <186dfc25-8ebd-43ef-8a5b-0fae22106712n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> X-Original-Sender: albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of albert+pandoc-9EawChwDxG8hFhg+JK9F0w@public.gmane.org designates 80.241.56.152 as permitted sender) smtp.mailfrom=albert+pandoc-9EawChwDxG8hFhg+JK9F0w@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:29832 Archived-At: be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org writes: > 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: > > See the [Quick introduction]. > > So, the links are given by the full title of the respective section they > refer to. Here's a quick rewrite of my old code that should do it. If there are internal links that should not be modified, simply add a title or a class to that link, and the filter will leave it alone. ``` lua local sections = {} function populate_section_numbers (doc) function populate (blocks) for _, div in pairs(blocks) do if div.t == 'Div' and div.attributes.number then local header = div.content[1] if header and header.t == 'Header' then sections['#' .. div.attr.identifier] = { number = div.attributes.number, } populate(div.content) end end end end populate(pandoc.utils.make_sections(true, nil, doc.blocks)) end function resolve_section_ref (link) -- don't edit non-internal links or those with a title or a class. if link.target:sub(1, 1) ~= '#' or #link.classes > 0 or #link.title > 0 then return nil end local section = sections[link.target] if section then link.content = {pandoc.Str(section.number .. '\u{A0}')} .. link.content return link end end return { {Pandoc = populate_section_numbers}, {Link = resolve_section_ref} } ``` -- Albert Krewinkel GPG: 8eed e3e2 e8c5 6f18 81fe e836 388d c0b2 1f63 1124