]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCitation.cpp
Restore XHTML output for InsetCitation.
[lyx.git] / src / insets / InsetCitation.cpp
index 1dd3f725910dae4e96454b67828b5f6d4e93d684..93e79263f6f64f331457a3aee8a2b1611424a5e2 100644 (file)
@@ -20,6 +20,7 @@
 #include "DispatchResult.h"
 #include "FuncRequest.h"
 #include "LaTeXFeatures.h"
+#include "output_xhtml.h"
 #include "ParIterator.h"
 #include "TocBackend.h"
 
@@ -355,8 +356,8 @@ docstring basicLabel(docstring const & keyList, docstring const & after)
 ParamInfo InsetCitation::param_info_;
 
 
-InsetCitation::InsetCitation(InsetCommandParams const & p)
-       : InsetCommand(p, "citation")
+InsetCitation::InsetCitation(Buffer * buf, InsetCommandParams const & p)
+       : InsetCommand(buf, p, "citation")
 {}
 
 
@@ -383,9 +384,8 @@ bool InsetCitation::isCompatibleCommand(string const & cmd)
 }
 
 
-docstring InsetCitation:: toolTip(BufferView const & bv, int, int) const
+docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
 {
-       static unsigned int maxwdth = 80;
        Buffer const & buf = bv.buffer();
        // Only after the buffer is loaded from file...
        if (!buf.isFullyLoaded())
@@ -404,32 +404,12 @@ docstring InsetCitation:: toolTip(BufferView const & bv, int, int) const
        vector<docstring>::const_iterator en = keys.end();
        docstring tip;
        for (; it != en; ++it) {
-               docstring key_info = bi.getInfo(*it);
+               docstring const key_info = bi.getInfo(*it);
                if (key_info.empty())
                        continue;
                if (!tip.empty())
                        tip += "\n";
-               docstring newkey;
-               while (key_info.size() > maxwdth) {
-                       int i = maxwdth - 1;
-                       // find the last space
-                       for (; i >= 0; --i)
-                               if (key_info[i] == ' ')
-                                       break;
-                       if (i < 0) { 
-                               // no space found
-                               key_info = key_info.substr(0, maxwdth - 3) + "...";
-                               break;
-                       }
-                       if (!newkey.empty())
-                               newkey += "\n";
-                       newkey += key_info.substr(0, i);
-                       key_info = "  " + key_info.substr(i);
-               }
-               if (!newkey.empty())
-                       newkey += "\n";
-               newkey += key_info;
-               tip += newkey;
+               tip += wrap(key_info, -4);
        }
        return tip;
 }
@@ -438,8 +418,8 @@ docstring InsetCitation:: toolTip(BufferView const & bv, int, int) const
 
 docstring InsetCitation::generateLabel() const
 {
-       docstring const before = getParam("before");
-       docstring const after  = getParam("after");
+       docstring const before = getParam("before");
+       docstring const after  = getParam("after");
 
        docstring label;
        CiteEngine const engine = buffer().params().citeEngine();
@@ -487,7 +467,7 @@ void InsetCitation::updateLabels(ParIterator const &)
 void InsetCitation::addToToc(DocIterator const & cpit)
 {
        Toc & toc = buffer().tocBackend().toc("citation");
-       toc.push_back(TocItem(cpit, 0, cache.screen_label));
+       toc.push_back(TocItem(cpit, 0, getParam("key")));
 }
 
 
@@ -525,6 +505,48 @@ int InsetCitation::docbook(odocstream & os, OutputParams const &) const
 }
 
 
+docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       BiblioInfo const & bi = buffer().masterBibInfo();
+       docstring const & key_list = getParam("key");
+       if (key_list.empty())
+               return docstring();
+
+       // FIXME We shuld do a better job outputing different things for the
+       // different citation styles.   For now, we use square brackets for every
+       // case.
+       xs << "[";
+       docstring const & before = getParam("before");
+       if (!before.empty())
+               xs << before << " ";
+
+       vector<docstring> const keys = getVectorFromString(key_list);
+       vector<docstring>::const_iterator it = keys.begin();
+       vector<docstring>::const_iterator const en = keys.end();
+       bool first = true;
+       for (; it != en; ++it) {
+               BiblioInfo::const_iterator const bt = bi.find(*it);
+               if (bt == bi.end())
+                       continue;
+               BibTeXInfo const & bibinfo = bt->second;
+               if (!first) {
+                       xs << ", ";
+                       first = false;
+               }
+               docstring const & label = bibinfo.label();
+               docstring const & target = label.empty() ? *it : label;
+               string const attr = "href='#" + to_utf8(*it) + "'";
+               xs << StartTag("a", attr) << target << EndTag("a");
+       }
+
+       docstring const & after = getParam("after");
+       if (!after.empty())
+               xs << ", " << after;
+       xs << "]";
+       return docstring();
+}
+
+
 void InsetCitation::tocString(odocstream & os) const
 {
        plaintext(os, OutputParams(0));
@@ -535,13 +557,16 @@ void InsetCitation::tocString(odocstream & os) const
 // the \cite command is valid. Eg, the user has natbib enabled, inputs some
 // citations and then changes his mind, turning natbib support off. The output
 // should revert to \cite[]{}
-int InsetCitation::latex(odocstream & os, OutputParams const &) const
+int InsetCitation::latex(odocstream & os, OutputParams const & runparams) const
 {
        CiteEngine cite_engine = buffer().params().citeEngine();
        // FIXME UNICODE
        docstring const cite_str = from_utf8(
                asValidLatexCommand(getCmdName(), cite_engine));
 
+       if (runparams.inulemcmd)
+               os << "\\mbox{";
+
        os << "\\" << cite_str;
 
        docstring const & before = getParam("before");
@@ -553,6 +578,9 @@ int InsetCitation::latex(odocstream & os, OutputParams const &) const
 
        os << '{' << cleanupWhitespace(getParam("key")) << '}';
 
+       if (runparams.inulemcmd)
+               os << "}";
+
        return 0;
 }