From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31153 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?SmnFmcOtIFdvbGtlcg==?= Newsgroups: gmane.text.pandoc Subject: Re: Filter for automatic md > HTML block level element ID creation? Date: Sat, 30 Jul 2022 16:34:51 +0200 Message-ID: <15c136b0-7748-e24d-65a5-1072d34b7a04@gmail.com> References: Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="35862"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-X-From: pandoc-discuss+bncBCP5LNUQRMBRBDMDSWLQMGQECSJVIOY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Jul 30 16:34:57 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wm1-f60.google.com ([209.85.128.60]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oHnYO-00098x-Gt for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 30 Jul 2022 16:34:56 +0200 Original-Received: by mail-wm1-f60.google.com with SMTP id r10-20020a05600c284a00b003a2ff6c9d6asf5503653wmb.4 for ; Sat, 30 Jul 2022 07:34:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659191696; cv=pass; d=google.com; s=arc-20160816; b=e7qS7yI2shA/LGpg3B7816jPQhKdHod9/2U6dGZZLu1SkphWcB3vkc7sUWeAU523Fv SEL44t4+5/CRfrYrPRmtu8xDUm87IqQkBUeV3byeQlcexeMSZXcoptvdng2hqK2rsUnr klrbLK2CokK3gu9gOqjJKOJx1mTclq94RTce1BzmVm2+fdKFZm9Ie4NeDoCGpmhf/Lpw fi2CN1eMeh+TM9DUYoh0uzZf1lg919bA1orPYvjlallpvKcmTL73nphp+5542dKmgxSX ByuzMH2VhE5edV2qExlzgasXPAt/rnstpB8n91lcFxAP5nGL66TdJoe39J6dTHwc+7iC ACng== 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:content-transfer-encoding :in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:sender:dkim-signature:dkim-signature; bh=cjIPRvtdCxracYcNvn1rdDDoxgMN2dLedmN/9uif18w=; b=dbaLOojN71ASmNePofCo0MrBgE5647pO3s2MmEkJhOahV+EY6JOEbohMMZ0BzvpOTN XE6j2pdDpLZL5zvVi4hgxTlQ4MVKTrbBsLbq1jx+ZYcBt+nlWUtfwq8F7d5qVafQteZB Uftfdk0xI/FgU4J+fQAWElTHNNy/zC+/dDV+zrPvlFzxJB/LfSA4BUkE96r5qxMp1ij8 Oy0XsL21a1h9ek73U++PyR1JENpFBdv2e+UR+6LqsywK7FT945ewk58NF2NiCjKAdgSI lr9PVs5ieiXanXlrv7BmvLnhRfPydfJ6fLiIAhQI6cf2WqbIdFfOTR/bck12HFNjVcQg Pg8A== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bSBt4xaG; spf=pass (google.com: domain of woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::42b as permitted sender) smtp.mailfrom=woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc; bh=cjIPRvtdCxracYcNvn1rdDDoxgMN2dLedmN/9uif18w=; b=q4PXoLllgWAgFrHIS7uE9QLkW0LHT9FpnXBAiaCeRz6jFq1m6ajjgXVV6q6REgylAo 6EUUWzqrAVBlnNTqc3d8HN/jzJkWWc3F/2DOxQrYM+AWBKrAqGSxSwb2kVr0SRJPtqWX fLmuoHuDvu+UZn5jx97l/7d2De2639WPIYTaQ6EGg1cTNRtHyckB3WzH5tVIdvDzaiSv 7XYbs/lAZFjRts6xf4m9Me74yXB68ICogWoB52j9Cl1W4o4lO8p5qFLLqdJj4CYg18kZ vBRWn7quNPpFuSLDW0HVOpFPwi/RhVKNX7riOn/4D5RCaNNHMaFCUY9Y93D1nmg5sZf0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc; bh=cjIPRvtdCxracYcNvn1rdDDoxgMN2dLedmN/9uif18w=; b=H3f1AnWG+uFk8NuO6PrZuku4vPL7udcsQN//ef58yKWGg++Ng3SyGztqxmduVLbfhM pRaYb8plURu1tZ1dpqy1JDlJPA/30nP6EGb5YvXr7Icbzht6AawQXjRM6noT8aXLH/Ej pwMfGKk5uqrvf2/XRMwfKlfCZEQVu4TRTbM/m/HO3YK2QzBKKK3DFkMlXRAW4tAN58tf gXPxUkTK6WhLY+sXXmMaNZzIuudUvtNZyZWS+QMQ0nnW/MHMd+MCZhiUwQS8RdVMqOUq LOOgN23fQgBZUD9TtJJYFmARDt+v5/NP3Uw2ajwIDi5SZHBqkwP8xN0ig3S+n/LqhO5K bCzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender :content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:sender:from:to:cc; bh=cjIPRvtdCxracYcNvn1rdDDoxgMN2dLedmN/9uif18w=; b=Pb7iPU6rL0g5QtGBgTcYZ4duhm72S27xrKkc0AZKfztCIaVNEvzUlNPPFI+muyo4cw hnxiDRDYeFHOrOS/rwlyv5Rcj2w3YK/6YBA5YD3RNKzV5JIwxuvhrXGyV98mmjUgPI6t Y0c4uoAzLZVaF1A7oFSsIwd4imPsF9Ppnqc/vDlQZUAkHI150aIHcs3988JkHQLhd8Qi xsE3n1BD3zJusLu9ON7FAqJhS7BwpD7hXAhOA/dUeidJ2LbWd12tB7Q30CpItkjPo4qE bm8ybEY30kWhawxteEdiAThTx Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACgBeo3rwFRqbM1VyvGdCPifIwE+A7iEJJK3Z9teNeYx22X6UDi25/fW PAiiQ8G5R7nnDPfpl/SKXC4= X-Google-Smtp-Source: AA6agR50qBMosOzCjy0ejVWcgvaLAREIgU193aOsK+wqEpALujyWOm7fvmJTsLCw9t/iTbcqgjTRzQ== X-Received: by 2002:a5d:6e8d:0:b0:21e:48a4:b267 with SMTP id k13-20020a5d6e8d000000b0021e48a4b267mr4961801wrz.507.1659191695940; Sat, 30 Jul 2022 07:34:55 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:adf:d216:0:b0:21e:e644:c8 with SMTP id j22-20020adfd216000000b0021ee64400c8ls6549620wrh.3.-pod-prod-gmail; Sat, 30 Jul 2022 07:34:52 -0700 (PDT) X-Received: by 2002:adf:ea0f:0:b0:220:5c01:22b7 with SMTP id q15-20020adfea0f000000b002205c0122b7mr872032wrm.597.1659191692335; Sat, 30 Jul 2022 07:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659191692; cv=none; d=google.com; s=arc-20160816; b=uZlOC4UeOEk/eBb1MKwLzKNz9VRdRhnVcF905kmQDOi4uubJGfkXBfCzRPXzYtJC1A jHuWPbb+flXotxXuUpE0rJTaEUpmLCC9bDaHDRcSyBJKdCgXmmqvjQIGghEBmSQvLacP KX5N9Qlct7fho5Sm/rjQznXbd5FQJz4HwNs9OEfwYqDrKH7BeWb1SY40m2IHAiZEjd0m tfLSdGRQdQ/woJY9m8cnopbuyVWzW3eDpLoT2vdZlacHBqKMOf007KudDAKwUjW9AxX+ zWM0n5XcIqICBPOZnZEtrVjz5LM1/8+BDS+KEtoptm5+InAh+xDmTH8jqCydMThiTNjp VSrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=k5MkgGtgK2qvXfrkU1UkO5JC458+9jvM617BMBYTS8w=; b=pUcwe4slZKYSuNBkZZ4YfJqiy4Dn5pD0pZCiBHbWRSFTo+Nfg0hRgXouXWkms/AuAn 39L6WRUNQH9+5UCP5vy5+1s2g4zS/Bp1zBUhHTzYCLXJZHNBUTizUFkyovIujehw5rXX MxVtDOwLj7A4ae+rqT9aDbfBuW2w8QA2MwUU/5dzJcuBytpyoay71Qew50700OAgvSZq 2IN2iRfPAyW17pVDxwyPEb346rPH4Lj9YzDYAllPXDz9squ3Ml2drY0MCkgEWwbyJCQF S68ZofO3Xgv274eI/f4+OhCN8MoX5sZuJe2NuzJN1TOlvehtgnHVjsoARjSUYxnw+KON CXSA== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bSBt4xaG; spf=pass (google.com: domain of woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::42b as permitted sender) smtp.mailfrom=woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Original-Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com. [2a00:1450:4864:20::42b]) by gmr-mx.google.com with ESMTPS id bh1-20020a05600005c100b0021d8e03fd0csi257326wrb.5.2022.07.30.07.34.52 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Jul 2022 07:34:52 -0700 (PDT) Received-SPF: pass (google.com: domain of woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::42b as permitted sender) client-ip=2a00:1450:4864:20::42b; Original-Received: by mail-wr1-x42b.google.com with SMTP id z17so4299100wrq.4 for ; Sat, 30 Jul 2022 07:34:52 -0700 (PDT) X-Received: by 2002:adf:d1c7:0:b0:21e:7eb3:3f1f with SMTP id b7-20020adfd1c7000000b0021e7eb33f1fmr5145192wrd.427.1659191691868; Sat, 30 Jul 2022 07:34:51 -0700 (PDT) Original-Received: from [192.168.0.14] ([185.137.144.10]) by smtp.gmail.com with ESMTPSA id m15-20020adffa0f000000b0021e5f32ade7sm6574175wrr.68.2022.07.30.07.34.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 30 Jul 2022 07:34:51 -0700 (PDT) Content-Language: cs In-Reply-To: X-Original-Sender: woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=bSBt4xaG; spf=pass (google.com: domain of woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org designates 2a00:1450:4864:20::42b as permitted sender) smtp.mailfrom=woljiri-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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:31153 Archived-At: (I wrote this message accidentally as a reply not to the mailing list,=20 so I send it once again to the list.) Below, you can get the source code of a Lua filter that adds anchors to=20 all paragraphs, list items (list items are also paragraphs in Pandoc)=20 and headings. The anchors are numbered (#para-0, #para-1 etc.). If you really need To the end of every paragraph (or other block), a link to the paragraph=20 is added. Both links and anchors are given a class name. You can style them. I=20 recommend this CSS: .para-link { font-size: .7em; text-decoration: none; color: inherit; opacity: .7; } .para-link:hover, .para-link:focus { text-decoration: underline; opacity: 1; } Usage of the filter: pandoc inputfile.md -o outputfile.html --lua-filter=3Dblockids.lua (Where the file blockids.lua is the filter file. Save it to the data dir=20 subdirectory =E2=80=98filters/=E2=80=99 or the cwd.) The code follows. -- Adds IDs to every block of the document. -- MIT License --=20 -- Copyright (c) 2022 Ji=C5=99=C3=AD Wolker --=20 -- Permission is hereby granted, free of charge, to any person obtaining=20 a copy -- of this software and associated documentation files (the "Software"),=20 to deal -- in the Software without restriction, including without limitation the=20 rights -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sel= l -- copies of the Software, and to permit persons to whom the Software is -- furnished to do so, subject to the following conditions: --=20 -- The above copyright notice and this permission notice shall be=20 included in -- all copies or substantial portions of the Software. --=20 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,=20 EXPRESS OR -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT=20 SHALL THE -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,=20 ARISING FROM, -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER=20 DEALINGS IN THE -- SOFTWARE. paragraph_number =3D 0 function Block(elem) local blocks_to_modify =3D { ["Para"] =3D true, ["Div"] =3D true, ["Header"] =3D true, } if blocks_to_modify[elem.t] then id =3D "para-"..paragraph_number paragraph_number =3D paragraph_number + 1 anchor =3D pandoc.Link({ }, "#"..id) anchor.classes:insert("para-anchor") anchor.identifier =3D id link =3D pandoc.Link("link", "#"..id) link.classes:insert("para-link") -- At the start of the block: elem.content:insert(1, anchor) -- At the end of the block: elem.content:insert(pandoc.Space()) elem.content:insert(link) -- Return the modified block. return elem end end --=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/15c136b0-7748-e24d-65a5-1072d34b7a04%40gmail.com.