commit 7ff9f47b3d81da3549e1157b324be9f96bd01e29
Author: Thibaut Cuvelier <[email protected]>
Date:   Thu Jul 17 06:47:40 2025 +0200

    InsetRef: support several references in one inset in DocBook.
---
 src/insets/InsetRef.cpp | 57 +++++++++++++++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 14 deletions(-)

diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp
index 1193a0d6f1..3bef74abc7 100644
--- a/src/insets/InsetRef.cpp
+++ b/src/insets/InsetRef.cpp
@@ -351,7 +351,7 @@ void InsetRef::latex(otexstream & os, OutputParams const & 
rp) const
        } else if (cmd == "formatted") {
                vector<docstring> flabels;
                docstring prefix;
-               os << getFormattedCmd(data, flabels, prefix, 
buffer().masterParams().xref_package, use_caps, useRange());;
+               os << getFormattedCmd(data, flabels, prefix, 
buffer().masterParams().xref_package, use_caps, useRange());
                if ((use_cleveref || use_zref) && use_nolink)
                        os << "*";
                if (buffer().masterParams().xref_package == "refstyle" && 
use_plural)
@@ -585,21 +585,40 @@ int InsetRef::plaintext(odocstringstream & os,
 }
 
 
-void InsetRef::docbook(XMLStream & xs, OutputParams const &) const
+void InsetRef::docbook(XMLStream & xs, OutputParams const & rp) const
 {
-       docstring const & ref = getParam("reference");
+       // When there are several labels, iterate over them all
+       // and generate one xref per label: DocBook's xref only
+       // supports one target.
+       //
+       // Separate the targets with commas, as this is the only
+       // language-agnostic way to have several links. Not ideal,
+       // though (having "and" would be better between the last
+       // two labels), but DocBook doesn't offer better.
+       // This means that there could be output like:
+       //     on page 4, on page 5, on page 6
+       // for three references, with each of the "on page #" being
+       // generated by the DocBook processor.
+       vector<docstring> labels = getVectorFromString(getEscapedLabel(rp));
        string const & cmd = params().getCmdName();
-       docstring linkend = xml::cleanID(ref);
 
        // A name is provided, LyX will provide it. This is supposed to be a 
very rare case.
        // Link with linkend, as is it within the document (not outside, in 
which case xlink:href is better suited).
        docstring const & name = getParam("name");
        if (!name.empty()) {
-               docstring attr = from_utf8("linkend=\"") + linkend + 
from_utf8("\"");
+               bool first_iteration = true;
+               for (const docstring & label : labels) {
+                       if (!first_iteration) {
+                               xs << ", ";
+                       }
+                       first_iteration = false;
 
-               xs << xml::StartTag("link", to_utf8(attr));
-               xs << name;
-               xs << xml::EndTag("link");
+                       docstring attr = from_utf8("linkend=\"") + 
xml::cleanID(label) + from_utf8("\"");
+
+                       xs << xml::StartTag("link", to_utf8(attr));
+                       xs << name;
+                       xs << xml::EndTag("link");
+               }
                return;
        }
 
@@ -639,12 +658,22 @@ void InsetRef::docbook(XMLStream & xs, OutputParams const 
&) const
        // TODO: what about labelonly? I don't get how this is supposed to 
work...
 
        // No name, ask DocBook to generate one.
-       docstring attr = from_utf8("linkend=\"") + linkend + from_utf8("\"");
-       if (!xref_style.empty())
-               attr += " xrefstyle=\"" + xref_style + "\"";
-       xs << display_before;
-       xs << xml::CompTag("xref", to_utf8(attr));
-       xs << display_after;
+
+       bool first_iteration = true;
+       for (const docstring & label : labels) {
+               if (!first_iteration) {
+                       xs << ", ";
+               }
+               first_iteration = false;
+
+               docstring attr = from_utf8("linkend=\"") + xml::cleanID(label) 
+ from_utf8("\"");
+
+               if (!xref_style.empty())
+                       attr += " xrefstyle=\"" + xref_style + "\"";
+               xs << display_before;
+               xs << xml::CompTag("xref", to_utf8(attr));
+               xs << display_after;
+       }
 }
 
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to