From e28c88767b86fdb520682f00898b4da145566779 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 11 Jun 2009 22:39:16 +0000 Subject: [PATCH] OK, now here's a big one: XHTML output for InsetBibtex. It's not perfect--- see the notes---but it does work reasonably well. And it will work a lot better when an unrelated patch of mine goes in: one that generally improves the display of BibTeX-derived information. Note how we use the TOC here, which has already gathered the information we need. This can also be done for other things. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30056 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/HTML/HTML.notes | 12 ++++-- src/insets/InsetBibtex.cpp | 75 ++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/development/HTML/HTML.notes b/development/HTML/HTML.notes index 223560f400..8b7f9e116e 100644 --- a/development/HTML/HTML.notes +++ b/development/HTML/HTML.notes @@ -17,6 +17,14 @@ These insets do nothing for XHTML: ERT, OptArg, Phantom These insets work but still need work: + InsetBibtex: There are a few issues here. One is that the output is not very + nice. This will be solved, though, by a patch of mine I seem to have forgotten + to finish. To get output that accorded with the BibTeX style, of course, we'd + have to parse the bbl file. I don't know if that's worth it. + Another issue concerns cross-references. At the moment, we simply use the + xref information for every entry, rather than listing the xref separately and + then referencing it. That should not be terribly hard, but it would take a bit + of work. InsetBox: We need a Length::asHTML() method and the like, but it basically works. though the CSS isn't there yet. InsetCitation: This has two limitations as of 11 VI 2009. The first is that we @@ -37,10 +45,6 @@ May need to make use here of TocWidget::itemInset, which should then be moved to TocBackend. These do not yet work and need some attention: - InsetBibtex: We should be able to collect the keys of references in - validate() and then use our parsed information to output some sort of - bibliography. Formatting is another question, but here again we could - try parsing the bbl file. InsetCommand: By default does nothing. That may be right? InsetExternal: I don't understand these so am not sure what to do. InsetFloat: This will need some work, again because I do not really understand diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 7b824bbf01..bb15688869 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -22,8 +22,10 @@ #include "FuncStatus.h" #include "LaTeXFeatures.h" #include "MetricsInfo.h" +#include "output_xhtml.h" #include "OutputParams.h" #include "TextClass.h" +#include "TocBackend.h" #include "frontends/alert.h" @@ -900,9 +902,78 @@ void InsetBibtex::validate(LaTeXFeatures & features) const } -int InsetBibtex::xhtml(odocstream &, OutputParams const &) const +namespace { + // used in xhtml to sort a list of BibTeXInfo objects + bool lSorter(BibTeXInfo const * lhs, BibTeXInfo const * rhs) + { + return lhs->getAbbreviatedAuthor() < rhs->getAbbreviatedAuthor(); + } +} + + +int InsetBibtex::xhtml(odocstream & os, OutputParams const &) const { - //Toc const & toc = buffer().tocBackend().toc("citation"); + // We are going to collect all the citation keys used in the document, + // getting them from the TOC. + Toc const & toc = buffer().tocBackend().toc("citation"); + Toc::const_iterator it = toc.begin(); + Toc::const_iterator en = toc.end(); + vector citekeys; + for (; it != en; ++it) { + if (it->str().empty()) + continue; + vector keys = getVectorFromString(it->str()); + vector::const_iterator dit = keys.begin(); + vector::const_iterator den = keys.end(); + for (; dit != den; ++dit) + citekeys.push_back(*dit); + } + if (citekeys.empty()) + return 0; + sort(citekeys.begin(), citekeys.end()); + unique(citekeys.begin(), citekeys.end()); + // We now have a sorted, unique list of the keys used in this document. + // We will now convert it to a list of the BibTeXInfo objects used in + // this document... + // FIXME We need to do something here about cross-references, if we + // want to be able to display them AS cross-references. Probably the + // easiest thing to do is to loop over the list again and add whatever + // cross-references we find, then sort and unique it, planning just to + // add the cross-references to the bibliography. + vector binfo; + vector::const_iterator cit = citekeys.begin(); + vector::const_iterator cen = citekeys.end(); + BiblioInfo const & bi = buffer().masterBibInfo(); + for (; cit != cen; ++cit) { + BiblioInfo::const_iterator bt = bi.find(*cit); + if (bt == bi.end()) + continue; + binfo.push_back(&(bt->second)); + } + // ...and sort it. + sort(binfo.begin(), binfo.end(), lSorter); + // Finally, then, we are ready for output. + os << "

" << _("References") << "

\n"; + os << "
\n"; + vector::const_iterator vit = binfo.begin(); + vector::const_iterator ven = binfo.end(); + // Now we loop over the entries + for (; vit != ven; ++vit) { + BibTeXInfo const * bip = *vit; + os << "

"; + os << ""; + docstring label = bip->label(); + if (label.empty()) + label = bip->key(); + os << "[" << 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. + os << "" << bi.getInfo(bip->key()) << ""; + os << "

\n"; + } + + os << "
\n"; return 0; } -- 2.39.5