From: Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org>
To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Subject: Re: Lua filter for section numbers in internal references
Date: Wed, 22 Dec 2021 11:12:07 +0000 [thread overview]
Message-ID: <YcMIB/cIBo3JwTa5@localhost> (raw)
In-Reply-To: <186dfc25-8ebd-43ef-8a5b-0fae22106712n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
It seems that you can use pandoc-crossref for such case: see the manual here (https://github.com/lierdakil/pandoc-crossref/blob/master/docs/index.md).
To answer the technical part of the question, `pandoc -t native <<< 'See the [Quick introduction].'` shows that "[Quick introduction]" is parsed as a normal string. You can create a span instead by adding a class: [Quick introduction]{.sectionref}. But even then, it will be simplier to parse its content if it is limited to one string (like "Quick-introduction").
Le Wednesday 22 December 2021 à 01:16:01AM, be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org a écrit :
> 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 [1]pandoc-discuss+unsubscribe-/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.
>
> References:
>
> [1] mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups.google.com/d/msgid/pandoc-discuss/186dfc25-8ebd-43ef-8a5b-0fae22106712n%40googlegroups.com?utm_medium=email&utm_source=footer
--
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/YcMIB/cIBo3JwTa5%40localhost.
next prev parent reply other threads:[~2021-12-22 11:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-22 9:16 be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org
[not found] ` <186dfc25-8ebd-43ef-8a5b-0fae22106712n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-22 11:12 ` Bastien DUMONT [this message]
2021-12-22 12:07 ` be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org
2021-12-22 12:12 ` be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org
[not found] ` <c8df6f45-5119-4d7c-b95c-ce1ecfc57a64n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2021-12-22 13:46 ` Bastien DUMONT
2021-12-22 14:53 ` Albert Krewinkel
[not found] ` <87sfukn12g.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2021-12-23 6:59 ` be...-GbY3e145aRm8w6eVIr4Tmg@public.gmane.org
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YcMIB/cIBo3JwTa5@localhost \
--to=bastien.dumont-vwifzpto/vqstnjn9+bgxg@public.gmane.org \
--cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).