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"
20 #include "LaTeXFeatures.h"
21 #include "OutputParams.h"
22 #include "output_xhtml.h"
23 #include "Paragraph.h"
24 #include "ParagraphParameters.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)
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'");
96 Language const * lang = buffer().params().language;
97 static string toctitle = N_("Table of Contents");
98 docstring title = lang
99 ? translateIfPossible(from_ascii(toctitle), lang->code())
100 : translateIfPossible(from_ascii(toctitle));
101 xs << html::StartTag("div", tocattr)
103 << html::EndTag("div");
106 Toc::const_iterator it = toc.begin();
107 Toc::const_iterator const en = toc.end();
109 for (; it != en; ++it) {
110 // First, we need to manage increases and decreases of depth
111 int const depth = it->depth();
113 // Ignore stuff above the tocdepth
114 if (depth > buffer().params().tocdepth)
117 if (depth > lastdepth) {
119 // open as many tags as we need to open to get to this level
120 // this includes the tag for the current level
121 for (int i = lastdepth + 1; i <= depth; ++i) {
123 attr << "class='lyxtoc-" << i << "'";
124 xs << html::StartTag("div", attr.str());
128 else if (depth < lastdepth) {
129 // close as many as we have to close to get back to this level
130 // this includes closing the last tag at this level
131 for (int i = lastdepth; i >= depth; --i)
132 xs << html::EndTag("div");
135 attr << "class='lyxtoc-" << depth << "'";
136 xs << html::StartTag("div", attr.str());
139 // no change of level, so close and open
140 xs << html::EndTag("div");
142 attr << "class='lyxtoc-" << depth << "'";
143 xs << html::StartTag("div", attr.str());
146 // Now output TOC info for this entry
147 Paragraph const & par = it->dit().innerParagraph();
148 // First the label, if there is one
149 docstring const & label = par.params().labelString();
152 // Now the content of the TOC entry, taken from the paragraph itself
153 OutputParams ours = op;
156 par.simpleLyXHTMLOnePar(buffer(), xs, ours, dummy);
158 // Now a link to that paragraph
159 string const parattr = "href='#" + par.magicLabel() + "' class='tocarrow'";
160 xs << html::StartTag("a", parattr);
162 // There ought to be a simple way to customize this.
163 // Maybe if we had an InsetLayout for TOC...
164 xs << XHTMLStream::NextRaw() << ">";
165 xs << html::EndTag("a");
167 for (int i = lastdepth; i > 0; --i)
168 xs << html::EndTag("div");
169 xs << html::EndTag("div");