From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/29827 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org" Newsgroups: gmane.text.pandoc Subject: Lua filter for section numbers in internal references Date: Wed, 22 Dec 2021 01:16:01 -0800 (PST) Message-ID: <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_7312_580911705.1640164561359" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28294"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBDQ6N25ANMINFWMLRYDBUBGOX7U5C-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Wed Dec 22 10:16:08 2021 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-oi1-f189.google.com ([209.85.167.189]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mzxjB-00072m-8x for gtp-pandoc-discuss@m.gmane-mx.org; Wed, 22 Dec 2021 10:16:05 +0100 Original-Received: by mail-oi1-f189.google.com with SMTP id p203-20020acaf1d4000000b002c660fc9a2esf772796oih.9 for ; Wed, 22 Dec 2021 01:16:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=sender:date:from:to:message-id:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=Ww2WN7kgeSlS+9JkYkV2vxWE/qnhEUNH1ZtO6x7sPuE=; b=iTgRPzMcKRtWc48UicjkHnjqFlOUbz5SSiQN0GElf0Kvk6qxwjXzhMWa0Cjt5ev3Kw XaWCiA+EktUM+0EzKoooSD7hF6pXHF9k8b6Visu3pO+tRIBjJJl5tNc7JhrU9FNrXaBV Bt9YF+tGau3PjWaFYD5P91VzNe/jN0Y93FWXAPgafMyST2ffix37CrXdSfWBOjrmMqm3 xZXK4/0nmb47o7xBythSqhs9c3YYS8Nr8mC6Fct/2OXFWEmi/yNNM5C2ALj7FSP8fzGe /7XQh4CHSbX8lwIk1WeJpt9wsnTGXKmmOXlLtrnE/Sg3z0wcSpEIxh2zBCUxKWNgbF4H ITmg== 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: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=Ww2WN7kgeSlS+9JkYkV2vxWE/qnhEUNH1ZtO6x7sPuE=; b=ebzumc4mIMtkBNMfy6eEUEHsSgV1SBn4ZPiC7aEg10y/l6uy7zRY2p7AG5Kromumk5 Egxd9aPYFxz3tSlXNBhe0ZWNAARvYbD0C39W/g5TmnJXeeA9ZeTCP7hGDcSP+SCbMcCV RfDZf896HNlqnwFKArK36N+04FBT82Sj1OEJy8VCjJY6w8mZ8+cfHZsMLS5mM4oUfYbv GgvY+M9t7J11mwjiNfLRiaBNKcSytoQzL91LEyuC5FFQ1jyyBNAsHblrPzqF3hejtZ/q LhIop48yD1Xa7CzbQ3uKhCjUcyNf7Ttkz2asBnT1jAsPbbS5RiA0P5dtwvw5U58ekTtC 0Tmw== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: AOAM530pLxyACdLwOOlS62VOeLo3YCR+sdMKe/GNhYfiWzLWHRCfxGuJ IQlULUqgZBvvyPG0sC3J7H8= X-Google-Smtp-Source: ABdhPJxljKcDXjP89dy37zVjbP/x861qE05pt3Y7QIk9GFma0IbntxXP7ep41rsFfLpfwKzdbhcpDA== X-Received: by 2002:a05:6830:4cf:: with SMTP id s15mr1469978otd.219.1640164563495; Wed, 22 Dec 2021 01:16:03 -0800 (PST) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:aca:41d5:: with SMTP id o204ls309022oia.9.gmail; Wed, 22 Dec 2021 01:16:02 -0800 (PST) X-Received: by 2002:aca:1115:: with SMTP id 21mr156209oir.137.1640164561897; Wed, 22 Dec 2021 01:16:01 -0800 (PST) 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:29827 Archived-At: ------=_Part_7312_580911705.1640164561359 Content-Type: multipart/alternative; boundary="----=_Part_7313_17868737.1640164561359" ------=_Part_7313_17868737.1640164561359 Content-Type: text/plain; charset="UTF-8" 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 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. I found a recipe at stackoverflow (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 = (require 'pandoc.utils').make_sections local section_numbers = {} function populate_section_numbers (doc) function populate (elements) for _, el in pairs(elements) do if el.t == 'Div' and el.attributes.number then section_numbers['#' .. el.attr.identifier] = 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) ~= '#' then return nil end local section_number = pandoc.Str(section_numbers[link.target]) return pandoc.Link({section_number}, link.target, link.title, link.attr) end return { {Pandoc = populate_section_numbers}, {Link = 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 attributes 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, 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/186dfc25-8ebd-43ef-8a5b-0fae22106712n%40googlegroups.com. ------=_Part_7313_17868737.1640164561359 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi,

I am trying to make a Lua filter that will replace t= he normal link text in internal links with section numbers. I want to use i= nternal links in my markdown document like this:

&= nbsp; See the [Quick introduction].
=

So, the links are given by the full title of the respec= tive section they refer to. I found a recipe at stackoverflow (https://stac= koverflow.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-introdu= ction)

This is the Lua code:

=
local make_sections =3D (require 'pandoc.= utils').make_sections
local section_numbers =3D {}

function popul= ate_section_numbers (doc)
  function populate (elements)
  =   for _, el in pairs(elements) do
      if el.t =3D= =3D 'Div' and el.attributes.number then
        sect= ion_numbers['#' .. el.attr.identifier] =3D el.attributes.number
  &= nbsp;     populate(el.content)
      end
&nb= sp;   end
  end
  populate(make_sections(true, nil, do= c.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])
  retur= n pandoc.Link({section_number}, link.target, link.title, link.attr)
end<= br>
return {
  {Pandoc =3D populate_section_numbers},
  = {Link =3D resolve_section_ref}
}



While I do understand what it does, I cannot fin= d out how to change it to my case. How can I retrieve the part written in [= ] instead of the attributes when scanning the document for those internal l= inks? Or is the not even possible? 

Any idea = is appreciated.


Torsten

--
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/186dfc25-8ebd-43ef-8a5b-0fae22106712n%40googlegroups.= com.
------=_Part_7313_17868737.1640164561359-- ------=_Part_7312_580911705.1640164561359--