]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBibtex.cpp
Routines for calculating numerical labels for BibTeX citations.
[lyx.git] / src / insets / InsetBibtex.cpp
index 1a03a821f90ede5152765b6cb8ffb4e283c1db75..2c426c72f4e7f6ff74c8ac960dc3b13498a586ce 100644 (file)
@@ -22,6 +22,7 @@
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
 #include "MetricsInfo.h"
+#include "output_xhtml.h"
 #include "OutputParams.h"
 #include "TextClass.h"
 
@@ -49,10 +50,9 @@ namespace Alert = frontend::Alert;
 namespace os = support::os;
 
 
-InsetBibtex::InsetBibtex(Buffer const & buf, InsetCommandParams const & p)
-       : InsetCommand(p, "bibtex")
+InsetBibtex::InsetBibtex(Buffer * buf, InsetCommandParams const & p)
+       : InsetCommand(buf, p, "bibtex")
 {
-       Inset::setBuffer(const_cast<Buffer &>(buf));
        buffer_->invalidateBibinfoCache();
 }
 
@@ -897,6 +897,56 @@ void InsetBibtex::validate(LaTeXFeatures & features) const
 {
        if (features.bufferParams().use_bibtopic)
                features.require("bibtopic");
+       // FIXME XHTML
+       // It'd be better to be able to get this from an InsetLayout, but at present
+       // InsetLayouts do not seem really to work for things that aren't InsetTexts.
+       if (features.runparams().flavor == OutputParams::HTML)
+               features.addPreambleSnippet("<style type=\"text/css\">\n"
+                       "div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
+                       "span.bibtexlabel:before{ content: \"[\"; }\n"
+                       "span.bibtexlabel:after{ content: \"] \"; }\n"
+                       "</style>");
+}
+
+
+docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       BiblioInfo const & bibinfo = buffer().masterBibInfo();
+       vector<docstring> const & cites = bibinfo.citedEntries();
+       xs << StartTag("h2", "class='bibtex'")
+               << _("References")
+               << EndTag("h2")
+               << StartTag("div", "class='bibtex'");
+
+       // Now we loop over the entries
+       vector<docstring>::const_iterator vit = cites.begin();
+       vector<docstring>::const_iterator const ven = cites.end();
+       for (; vit != ven; ++vit) {
+               BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
+               if (biit == bibinfo.end())
+                       continue;
+               BibTeXInfo const & entry = biit->second;
+               xs << StartTag("div", "class='bibtexentry'");
+               // FIXME XHTML
+               // The same name/id problem we have elsewhere.
+               string const attr = "id='" + to_utf8(entry.key()) + "'";
+               xs << CompTag("a", attr);
+               docstring label = entry.label();
+               if (label.empty())
+                       label = entry.key();
+               xs << StartTag("span", "class='bibtexlabel'")
+                       << label 
+                       << EndTag("span");
+               // FIXME Right now, we are calling BibInfo::getInfo on the key,
+               // which will give us all the cross-referenced info. But for every
+               // entry, so there's a lot of repitition. This should be fixed.
+               xs << StartTag("span", "class='bibtexinfo'") 
+                       << bibinfo.getInfo(entry.key())
+                       << EndTag("span")
+                       << EndTag("div");
+       }
+       xs << EndTag("div");
+       return docstring();
 }