> On 27 Sep 2023, at 15:18, Peter Eisentraut <peter@eisentraut.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[@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