2 * \file output_linuxdoc.C
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
9 * Full author contact details are available in file CREDITS.
14 #include "output_linuxdoc.h"
17 #include "bufferparams.h"
18 #include "outputparams.h"
19 #include "paragraph.h"
20 #include "paragraph_funcs.h"
21 #include "ParagraphList.h"
22 #include "ParagraphParameters.h"
32 void linuxdocParagraphs(Buffer const & buf,
33 ParagraphList const & paragraphs,
35 OutputParams const & runparams)
38 Paragraph::depth_type depth = 0; // paragraph depth
40 vector<string> environment_stack(5);
42 ParagraphList::const_iterator pit = paragraphs.begin();
43 ParagraphList::const_iterator pend = paragraphs.end();
45 BOOST_ASSERT(runparams.par_begin <= runparams.par_end);
46 // if only part of the paragraphs will be outputed
47 if (runparams.par_begin != runparams.par_end) {
48 pit = boost::next(paragraphs.begin(), runparams.par_begin);
49 pend = boost::next(paragraphs.begin(), runparams.par_end);
50 // runparams will be passed to nested paragraphs, so
51 // we have to reset the range parameters.
52 const_cast<OutputParams&>(runparams).par_begin = 0;
53 const_cast<OutputParams&>(runparams).par_end = 0;
56 for (; pit != pend; ++pit) {
57 LyXLayout_ptr const & style = pit->layout();
58 // treat <toc> as a special case for compatibility with old code
59 if (!pit->empty() && pit->isInset(0)) {
60 InsetBase const * inset = pit->getInset(0);
61 if (inset->lyxCode() == InsetBase::TOC_CODE) {
62 string const temp = "toc";
63 sgml::openTag(os, temp);
68 // environment tag closing
69 for (; depth > pit->params().depth(); --depth) {
70 sgml::closeTag(os, environment_stack[depth]);
71 environment_stack[depth].erase();
74 // write opening SGML tags
75 switch (style->latextype) {
77 if (depth == pit->params().depth()
78 && !environment_stack[depth].empty()) {
79 sgml::closeTag(os, environment_stack[depth]);
80 environment_stack[depth].erase();
86 sgml::openTag(os, style->latexname());
92 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
95 if (!environment_stack[depth].empty()) {
96 sgml::closeTag(os, environment_stack[depth]);
100 environment_stack[depth].erase();
101 sgml::openTag(os, style->latexname());
104 case LATEX_ENVIRONMENT:
105 case LATEX_ITEM_ENVIRONMENT:
106 case LATEX_BIB_ENVIRONMENT: {
107 string const & latexname = style->latexname();
109 if (depth == pit->params().depth()
110 && environment_stack[depth] != latexname) {
111 sgml::closeTag(os, environment_stack[depth]);
112 environment_stack[depth].erase();
114 if (depth < pit->params().depth()) {
115 depth = pit->params().depth();
116 environment_stack[depth].erase();
118 if (environment_stack[depth] != latexname) {
120 sgml::openTag(os, "p");
122 sgml::openTag(os, latexname);
124 if (environment_stack.size() == depth + 1)
125 environment_stack.push_back("!-- --");
126 environment_stack[depth] = latexname;
129 if (style->latexparam() == "CDATA")
132 if (style->latextype == LATEX_ENVIRONMENT) break;
134 if (style->labeltype == LABEL_MANUAL)
139 sgml::openTag(os, item_name);
144 sgml::openTag(os, style->latexname());
148 pit->simpleLinuxDocOnePar(buf, os,
149 outerFont(std::distance(paragraphs.begin(), pit), paragraphs),
153 // write closing SGML tags
154 switch (style->latextype) {
157 case LATEX_ENVIRONMENT:
158 case LATEX_ITEM_ENVIRONMENT:
159 case LATEX_BIB_ENVIRONMENT:
160 if (style->latexparam() == "CDATA")
164 sgml::closeTag(os, style->latexname());
170 for (int i = depth; i >= 0; --i)
171 sgml::closeTag(os, environment_stack[i]);