From e70c04b3503ae092b6b57686486f0e9182fc8184 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Thu, 3 Dec 2009 21:06:41 +0000 Subject: [PATCH] CSS for InsetBibtex. We include this via the validate mechanism, and borrow the LatexFeatures::addPremableSnippet() method to do it. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32301 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 14 ++++++++------ src/LaTeXFeatures.cpp | 23 ++++++++++++++++++----- src/LaTeXFeatures.h | 4 +++- src/insets/InsetBibtex.cpp | 30 ++++++++++++++++++------------ 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e3ab0d298e..e5bca13233 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1432,15 +1432,17 @@ void Buffer::writeLyXHTMLSource(odocstream & os, // FIXME Get this during validation? What about other meta-data? os << "TBA\n"; - os << features.getTClassHTMLPreamble(); - - os << '\n'; + os << "\n\n" + << features.getTClassHTMLPreamble() + << "\n\n" + << from_utf8(features.getPreambleSnippets()); + os << "\n\n"; docstring const styleinfo = features.getTClassHTMLStyles(); if (!styleinfo.empty()) { - os << "\n"; + os << "\n"; } os << "\n\n"; } diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 5d35d03f40..21af632954 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -415,6 +415,7 @@ bool LaTeXFeatures::isAvailable(string const & name) void LaTeXFeatures::addPreambleSnippet(string const & preamble) { + LYXERR0(preamble); SnippetList::const_iterator begin = preamble_snippets_.begin(); SnippetList::const_iterator end = preamble_snippets_.end(); if (find(begin, end, preamble) == end) @@ -765,16 +766,28 @@ string const LaTeXFeatures::getPackages() const } +string LaTeXFeatures::getPreambleSnippets() const +{ + ostringstream snip; + SnippetList::const_iterator pit = preamble_snippets_.begin(); + SnippetList::const_iterator pend = preamble_snippets_.end(); + for (; pit != pend; ++pit) { + LYXERR0(*pit); + snip << *pit << '\n'; + } + LYXERR0(snip.str()); + return snip.str(); +} + + docstring const LaTeXFeatures::getMacros() const { odocstringstream macros; - if (!preamble_snippets_.empty()) + if (!preamble_snippets_.empty()) { macros << '\n'; - SnippetList::const_iterator pit = preamble_snippets_.begin(); - SnippetList::const_iterator pend = preamble_snippets_.end(); - for (; pit != pend; ++pit) - macros << *pit << '\n'; + macros << from_utf8(getPreambleSnippets()); + } if (mustProvide("papersize")) { if (runparams_.flavor == OutputParams::LATEX) diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index bc666ff34b..77497a854d 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -74,6 +74,8 @@ public: void showStruct() const; /// void addPreambleSnippet(std::string const &); + /// + std::string getPreambleSnippets() const; /// Add a feature name requirements void require(std::string const & name); /// Add a set of feature names requirements @@ -127,7 +129,7 @@ private: typedef std::set Features; /// Features features_; - /// Static preamble bits from the external material insets + /// Static preamble bits, from external templates, or anywhere else typedef std::list SnippetList; /// SnippetList preamble_snippets_; diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp index 459098486f..85b6248988 100644 --- a/src/insets/InsetBibtex.cpp +++ b/src/insets/InsetBibtex.cpp @@ -898,6 +898,12 @@ void InsetBibtex::validate(LaTeXFeatures & features) const { if (features.bufferParams().use_bibtopic) features.require("bibtopic"); + if (features.runparams().flavor == OutputParams::HTML) + features.addPreambleSnippet(""); } @@ -946,17 +952,17 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const // ...and sort it. sort(binfo.begin(), binfo.end(), lSorter); // Finally, then, we are ready for output. - xs << StartTag("h2", "class='bibliography'"); - xs << _("References"); - xs << EndTag("h2"); - xs << StartTag("div", "class='bibliography'"); + xs << StartTag("h2", "class='bibtex'") + << _("References") + << EndTag("h2") + << StartTag("div", "class='bibtex'"); // Now we loop over the entries vector::const_iterator vit = binfo.begin(); vector::const_iterator const ven = binfo.end(); for (; vit != ven; ++vit) { BibTeXInfo const * bip = *vit; - xs << StartTag("div", "class='bibentry'"); + xs << StartTag("div", "class='bibtexentry'"); // FIXME XHTML // The same name/id problem we have elsewhere. string const attr = "id='" + to_utf8(bip->key()) + "'"; @@ -964,16 +970,16 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const docstring label = bip->label(); if (label.empty()) label = bip->key(); - xs << StartTag("span", "class='biblabel'"); - xs << "[" << label << "] "; - xs << EndTag("span"); + 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='bibinfo'"); - xs << bi.getInfo(bip->key()); - xs << EndTag("span"); - xs << EndTag("div"); + xs << StartTag("span", "class='bibtexinfo'") + << bi.getInfo(bip->key()) + << EndTag("span") + << EndTag("div"); } xs << EndTag("div"); return docstring(); -- 2.39.5