public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: name name <ivan20151013-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: Heading References: Looking for the best possible approach
Date: Tue, 16 Aug 2022 11:41:57 -0700 (PDT)	[thread overview]
Message-ID: <9dfb80b3-422c-4e95-9b22-ad5ab378f990n@googlegroups.com> (raw)
In-Reply-To: <Yvueqq6Qo2xt3BCG@localhost>


[-- Attachment #1.1: Type: text/plain, Size: 3988 bytes --]

Thanks BPJ, and thanks  Bastien Dumont, for a working workaround.

What I don't understand, though, is that why such an essential thing 
doesn't work out of the box. The similar syntax (I mean the *idea*, not the 
syntax itself) works, for example, for hyperlinks; and so why it doesn't 
work for headings?

~~~
[hyperlink text][hyperlink label]

[hyperlink label]: http://site.web/page.html
~~~

On Tuesday, August 16, 2022 at 4:42:08 PM UTC+3 Bastien Dumont wrote:

> You can do that using a filter that first collects the information you 
> need about the headers, and then update the link text. Here is such a 
> filter:
>
> ``` automatic-link-text.lua
> local header_id_to_content = {}
>
> local function get_header_infos(header)
> local id = header.identifier
> if id then
> header_id_to_content[id] = header.content
> end
> end
>
> local function update_internal_link_content(link)
> if string.sub(link.target, 1, 1) == '#'
> and #link.content == 0
> and header_id_to_content[string.sub(link.target, 2)]
> then
> link.content = header_id_to_content[string.sub(link.target, 2)]
> end
> return link
> end
>
> return {
> { Header = get_header_infos },
> { Link = update_internal_link_content }
> }
> ```
>
> The following command:
>
> ```
> pandoc -L automatic-link-text.lua <<< '
> # My header {#headerid}
>
> See [](#headerid).
> '
> ```
>
> outputs:
>
> ```
> <h1 id="headerid">My header</h1>
> <p>See <a href="#headerid">My header</a>.</p>
> ```
>
>
> Le Tuesday 16 August 2022 à 05:12:15AM, name name a écrit :
> > I'm new to Pandoc.
> > 
> > From what I see in the manual, it seems there are only two ways to create
> > heading references:
> > 
> > ~~~
> > # Heading {#identifier .class .class key=value key=value}
> > ~~~
> > 
> > ~~~
> > For more information about <...>, see [the previous 
> section](#identifier).
> > 
> > or
> > For more information about <...>, see [Heading][].
> > ~~~
> > 
> > The drawback of using the 2nd approach is that if you change the heading
> > itself, the link will be broken.
> > 
> > And the drawback of using the 1st approach is that you need to write (and
> > update, if necessary) the link text manually.
> > 
> > Is it possible to have the best from both approaches without their 
> drawbacks?
> > Here is what I search for:
> > 
> > ~~~
> > For more information about <...>, see [][#identifier].
> > 
> > or maybe
> > For more information about <...>, see [](#identifier).
> > ~~~
> > 
> > These variations don't work, but the idea is that because the link uses #
> > identifier and not the heading text itself, it is not "fragile", and at 
> the
> > same time, the displayed text is updated automatically, so if you change 
> the
> > heading "Heading" to "My Heading", this won't break the link.
> > 
> > --
> > 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To view this discussion on the web visit [2]
> https://groups.google.com/d/msgid/
> > pandoc-discuss/8b08b876-118d-41cb-9475-e097d069fc1cn%40googlegroups.com.
> > 
> > References:
> > 
> > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> > [2] 
> https://groups.google.com/d/msgid/pandoc-discuss/8b08b876-118d-41cb-9475-e097d069fc1cn%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/9dfb80b3-422c-4e95-9b22-ad5ab378f990n%40googlegroups.com.

[-- Attachment #1.2: Type: text/html, Size: 6077 bytes --]

      reply	other threads:[~2022-08-16 18:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-16 12:12 name name
     [not found] ` <8b08b876-118d-41cb-9475-e097d069fc1cn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-08-16 13:25   ` BPJ
2022-08-16 13:42   ` Bastien DUMONT
2022-08-16 18:41     ` name name [this message]

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=9dfb80b3-422c-4e95-9b22-ad5ab378f990n@googlegroups.com \
    --to=ivan20151013-re5jqeeqqe8avxtiumwx3w@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).