Re: Hyperlinks for source file references

From: Daniel Gustafsson <daniel(at)yesql(dot)se>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Hyperlinks for source file references
Date: 2024-12-02 15:39:22
Message-ID: AD404098-0C3F-4A7D-BC82-4A0FE430B1C8@yesql.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

> On 27 Sep 2023, at 15:18, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:

> A slightly fancier variant that avoids having to hardcode the git web URL pattern in a bunch of places:
>
> You mark it up like
>
> <ulink url="file://src/include/access/tableam.h" type="pgsrc"/>
>
> and then write a bit of XSL to process that into whatever form you want.

Álvaro reminded me about this thread and after I went digging in old branches I
figured I'd share back where I left off in case anyone has any good ideas. The
smallest version I had was:

+<!-- Support for genering links to PG gitweb -->
+
+<xsl:template match="ulink[(at)type='gitweb']">
+ <xsl:call-template name="ulink">
+ <xsl:with-param name="url" select="concat('https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=', @url, ';hb=HEAD')"/>
+ </xsl:call-template>
+</xsl:template>

This rewrites the url attribute into a gitweb url and call ulink to complete
the rendering. The branch name should be an entity of course.

What I don't like about this is that the <ulink> can't be empty as the @url is
rewritten. Normally the @url will be the text portion of the link which is
what one want. With the above, we need this:

- <filename>src/backend/access/nbtree/README</filename> and
+ <ulink url="src/backend/access/nbtree/README" type="gitweb">src/backend/access/nbtree/README</ulink> and

Without that the link text will be the full URL which clearly isn't appealing.
I don't think that's a net improvement, what I would to achieve instead is an
empty tag like:

<ulink url="src/backend/foo.c" type="gitweb" />

In HTML it should render <a href="..">src/backend/foo.c</a> and for formats
without hyperlinks it should just render src/backend/foo.c. If the tag ins't
empty it should render the the link with the child element as usual.

Maybe it isn't hard, but I was unable to set the before-rewrite url attribute
as the child in case there are no children before invoking the ulink template.
Maybe someone has better XSLT skills and can make it work?

--
Daniel Gustafsson

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Shubham Khanna 2024-12-02 17:32:09 Re: pg_createsubscriber: publication-name and subscription-name options do not exist
Previous Message vignesh C 2024-12-02 11:27:34 Re: pg_createsubscriber: publication-name and subscription-name options do not exist