]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetBibtex.cpp
Pure HTML output for math macros.
[lyx.git] / src / insets / InsetBibtex.cpp
index 0dd60da08a13c674e46939a6411ead76b8acfcc0..dff066f12c69a0551ac05ae433005286d8fb5cab 100644 (file)
@@ -21,7 +21,7 @@
 #include "FuncRequest.h"
 #include "FuncStatus.h"
 #include "LaTeXFeatures.h"
-#include "MetricsInfo.h"
+#include "output_xhtml.h"
 #include "OutputParams.h"
 #include "TextClass.h"
 
@@ -49,17 +49,16 @@ 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();
 }
 
 
 InsetBibtex::~InsetBibtex()
 {
-       if (isBufferValid())
+       if (isBufferLoaded())
                buffer_->invalidateBibinfoCache();
 }
 
@@ -219,7 +218,7 @@ static string normalizeName(Buffer const & buffer,
        OutputParams const & runparams, string const & name, string const & ext)
 {
        string const fname = makeAbsPath(name, buffer.filePath()).absFilename();
-       if (FileName(name).isAbsolute() || !FileName(fname + ext).isReadableFile())
+       if (FileName::isAbsolute(name) || !FileName(fname + ext).isReadableFile())
                return name;
        if (!runparams.nice)
                return fname;
@@ -268,7 +267,6 @@ int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const
 
                if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
                    not_from_texmf) {
-
                        // mangledFilename() needs the extension
                        DocFileName const in_file = DocFileName(try_in_file);
                        database = removeExtension(in_file.mangledFilename());
@@ -303,7 +301,6 @@ int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const
        if (!warned_about_spaces &&
            runparams.nice && db_out.find(' ') != docstring::npos) {
                warned_about_spaces = true;
-
                Alert::warning(_("Export Warning!"),
                               _("There are spaces in the paths to your BibTeX databases.\n"
                                              "BibTeX will be unable to find them."));
@@ -317,7 +314,6 @@ int InsetBibtex::latex(odocstream & os, OutputParams const & runparams) const
                        style = split(style, bibtotoc, ',');
        }
 
-
        // line count
        int nlines = 0;
 
@@ -411,8 +407,7 @@ support::FileNameList InsetBibtex::getBibFiles() const
        vector<docstring>::const_iterator it = bibfilelist.begin();
        vector<docstring>::const_iterator en = bibfilelist.end();
        for (; it != en; ++it) {
-               FileName const file = 
-                       findtexfile(changeExtension(to_utf8(*it), "bib"), "bib");
+               FileName const file = getBibTeXPath(*it, buffer());
 
                if (!file.empty())
                        vec.push_back(file);
@@ -901,6 +896,77 @@ 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>");
+}
+
+
+// FIXME 
+// docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
+// And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
+docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       BiblioInfo const & bibinfo = buffer().masterBibInfo();
+       vector<docstring> const & cites = bibinfo.citedEntries();
+       CiteEngine const engine = buffer().params().citeEngine();
+       bool const numbers = 
+               (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
+
+       xs << html::StartTag("h2", "class='bibtex'")
+               << _("References")
+               << html::EndTag("h2")
+               << html::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 << html::StartTag("div", "class='bibtexentry'");
+               // FIXME XHTML
+               // The same name/id problem we have elsewhere.
+               string const attr = "id='" + to_utf8(entry.key()) + "'";
+               xs << html::CompTag("a", attr);
+               docstring citekey;
+               if (numbers)
+                       citekey = entry.citeNumber();
+               else {
+                       docstring const auth = entry.getAbbreviatedAuthor();
+                       // we do it this way so as to access the xref, if necessary
+                       // note that this also gives us the modifier
+                       docstring const year = bibinfo.getYear(*vit, true);
+                       if (!auth.empty() && !year.empty())
+                               citekey = auth + ' ' + year;
+               }
+               if (citekey.empty()) {
+                       citekey = entry.label();
+                       if (citekey.empty())
+                               citekey = entry.key();
+               }
+               xs << html::StartTag("span", "class='bibtexlabel'")
+                       << citekey
+                       << html::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 << html::StartTag("span", "class='bibtexinfo'") 
+                       << bibinfo.getInfo(entry.key(), buffer(), true)
+                       << html::EndTag("span")
+                       << html::EndTag("div");
+               xs.cr();
+       }
+       xs << html::EndTag("div");
+       return docstring();
 }