]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCitation.cpp
Fix use of std::regex_match
[lyx.git] / src / insets / InsetCitation.cpp
index 4d1bb682c5fefe0c2972f0a080448225e5d11368..5d35f9d5a49f52bacf2282c4bcbe8aa6df2f9c40 100644 (file)
@@ -24,6 +24,7 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "output_xhtml.h"
+#include "output_docbook.h"
 #include "ParIterator.h"
 #include "texstream.h"
 #include "TocBackend.h"
@@ -322,8 +323,8 @@ inline docstring wrapCitation(docstring const & key,
                return content;
        // we have to do the escaping here, because we will ultimately
        // write this as a raw string, so as not to escape the tags.
-       return "<a href='#LyXCite-" + html::cleanAttr(key) + "'>" +
-                       html::htmlize(content, XHTMLStream::ESCAPE_ALL) + "</a>";
+       return "<a href='#LyXCite-" + xml::cleanAttr(key) + "'>" +
+                       xml::xmlize(content, XMLStream::ESCAPE_ALL) + "</a>";
 }
 
 } // anonymous namespace
@@ -384,7 +385,7 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
        // we need to give the other defaults, too, to set it.
        vector<docstring> keys =
                getVectorFromString(key, from_ascii(","), false, false);
-       for (auto k : keys) {
+       for (auto const & k : keys) {
                if (biblist.find(k) == biblist.end()) {
                        setBroken(true);
                        break;
@@ -545,23 +546,37 @@ static docstring const cleanupWhitespace(docstring const & citelist)
 }
 
 
-int InsetCitation::docbook(odocstream & os, OutputParams const &) const
+void InsetCitation::docbook(XMLStream & xs, OutputParams const &) const
 {
-       os << from_ascii("<citation>")
-          << cleanupWhitespace(getParam("key"))
-          << from_ascii("</citation>");
-       return 0;
+       if (getCmdName() == "nocite")
+               return;
+
+       // Split the different citations (on ","), so that one tag can be output for each of them.
+       string citations = to_utf8(getParam("key")); // Citation strings are not supposed to be too fancy.
+       if (citations.find(',') == string::npos) {
+               xs << xml::CompTag("biblioref", "endterm=\"" + citations + "\"");
+       } else {
+               size_t pos = 0;
+               while (pos != string::npos) {
+                       pos = citations.find(',');
+                       xs << xml::CompTag("biblioref", "endterm=\"" + citations.substr(0, pos) + "\"");
+                       citations.erase(0, pos + 1);
+
+                       if (pos != string::npos) {
+                               xs << ", "; 
+                       }
+               }
+       }
 }
 
 
-docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetCitation::xhtml(XMLStream & xs, OutputParams const &) const
 {
-       string const & cmd = getCmdName();
-       if (cmd == "nocite")
+       if (getCmdName() == "nocite")
                return docstring();
 
        // have to output this raw, because generateLabel() will include tags
-       xs << XHTMLStream::ESCAPE_NONE << generateLabel(true);
+       xs << XMLStream::ESCAPE_NONE << generateLabel(true);
 
        return docstring();
 }
@@ -588,7 +603,7 @@ void InsetCitation::forOutliner(docstring & os, size_t const, bool const) const
 // engine, e.g. \cite[]{} for the basic engine.
 void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
 {
-       // When this is a child compiled on its own, we use the childs
+       // When this is a child compiled on its own, we use the children
        // own bibinfo, else the master's
        BiblioInfo const & bi = runparams.is_child
                        ? buffer().masterBibInfo() : buffer().bibInfo();