+ "span.bibtexlabel:after{ content: \"] \"; }");
+}
+
+
+void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
+{
+ buffer().registerBibfiles(getBibFiles());
+ // record encoding of bib files for biblatex
+ string const enc = (params()["encoding"] == from_ascii("default")) ?
+ string() : to_ascii(params()["encoding"]);
+ bool invalidate = false;
+ if (buffer().params().bibEncoding() != enc) {
+ buffer().params().setBibEncoding(enc);
+ invalidate = true;
+ }
+ map<string, string> encs = getFileEncodings();
+ map<string, string>::const_iterator it = encs.begin();
+ for (; it != encs.end(); ++it) {
+ if (buffer().params().bibFileEncoding(it->first) != it->second) {
+ buffer().params().setBibFileEncoding(it->first, it->second);
+ invalidate = true;
+ }
+ }
+ if (invalidate)
+ buffer().invalidateBibinfoCache();
+}
+
+
+map<string, string> InsetBibtex::getFileEncodings() const
+{
+ vector<string> ps =
+ getVectorFromString(to_utf8(getParam("file_encodings")), "\t");
+ std::map<string, string> res;
+ for (string const & s: ps) {
+ string key;
+ string val = split(s, key, ' ');
+ res[key] = val;
+ }
+ return res;
+}
+
+
+docstring InsetBibtex::getRefLabel() const
+{
+ if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
+ return buffer().B_("Bibliography");
+ return buffer().B_("References");
+}
+
+
+void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
+ UpdateType, TocBackend & backend) const
+{
+ if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
+ return;
+
+ docstring const str = getRefLabel();
+ TocBuilder & b = backend.builder("tableofcontents");
+ b.pushItem(cpit, str, output_active);
+ b.pop();
+}
+
+
+int InsetBibtex::plaintext(odocstringstream & os,
+ OutputParams const & op, size_t max_length) const
+{
+ docstring const reflabel = getRefLabel();
+
+ // We could output more information here, e.g., what databases are included
+ // and information about options. But I don't necessarily see any reason to
+ // do this right now.
+ if (op.for_tooltip || op.for_toc || op.for_search) {
+ os << '[' << reflabel << ']' << '\n';
+ return PLAINTEXT_NEWLINE;
+ }
+
+ BiblioInfo bibinfo = buffer().masterBibInfo();
+ bibinfo.makeCitationLabels(buffer());
+ vector<docstring> const & cites = bibinfo.citedEntries();
+
+ size_t start_size = os.str().size();
+ docstring refoutput;
+ refoutput += reflabel + "\n\n";
+
+ // Tell BiblioInfo our purpose
+ CiteItem ci;
+ ci.context = CiteItem::Export;
+
+ // 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) {
+ if (start_size + refoutput.size() >= max_length)
+ break;
+ BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
+ if (biit == bibinfo.end())
+ continue;
+ BibTeXInfo const & entry = biit->second;
+ refoutput += "[" + entry.label() + "] ";
+ // 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.
+ refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
+ }
+ os << refoutput;
+ return int(refoutput.size());