git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] asciidoctor-extensions.rb: handle "book" doctype in linkgit

From
MÅMartin Ågren <martin.agren@gmail.com>
Date
Sep 22, 2019, 11:57 UTC
Message-ID
<78d131f31b760addf5d22d4f95f04eda9aa45927.1569152396.git.martin.agren@gmail.com>
In-Reply-To
<cover.1569152396.git.martin.agren@gmail.com>

user-manual.txt is the only file we process using the "book" doctype. When we use AsciiDoc, user-manual.conf ensures that the linkgit macro expands into something like

  <ulink url="git-foo.html">git-foo(1)</ulink>

in user-manual.xml, which we then process into a clickable link, both in user-manual.html and user-manual.pdf. With Asciidoctor, user-manual.conf is ignored (this is expected) and our Asciidoctor-specific implementation of linkgit kicks in:

  <citerefentry>
    <refentrytitle>git-foo</refentrytitle><manvolnum>1</manvolnum>
  </citerefentry>

This eventually renders as "git-foo(1)", which is not bad, but it doesn't turn into a link.

Teach our Asciidoctor-specific implementation of the linkgit macro that if the doctype is "book", we should emit <ulink .../> just like we do with AsciiDoc. While we're doing this, future-proof by supporting a "prefix". The implementation in user-manual.conf doesn't support this, and we don't need this for now because user-manual.txt is the only file we process this way (and it's immediately in Documentation/).

Signed-off-by: Martin Ågren <martin.agren@gmail.com>
---
 Documentation/asciidoctor-extensions.rb | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/Documentation/asciidoctor-extensions.rb b/Documentation/asciidoctor-extensions.rb
index 0089e0cfb8..70a0956663 100644
--- a/Documentation/asciidoctor-extensions.rb
+++ b/Documentation/asciidoctor-extensions.rb
@@ -9,8 +9,11 @@ module Git
       named :chrome
 
       def process(parent, target, attrs)
-        if parent.document.basebackend? 'html'
-          prefix = parent.document.attr('git-relative-html-prefix')
+        prefix = parent.document.attr('git-relative-html-prefix')
+        if parent.document.doctype == 'book'
+          "<ulink url=\"#{prefix}#{target}.html\">" \
+          "#{target}(#{attrs[1]})</ulink>"
+        elsif parent.document.basebackend? 'html'
           %(<a href="#{prefix}#{target}.html">#{target}(#{attrs[1]})</a>)
         elsif parent.document.basebackend? 'docbook'
           "<citerefentry>\n" \
-- 
2.23.0
Previous: Martin ÅgrenNext: Martin Ågren
Message 4 of 5 in “fix user-manual with Asciidoctor”
  1. 0/4 fix user-manual with AsciidoctorMartin Ågren, Sep 22, 2019
  2. 1/4 user-manual.txt: add missing section labelMartin Ågren, Sep 22, 2019
  3. 2/4 user-manual.txt: change header notationMartin Ågren, Sep 22, 2019
  4. 3/4 asciidoctor-extensions.rb: handle "book" doctype in linkgitMartin Ågren, Sep 22, 2019
  5. 4/4 user-manual.txt: render ASCII art correctly under AsciidoctorMartin Ågren, Sep 22, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.