3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
8 * Full author contact details are available in file CREDITS.
16 #include "BufferParams.h"
17 #include "DispatchResult.h"
18 #include "FuncRequest.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
21 #include "OutputParams.h"
22 #include "output_xhtml.h"
23 #include "Paragraph.h"
24 #include "TextClass.h"
25 #include "TocBackend.h"
27 #include "support/debug.h"
28 #include "support/gettext.h"
37 InsetTOC::InsetTOC(Buffer * buf, InsetCommandParams const & p)
38 : InsetCommand(buf, p, "toc")
42 ParamInfo const & InsetTOC::findInfo(string const & /* cmdName */)
44 static ParamInfo param_info_;
45 if (param_info_.empty()) {
46 param_info_.add("type", ParamInfo::LATEX_REQUIRED);
52 docstring InsetTOC::screenLabel() const
54 if (getCmdName() == "tableofcontents")
55 return buffer().B_("Table of Contents");
56 return _("Unknown TOC type");
60 int InsetTOC::plaintext(odocstream & os, OutputParams const &) const
62 os << screenLabel() << "\n\n";
63 buffer().tocBackend().writePlaintextTocList(getCmdName(), os);
64 return PLAINTEXT_NEWLINE;
68 int InsetTOC::docbook(odocstream & os, OutputParams const &) const
70 if (getCmdName() == "tableofcontents")
76 docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
78 Layout const & lay = buffer().params().documentClass().htmlTOCLayout();
79 string const & tocclass = lay.defaultCSSClass();
80 string const tocattr = "class='tochead " + tocclass + "'";
82 // we'll use our own stream, because we are going to defer everything.
83 // that's how we deal with the fact that we're probably inside a standard
84 // paragraph, and we don't want to be.
88 Toc const & toc = buffer().tocBackend().toc("tableofcontents");
92 xs << StartTag("div", "class='toc'");
93 xs << StartTag("div", tocattr)
94 << _("Table of Contents")
96 Toc::const_iterator it = toc.begin();
97 Toc::const_iterator const en = toc.end();
99 for (; it != en; ++it) {
100 Paragraph const & par = it->dit().innerParagraph();
101 int const depth = it->depth();
102 if (depth > buffer().params().tocdepth)
105 if (depth > lastdepth) {
107 // open as many tags as we need to open to get to this level
108 // this includes the tag for the current level
109 for (int i = lastdepth + 1; i <= depth; ++i) {
111 attr << "class='lyxtoc-" << i << "'";
112 xs << StartTag("div", attr.str());
116 else if (depth < lastdepth) {
117 // close as many as we have to close to get back to this level
118 // this includes closing the last tag at this level
119 for (int i = lastdepth; i >= depth; --i)
123 attr << "class='lyxtoc-" << depth << "'";
124 xs << StartTag("div", attr.str());
127 // no change of level, so close and open
130 attr << "class='lyxtoc-" << depth << "'";
131 xs << StartTag("div", attr.str());
133 string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'";
134 OutputParams ours = op;
136 par.simpleLyXHTMLOnePar(buffer(), xs, ours, dummy);
138 xs << StartTag("a", parattr);
140 // There ought to be a simple way to customize this.
141 xs << XHTMLStream::NextRaw() << "⇘";
144 for (int i = lastdepth; i > 0; --i)