]> git.lyx.org Git - lyx.git/commitdiff
DocBook: in InsetInfo, ensure that no db:date is inserted within a db:date.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Sun, 8 Oct 2023 19:06:46 +0000 (21:06 +0200)
committerScott Kostyshak <skostysh@lyx.org>
Tue, 10 Oct 2023 13:57:17 +0000 (09:57 -0400)
autotests/export/docbook/insetinfo.lyx
autotests/export/docbook/insetinfo.xml
src/Paragraph.cpp
src/insets/InsetInfo.cpp

index 1ae6c307606f57ae09827ebea8e7951a08b05870..a1b04a54f9e5bea25d7f45a51200fd9112dd6c5d 100644 (file)
@@ -91,6 +91,17 @@ Test:
  InsetInfo
 \end_layout
 
+\begin_layout Date
+
+\lang japanese-cjk
+\begin_inset Info
+type  "moddate"
+arg   "long"
+\end_inset
+
+
+\end_layout
+
 \begin_layout Standard
 
 \lang spanish
index 48ba1d802d4dc15a95048a8a520a61f3d7dcfa70..dd0dd6630cf5cb118f1f3f08a89139c1ae6eb2bd 100644 (file)
@@ -2,6 +2,9 @@
 <!-- This DocBook file was created by LyX 2.4.0~RC1.devel
   See https://www.lyx.org/ for more information -->
 <article xml:lang="en-US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
+<info>
 <title>Test: InsetInfo</title>
+<date>2023-10-08</date>
+</info>
 <para>Véase la <emphasis><phrase role="localized">User's Guide</phrase></emphasis> o <emphasis><phrase role="localized">Additional Features</phrase></emphasis> para más detalles.</para>
 </article>
\ No newline at end of file
index 333aeb8862cbda0c70e4d2b0832d5dcfcba89132..5ac03fa474429cbfecfbcbb0394e0ec53fb04677 100644 (file)
@@ -3635,11 +3635,11 @@ std::tuple<vector<xml::FontTag>, vector<xml::EndFontTag>> computeDocBookFontSwit
 
 std::tuple<std::vector<docstring>, std::vector<docstring>, std::vector<docstring>>
     Paragraph::simpleDocBookOnePar(Buffer const & buf,
-                                                      OutputParams const & runparams,
-                                                      Font const & outerfont,
-                                                      pos_type initial,
-                                                      bool is_last_par,
-                                                      bool ignore_fonts) const
+                                   OutputParams const & runparams,
+                                   Font const & outerfont,
+                                   pos_type initial,
+                                   bool is_last_par,
+                                   bool ignore_fonts) const
 {
        // Return values: segregation of the content of this paragraph.
        std::vector<docstring> prependedParagraphs; // Anything that must be output before the main tag of this paragraph.
@@ -3669,6 +3669,7 @@ std::tuple<std::vector<docstring>, std::vector<docstring>, std::vector<docstring
             }
         }
     }
+       rp.lastid = id();
 
     // State variables for the main loop.
     auto xs = new XMLStream(os); // XMLStream has no copy constructor: to create a new object, the only solution
index 1f50dfef5ff9437edc52275f414cea21ef7327cb..b08eb7b815b73237f50a3d54b9b47225f88c33c7 100644 (file)
@@ -1726,9 +1726,20 @@ void InsetInfo::docbook(XMLStream & xs, OutputParams const & rp) const
                        break;
                }
 
-               xml::openTag(xs, "date", "role=\"" + role + "\"", "inline");
+               // A db:date cannot be nested within a db:date. This case typically happens when the document class defines a
+               // Date layout. In this case, avoid outputting a new db:date. This means that InsetInfo cannot add a role on top
+               // of the previous db:date, hence add it as a comment. (Another solution would be an XML processing instruction,
+               // but this case is not common enough.) Adding the role to the already output tag might have consequences for
+               // some document classes where the layout already has a role or uses the same role for another purpose.
+               const bool isWithinDate = buffer().getParFromID(rp.lastid).top().paragraph().layout().docbooktag() == "date";
+
+               if (!isWithinDate)
+                       xml::openTag(xs, "date", "role=\"" + role + "\"", "inline");
+               else
+                       xs << XMLStream::ESCAPE_NONE << from_ascii(std::string("<!-- ") + role + " -->");
                xs << qstring_to_ucs4(parseDate(buffer(), params_).toString(Qt::ISODate));
-               xml::closeTag(xs, "date", "inline");
+               if (!isWithinDate)
+                       xml::closeTag(xs, "date", "inline");
                break;
        }
 
@@ -1752,9 +1763,17 @@ void InsetInfo::docbook(XMLStream & xs, OutputParams const & rp) const
                }
 
                // DocBook has no specific element for time, so use a date.
-               xml::openTag(xs, "date", "(role=\"" + role + "\"", "inline");
+               // See the discussion above (DATE_INFO, MODDATE_INFO, and FIXDATE_INFO) for a discussion about the choices that
+               // have been made.
+               const bool isWithinDate = buffer().getParFromID(rp.lastid).top().paragraph().layout().docbooktag() == "date";
+
+               if (!isWithinDate)
+                       xml::openTag(xs, "date", "role=\"" + role + "\"", "inline");
+               else
+                       xs << XMLStream::ESCAPE_NONE << from_ascii(std::string("<!-- ") + role + " -->");
                xs << qstring_to_ucs4(parseTime(buffer(), params_).toString(Qt::ISODate));
-               xml::closeTag(xs, "date", "inline");
+               if (!isWithinDate)
+                       xml::closeTag(xs, "date", "inline");
                break;
        }