From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31231 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: name name Newsgroups: gmane.text.pandoc Subject: Re: Heading References: Looking for the best possible approach Date: Tue, 16 Aug 2022 11:41:57 -0700 (PDT) Message-ID: <9dfb80b3-422c-4e95-9b22-ad5ab378f990n@googlegroups.com> References: <8b08b876-118d-41cb-9475-e097d069fc1cn@googlegroups.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_658_2042654959.1660675317454" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34897"; mail-complaints-to="usenet@ciao.gmane.io" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD35HTOSWYHRB5WJ56LQMGQEDRAIAXI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Tue Aug 16 20:42:02 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-yw1-f184.google.com ([209.85.128.184]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oO1Vq-0008pa-3I for gtp-pandoc-discuss@m.gmane-mx.org; Tue, 16 Aug 2022 20:42:02 +0200 Original-Received: by mail-yw1-f184.google.com with SMTP id 00721157ae682-31f56f635a9sf118248137b3.4 for ; Tue, 16 Aug 2022 11:42:01 -0700 (PDT) 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-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :sender:from:to:cc; bh=t8pyS9swV3K/pNOU3uGK5jT0HQJAUQ+xGm3eE+KZ+Qw=; b=NKL6nuqSicHCclqrCHmpQXAW4L2916ER+rBHMaJyjHd2lBoev3LZPfK07IycBxPJKd +2Kt/O9RtxGB9iB8XW9aY+hJc4P481yyRF0yE1nkxR5eokpERu4yBYgHP4dIdcqWNp/P ll0u+ADw3mK5poCHBY8s0TDlWmApuE6YZv5vUJFy2BkGreUl3DfhMGNyoF28taoXJl0u IxEry2bmXk3yTzCcoZi6lEmPKSWFlduJ6luViX1uXj04FsyT1Dx3ICpEhGCLoXJKoTct 9FWu++xp3+02PKtqQ+GkuI9f6Sw9l2ifqnpHG+6p0qmN2DLx9MVoNwGdQSKnS9ofiYBJ C+9w== 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-sender :mime-version:subject:references:in-reply-to:message-id:to:from:date :from:to:cc; bh=t8pyS9swV3K/pNOU3uGK5jT0HQJAUQ+xGm3eE+KZ+Qw=; b=cLnXcheoKkBc0k0aH3Y8SNjSWfv0m0sYMeSxmRSHLec4YXLRLk6WFbVZIKF5hg6yzs 6nfPWy4ZlUi/eY3GOUx7NjYEbEBt8EM0z9hl6yEJ1xe2/ObyCzizZbduT4CHtYCa8J7C FEKziwabYt4TYogrjiwIKPvgCnHUjT7ZARQpahQx43a9e2h7UuvGxAGo51xf3nuMRART rJnfcpbfL2TLqCLnYNN8srJH58bywrYd+W1epTLh9wcxa9MAeEkNuN2BwxDx8olq+XPT WNnlNw5bpm30Qh5zGP8fJcf5L4JUb1Nq3uwfAKufJnCqqj3d9tfeD/Q8iKBdjU6Bl/eJ +SSQ== 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-sender:mime-version:subject:references:in-reply-to :message-id:to:from:date:x-gm-message-state:sender:from:to:cc; bh=t8pyS9swV3K/pNOU3uGK5jT0HQJAUQ+xGm3eE+KZ+Qw=; b=DUDd4SYaRApZ52DgDJ/8QB4Xj2TK16Z35GJaXVMEaxV9bC1Sj7DhNVjYFi8Os83InY KUERTTBqqMstAGUw2Q3pge1EQ4g+mgkUjbMQbKdCS+Y/imFp5u2jW87z6JsWEcxvBhiR lPJ91MZaCRBckEW6KKA7dII/HALS7xfxflFo+pJoc6TW83kbvo1uMBY1+f7EBtpuKXN/ HUr5C17JRG/nlCccyecleA8JtvHq6oK0RfR88CRMjgL0588Z50TnSYF2QkW/9fXcVvL2 C3sgo55B6wPiNnHUY+tqR+0xyVOC0yEAJmZm8yGyarzJQXJX9hsvTn/1PBNZdOqUIM+n igFg== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACgBeo1xb36nrTcKVtEciM/HjP7DCQ/3+2d4irk1el79fHFPlhjZdmbr tkRDx1KG9KG+r0Wn3bfgsQc= X-Google-Smtp-Source: AA6agR5eIFrwlXsOp89rK+2+2NXWNGliNw+LYpW7YppovrbZqkLwYnrnr6r5EIC9iRrHFKXZkLhrVA== X-Received: by 2002:a81:5754:0:b0:334:d3cb:3f2c with SMTP id l81-20020a815754000000b00334d3cb3f2cmr162938ywb.189.1660675321052; Tue, 16 Aug 2022 11:42:01 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a81:1cc:0:b0:31e:dfc9:3ae7 with SMTP id 195-20020a8101cc000000b0031edfc93ae7ls6656508ywb.7.-pod-prod-gmail; Tue, 16 Aug 2022 11:41:58 -0700 (PDT) X-Received: by 2002:a81:7c54:0:b0:31f:61f9:f2fb with SMTP id x81-20020a817c54000000b0031f61f9f2fbmr18026456ywc.260.1660675318036; Tue, 16 Aug 2022 11:41:58 -0700 (PDT) In-Reply-To: X-Original-Sender: ivan20151013-Re5JQEeQqe8AvxtiuMwx3w@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:31231 Archived-At: ------=_Part_658_2042654959.1660675317454 Content-Type: multipart/alternative; boundary="----=_Part_659_389234260.1660675317454" ------=_Part_659_389234260.1660675317454 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks BPJ, and thanks Bastien Dumont, for a working workaround. What I don't understand, though, is that why such an essential thing=20 doesn't work out of the box. The similar syntax (I mean the *idea*, not the= =20 syntax itself) works, for example, for hyperlinks; and so why it doesn't=20 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=20 > need about the headers, and then update the link text. Here is such a=20 > filter: > > ``` automatic-link-text.lua > local header_id_to_content =3D {} > > local function get_header_infos(header) > local id =3D header.identifier > if id then > header_id_to_content[id] =3D header.content > end > end > > local function update_internal_link_content(link) > if string.sub(link.target, 1, 1) =3D=3D '#' > and #link.content =3D=3D 0 > and header_id_to_content[string.sub(link.target, 2)] > then > link.content =3D header_id_to_content[string.sub(link.target, 2)] > end > return link > end > > return { > { Header =3D get_header_infos }, > { Link =3D update_internal_link_content } > } > ``` > > The following command: > > ``` > pandoc -L automatic-link-text.lua <<< ' > # My header {#headerid} > > See [](#headerid). > ' > ``` > > outputs: > > ``` >

My header

>

See My header.

> ``` > > > Le Tuesday 16 August 2022 =C3=A0 05:12:15AM, name name a =C3=A9crit : > > I'm new to Pandoc. > >=20 > > From what I see in the manual, it seems there are only two ways to crea= te > > heading references: > >=20 > > ~~~ > > # Heading {#identifier .class .class key=3Dvalue key=3Dvalue} > > ~~~ > >=20 > > ~~~ > > For more information about <...>, see [the previous=20 > section](#identifier). > >=20 > > or > > For more information about <...>, see [Heading][]. > > ~~~ > >=20 > > The drawback of using the 2nd approach is that if you change the headin= g > > itself, the link will be broken. > >=20 > > And the drawback of using the 1st approach is that you need to write (a= nd > > update, if necessary) the link text manually. > >=20 > > Is it possible to have the best from both approaches without their=20 > drawbacks? > > Here is what I search for: > >=20 > > ~~~ > > For more information about <...>, see [][#identifier]. > >=20 > > or maybe > > For more information about <...>, see [](#identifier). > > ~~~ > >=20 > > 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= =20 > the > > same time, the displayed text is updated automatically, so if you chang= e=20 > the > > heading "Heading" to "My Heading", this won't break the link. > >=20 > > -- > > You received this message because you are subscribed to the Google Grou= ps > > "pandoc-discuss" group. > > To unsubscribe from this group and stop receiving emails from it, send= =20 > 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= . > >=20 > > References: > >=20 > > [1] mailto:pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > [2]=20 > https://groups.google.com/d/msgid/pandoc-discuss/8b08b876-118d-41cb-9475-= e097d069fc1cn%40googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter > > --=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/9dfb80b3-422c-4e95-9b22-ad5ab378f990n%40googlegroups.com. ------=_Part_659_389234260.1660675317454 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks BPJ, and thanks  Bastien Dumont, for a working workaround.

What I don't u= nderstand, 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) work= s, for example, for hyperlinks; and so why it doesn't work for headings?

~~~
[hyperlink text][hyperlink label]

[hyp= erlink 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 firs= t 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 =3D {}

local function get_header_infos(header)
local id =3D header.identifier
if id then
header_id_to_content[id] =3D header.content
end
end

local function update_internal_link_content(link)
if string.sub(link.target, 1, 1) =3D=3D '#'
and #link.content =3D=3D 0
and header_id_to_content[string.sub(link.target, 2)]
then
link.content =3D header_id_to_content[string.sub(link.target, 2)]
end
return link
end

return {
{ Header =3D get_header_infos },
{ Link =3D update_internal_link_content }
}
```

The following command:

```
pandoc -L automatic-link-text.lua <<< '
# My header {#headerid}

See [](#headerid).
'
```

outputs:

```
<h1 id=3D"headerid">My header</h1>
<p>See <a href=3D"#headerid">My header</a>.= </p>
```


Le Tuesday 16 August 2022 =C3=A0 05:12:15AM, name name a =C3=A9crit :
> I'm new to Pandoc.
>=20
> From what I see in the manual, it seems there are only two ways to= create
> heading references:
>=20
> ~~~
> # Heading {#identifier .class .class key=3Dvalue key=3Dvalue}
> ~~~
>=20
> ~~~
> For more information about <...>, see [the previous section]= (#identifier).
>=20
> or
> For more information about <...>, see [Heading][].
> ~~~
>=20
> The drawback of using the 2nd approach is that if you change the h= eading
> itself, the link will be broken.
>=20
> And the drawback of using the 1st approach is that you need to wri= te (and
> update, if necessary) the link text manually.
>=20
> Is it possible to have the best from both approaches without their= drawbacks?
> Here is what I search for:
>=20
> ~~~
> For more information about <...>, see [][#identifier].
>=20
> or maybe
> For more information about <...>, see [](#identifier).
> ~~~
>=20
> These variations don't work, but the idea is that because the = link uses #
> identifier and not the heading text itself, it is not "fragil= e", and at the
> same time, the displayed text is updated automatically, so if you = change the
> heading "Heading" to "My Heading", this won= 9;t break the link.
>=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 email
> to [1]pandoc-discus...@= googlegroups.com.
> To view this discussion on the web visit [2]https://groups.google.com/d/msgid/
> pandoc-discuss/8b08b876-118d-41cb-9475-e097d069fc1cn%40googlegroups.com.
>=20
> References:
>=20
> [1] mailto:pandoc-discu= s...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
> [2] https://groups= .google.com/d/msgid/pandoc-discuss/8b08b876-118d-41cb-9475-e097d069fc1cn%40= googlegroups.com?utm_medium=3Demail&utm_source=3Dfooter

--
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/9dfb80b3-422c-4e95-9b22-ad5ab378f990n%40googlegroups.= com.
------=_Part_659_389234260.1660675317454-- ------=_Part_658_2042654959.1660675317454--