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 "paragraph.h"
19 #include "paragraph_funcs.h"
20 #include "ParagraphParameters.h"
33 void linuxdocParagraphs(Buffer const & buf,
34 ParagraphList const & paragraphs,
36 OutputParams const & runparams)
39 Paragraph::depth_type depth = 0; // paragraph depth
41 vector<string> environment_stack(5);
43 ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
44 ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
45 for (; pit != pend; ++pit) {
46 LyXLayout_ptr const & style = pit->layout();
47 // treat <toc> as a special case for compatibility with old code
48 if (pit->isInset(0)) {
49 InsetOld * inset = pit->getInset(0);
50 InsetOld::Code lyx_code = inset->lyxCode();
51 if (lyx_code == InsetOld::TOC_CODE) {
52 string const temp = "toc";
53 sgml::openTag(os, depth, false, temp);
58 // environment tag closing
59 for (; depth > pit->params().depth(); --depth) {
60 sgml::closeTag(os, depth, false, environment_stack[depth]);
61 environment_stack[depth].erase();
64 // write opening SGML tags
65 switch (style->latextype) {
67 if (depth == pit->params().depth()
68 && !environment_stack[depth].empty()) {
69 sgml::closeTag(os, depth, false, environment_stack[depth]);
70 environment_stack[depth].erase();
76 sgml::openTag(os, depth, false, style->latexname());
81 //error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
84 if (!environment_stack[depth].empty()) {
85 sgml::closeTag(os, depth, false, environment_stack[depth]);
89 environment_stack[depth].erase();
90 sgml::openTag(os, depth, false, style->latexname());
93 case LATEX_ENVIRONMENT:
94 case LATEX_ITEM_ENVIRONMENT:
95 case LATEX_BIB_ENVIRONMENT:
97 string const & latexname = style->latexname();
99 if (depth == pit->params().depth()
100 && environment_stack[depth] != latexname) {
101 sgml::closeTag(os, depth, false,
102 environment_stack[depth]);
103 environment_stack[depth].erase();
105 if (depth < pit->params().depth()) {
106 depth = pit->params().depth();
107 environment_stack[depth].erase();
109 if (environment_stack[depth] != latexname) {
111 sgml::openTag(os, depth, false, "p");
113 sgml::openTag(os, depth, false, latexname);
115 if (environment_stack.size() == depth + 1)
116 environment_stack.push_back("!-- --");
117 environment_stack[depth] = latexname;
120 if (style->latexparam() == "CDATA")
123 if (style->latextype == LATEX_ENVIRONMENT) break;
125 if (style->labeltype == LABEL_MANUAL)
130 sgml::openTag(os, depth + 1, false, item_name);
135 sgml::openTag(os, depth, false, style->latexname());
139 pit->simpleLinuxDocOnePar(buf, os, outerFont(pit, paragraphs),
143 // write closing SGML tags
144 switch (style->latextype) {
147 case LATEX_ENVIRONMENT:
148 case LATEX_ITEM_ENVIRONMENT:
149 case LATEX_BIB_ENVIRONMENT:
150 if (style->latexparam() == "CDATA")
154 sgml::closeTag(os, depth, false, style->latexname());
160 for (int i = depth; i >= 0; --i)
161 sgml::closeTag(os, depth, false, environment_stack[i]);