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"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
22 #include "OutputParams.h"
23 #include "output_xhtml.h"
24 #include "Paragraph.h"
25 #include "TextClass.h"
26 #include "TocBackend.h"
28 #include "support/debug.h"
29 #include "support/gettext.h"
38 InsetTOC::InsetTOC(Buffer * buf, InsetCommandParams const & p)
39 : InsetCommand(buf, p, "toc")
43 ParamInfo const & InsetTOC::findInfo(string const & /* cmdName */)
45 static ParamInfo param_info_;
46 if (param_info_.empty()) {
47 param_info_.add("type", ParamInfo::LATEX_REQUIRED);
53 docstring InsetTOC::screenLabel() const
55 if (getCmdName() == "tableofcontents")
56 return buffer().B_("Table of Contents");
57 return _("Unknown TOC type");
61 int InsetTOC::plaintext(odocstream & os, OutputParams const &) const
63 os << screenLabel() << "\n\n";
64 buffer().tocBackend().writePlaintextTocList(getCmdName(), os);
65 return PLAINTEXT_NEWLINE;
69 int InsetTOC::docbook(odocstream & os, OutputParams const &) const
71 if (getCmdName() == "tableofcontents")
77 docstring InsetTOC::xhtml(XHTMLStream &, OutputParams const & op) const
79 Layout const & lay = buffer().params().documentClass().htmlTOCLayout();
80 string const & tocclass = lay.defaultCSSClass();
81 string const tocattr = "class='tochead " + tocclass + "'";
83 // we'll use our own stream, because we are going to defer everything.
84 // that's how we deal with the fact that we're probably inside a standard
85 // paragraph, and we don't want to be.
89 Toc const & toc = buffer().tocBackend().toc("tableofcontents");
93 xs << html::StartTag("div", "class='toc'");
94 Language const * lang = buffer().params().language;
95 static string toctitle = N_("Table of Contents");
96 docstring title = lang
97 ? translateIfPossible(from_ascii(toctitle), lang->code())
98 : translateIfPossible(from_ascii(toctitle));
99 xs << html::StartTag("div", tocattr)
101 << html::EndTag("div");
102 Toc::const_iterator it = toc.begin();
103 Toc::const_iterator const en = toc.end();
105 for (; it != en; ++it) {
106 Paragraph const & par = it->dit().innerParagraph();
107 int const depth = it->depth();
108 if (depth > buffer().params().tocdepth)
111 if (depth > lastdepth) {
113 // open as many tags as we need to open to get to this level
114 // this includes the tag for the current level
115 for (int i = lastdepth + 1; i <= depth; ++i) {
117 attr << "class='lyxtoc-" << i << "'";
118 xs << html::StartTag("div", attr.str());
122 else if (depth < lastdepth) {
123 // close as many as we have to close to get back to this level
124 // this includes closing the last tag at this level
125 for (int i = lastdepth; i >= depth; --i)
126 xs << html::EndTag("div");
129 attr << "class='lyxtoc-" << depth << "'";
130 xs << html::StartTag("div", attr.str());
133 // no change of level, so close and open
134 xs << html::EndTag("div");
136 attr << "class='lyxtoc-" << depth << "'";
137 xs << html::StartTag("div", attr.str());
139 string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'";
140 OutputParams ours = op;
142 par.simpleLyXHTMLOnePar(buffer(), xs, ours, dummy);
144 xs << html::StartTag("a", parattr);
146 // There ought to be a simple way to customize this.
147 xs << XHTMLStream::NextRaw() << "⇘";
148 xs << html::EndTag("a");
150 for (int i = lastdepth; i > 0; --i)
151 xs << html::EndTag("div");
152 xs << html::EndTag("div");