]> git.lyx.org Git - features.git/commitdiff
Initial work for XHTML output of the index. It just occurred to me the
authorRichard Heck <rgheck@comcast.net>
Tue, 12 Jan 2010 20:44:39 +0000 (20:44 +0000)
committerRichard Heck <rgheck@comcast.net>
Tue, 12 Jan 2010 20:44:39 +0000 (20:44 +0000)
other day that this would be easy, since the Index is in the TOC. There
is more to be done here still, though.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33000 a592a061-630c-0410-9148-cb99ea01b6c8

src/insets/InsetIndex.cpp
src/insets/InsetIndex.h

index 4fdbfc502ef028667e99fbcf04f76d88be367bdd..a9610d6b42421ba74f5e57644d5a8e5f42765ac4 100644 (file)
@@ -25,6 +25,7 @@
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "output_latex.h"
+#include "output_xhtml.h"
 #include "sgml.h"
 #include "TocBackend.h"
 
@@ -175,8 +176,13 @@ int InsetIndex::docbook(odocstream & os, OutputParams const & runparams) const
 }
 
 
-docstring InsetIndex::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetIndex::xhtml(XHTMLStream & xs, OutputParams const &) const
 {
+       // we just print an anchor, taking the paragraph ID from 
+       // our own interior paragraph, which doesn't get printed
+       std::string const magic = paragraphs().front().magicLabel();
+       std::string const attr = "id='" + magic + "'";
+       xs << CompTag("a", attr);
        return docstring();
 }
 
@@ -552,9 +558,65 @@ bool InsetPrintIndex::hasSettings() const
 }
 
 
-docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const &) const
+namespace {
+
+struct IndexEntry
 {
-       return docstring();
+       IndexEntry(docstring const & s, DocIterator const & d) 
+                       : idx(s), dit(d)
+       {}
+       
+       docstring idx;
+       DocIterator dit;
+};
+
+bool operator<(IndexEntry const & lhs, IndexEntry const & rhs)
+{
+       return lhs.idx < rhs.idx;
+}
+
+} // anon namespace
+
+
+docstring InsetPrintIndex::xhtml(XHTMLStream &, OutputParams const & op) const
+{
+       Layout const & lay = buffer().params().documentClass().htmlTOCLayout();
+       string const & tocclass = lay.defaultCSSClass();
+       string const tocattr = "class='tochead " + tocclass + "'";
+
+       // we'll use our own stream, because we are going to defer everything.
+       // that's how we deal with the fact that we're probably inside a standard
+       // paragraph, and we don't want to be.
+       odocstringstream ods;
+       XHTMLStream xs(ods);
+
+       Toc const & toc = buffer().tocBackend().toc("index");
+       if (toc.empty())
+               return docstring();
+
+       xs << StartTag("div", "class='index'");
+       xs << StartTag("div", tocattr) 
+                << _("Index") 
+                << EndTag("div");
+       Toc::const_iterator it = toc.begin();
+       Toc::const_iterator const en = toc.end();
+       Font const dummy;
+       vector<IndexEntry> entries;
+       for (; it != en; ++it)
+               entries.push_back(IndexEntry(it->str(), it->dit()));
+       stable_sort(entries.begin(), entries.end());
+       vector<IndexEntry>::const_iterator eit = entries.begin();
+       vector<IndexEntry>::const_iterator een = entries.end();
+       for (; eit != een; ++eit) {
+               Paragraph const & par = eit->dit.innerParagraph();
+               string const parattr = "href='#" + par.magicLabel() + "'";
+               xs << CompTag("br") << StartTag("a", parattr);
+               par.simpleLyXHTMLOnePar(buffer(), xs, op, dummy, true);
+               xs << EndTag("a");
+       }
+
+       xs << EndTag("div");
+       return ods.str();
 }
 
 } // namespace lyx
index bc288b85503bee107c9e44c6eb63faf51d714d0b..9b106915253c0dfdad8eef77e84b751e3532d0cf 100644 (file)
@@ -58,8 +58,7 @@ private:
        void read(Lexer & lex);
        ///
        int docbook(odocstream &, OutputParams const &) const;
-       /// At the moment, this does nothing. See development/HTML.notes
-       /// for some remarks on what could be done.
+       /// 
        docstring xhtml(XHTMLStream &, OutputParams const &) const;
        ///
        int latex(odocstream &, OutputParams const &) const;
@@ -104,7 +103,7 @@ public:
        static bool isCompatibleCommand(std::string const & s);
        ///
        int latex(odocstream &, OutputParams const &) const;
-       /// Does nothing yet.
+       /// 
        docstring xhtml(XHTMLStream &, OutputParams const &) const;
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);