]> git.lyx.org Git - lyx.git/commitdiff
DocBook: in bibliographies, fix support for editors.
authorThibaut Cuvelier <tcuvelier@lyx.org>
Mon, 26 Feb 2024 14:50:12 +0000 (15:50 +0100)
committerThibaut Cuvelier <tcuvelier@lyx.org>
Mon, 26 Feb 2024 14:52:35 +0000 (15:52 +0100)
Also, add TODOs for similar problems lurking around.

autotests/export/docbook/basic.xml
src/insets/InsetBibtex.cpp

index b589ee63b977e63b2114c5b5c09a8b56c416b3af..87c951f359236674c47502ca53d0bc1658458b61 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!-- This DocBook file was created by LyX 2.4.0dev
   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">
+<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>I am a title</title>
 <author>
 <m:math display="inline">
  
 <m:mrow>
- <m:mrow>
-  <m:mspace width="6px"/>
-  <m:mi>w</m:mi>
-  <m:mi>i</m:mi>
-  <m:mi>t</m:mi>
-  <m:mi>h</m:mi>
-  <m:mspace width="6px"/>
-  <m:mi>a</m:mi>
-  <m:mspace width="6px"/>
-  <m:mi>f</m:mi>
-  <m:mi>o</m:mi>
-  <m:mi>r</m:mi>
-  <m:mi>m</m:mi>
-  <m:mi>u</m:mi>
-  <m:mi>l</m:mi>
-  <m:mi>a</m:mi>
- </m:mrow>
+ <m:mspace width="6px"/>
+ <m:mi>w</m:mi>
+ <m:mi>i</m:mi>
+ <m:mi>t</m:mi>
+ <m:mi>h</m:mi>
+ <m:mspace width="6px"/>
+ <m:mi>a</m:mi>
+ <m:mspace width="6px"/>
+ <m:mi>f</m:mi>
+ <m:mi>o</m:mi>
+ <m:mi>r</m:mi>
+ <m:mi>m</m:mi>
+ <m:mi>u</m:mi>
+ <m:mi>l</m:mi>
+ <m:mi>a</m:mi>
 </m:mrow>
 </m:math>
 </inlineequation>. </para>
 </blockquote>
-<para>Now, we're outside quotes.</para>
+<para>Now, we&#8217;re outside quotes.</para>
 <informalequation>
 <alt role='tex'>Formula!</alt>
 <m:math display="block">
  
 <m:mrow>
- <m:mrow>
-  <m:mi>F</m:mi>
-  <m:mi>o</m:mi>
-  <m:mi>r</m:mi>
-  <m:mi>m</m:mi>
-  <m:mi>u</m:mi>
-  <m:mi>l</m:mi>
-  <m:mi>a</m:mi>
-  <m:mo>!</m:mo>
- </m:mrow>
+ <m:mi>F</m:mi>
+ <m:mi>o</m:mi>
+ <m:mi>r</m:mi>
+ <m:mi>m</m:mi>
+ <m:mi>u</m:mi>
+ <m:mi>l</m:mi>
+ <m:mi>a</m:mi>
+ <m:mo>!</m:mo>
 </m:mrow>
 </m:math>
 </informalequation>
@@ -420,6 +416,9 @@ I am no more code. </para>
 </personname>
 </author>
 </authorgroup>
+<editor>
+<personname>The editor</personname>
+</editor>
 <bibliomisc role="note">An optional note</bibliomisc>
 </biblioentry>
 <biblioentry xml:id="small">
index b073f619e61ce64e83ba28e8147b4b304771e022..6d38631f81aa2a8b794175b6aa4b7214ae2a9738 100644 (file)
@@ -1128,6 +1128,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
                make_pair("url", "uri")
        };
        // Relations between documents.
+       // TODO: some elements should be mutually exclusive; right now, all of them are output.
        vector<pair<string, string>> relations = { // <bibtex, docbook biblioset relation>
                make_pair("journal", "journal"),
                make_pair("journaltitle", "journal"),
@@ -1144,9 +1145,11 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
        toDocBookTag["fullnames:author"] = "SPECIFIC"; // No direct translation to DocBook: <authorgroup>.
        toDocBookTag["publisher"] = "SPECIFIC"; // No direct translation to DocBook: <publisher>.
        toDocBookTag["address"] = "SPECIFIC"; // No direct translation to DocBook: <publisher>.
-       toDocBookTag["editor"] = "editor";
+       toDocBookTag["editor"] = "SPECIFIC";  // No direct translation to DocBook: <editor><personname/orgname>.
+       toDocBookTag["fullbynames:editor"] = "SPECIFIC";  // No direct translation to DocBook: <editor><personname/orgname>.
        toDocBookTag["institution"] = "SPECIFIC"; // No direct translation to DocBook: <org>.
 
+       // TODO: some elements should be mutually exclusive; right now, all of them are output.
        toDocBookTag["title"] = "title";
        toDocBookTag["fulltitle"] = "title";
        toDocBookTag["quotetitle"] = "title";
@@ -1159,6 +1162,7 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
        toDocBookTag["year"] = "SPECIFIC"; // No direct translation to DocBook: <pubdate>.
        toDocBookTag["month"] = "SPECIFIC"; // No direct translation to DocBook: <pubdate>.
 
+       // TODO: some elements should be mutually exclusive; right now, all of them are output.
        toDocBookTag["journal"] = "SPECIFIC"; // No direct translation to DocBook: <biblioset>.
        toDocBookTag["journaltitle"] = "SPECIFIC"; // No direct translation to DocBook: <biblioset>.
        toDocBookTag["fulljournaltitle"] = "SPECIFIC"; // No direct translation to DocBook: <biblioset>.
@@ -1359,6 +1363,38 @@ void InsetBibtex::docbook(XMLStream & xs, OutputParams const &) const
                                eraseTag("fullnames:author");
                        }
 
+                       // <editor>
+                       // Example: http://tdg.docbook.org/tdg/5.1/editor.html
+                       if (hasTag("editor") || hasTag("fullbynames:editor")) {
+                               // If several editor tags are present, only output one.
+                               const docstring editorName = getTag(hasTag("editor") ? "editor" : "fullbynames:editor");
+
+                               // Arbitrarily decide that the editor is always a person. There is no reliable information in the input
+                               // to make the distinction between a person (<personname>) and an organisation (<orgname>).
+                               xs << xml::StartTag("editor");
+                               xs << xml::CR();
+                               xs << xml::StartTag("personname");
+                               xs << editorName;
+                               xs << xml::EndTag("personname");
+                               xs << xml::CR();
+                               xs << xml::EndTag("editor");
+                               xs << xml::CR();
+
+                               if (hasTag("editor") && hasTag("fullbynames:editor")) {
+                                       xs << XMLStream::ESCAPE_NONE <<
+                                                       from_utf8("<!-- Several editor tags in the reference. Other editor tag: ") +
+                                                       getTag("fullbynames:editor") + from_utf8(" -->\n");
+                               }
+
+                               // Erase all editor tags that might be present, even if only one is output.
+                               if (hasTag("editor")) {
+                                       eraseTag("editor");
+                               }
+                               if (hasTag("fullbynames:editor")) {
+                                       eraseTag("fullbynames:editor");
+                               }
+                       }
+
                        // <abstract>
                        if (hasTag("abstract")) {
                                // Split the paragraphs on new line.