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 "ParagraphList.h"
21 #include "ParagraphParameters.h"
31 void linuxdocParagraphs(Buffer const & buf,
32 ParagraphList const & paragraphs,
34 OutputParams const & runparams)
37 Paragraph::depth_type depth = 0; // paragraph depth
39 vector<string> environment_stack(5);
41 ParagraphList::const_iterator pit = paragraphs.begin();
42 ParagraphList::const_iterator pend = paragraphs.end();
43 for (; pit != pend; ++pit) {
44 LyXLayout_ptr const & style = pit->layout();
45 // treat <toc> as a special case for compatibility with old code
46 if (!pit->empty() && pit->isInset(0)) {
47 InsetBase const * inset = pit->getInset(0);
48 if (inset->lyxCode() == InsetBase::TOC_CODE) {
49 string const temp = "toc";
50 sgml::openTag(os, temp);
55 // environment tag closing
56 for (; depth > pit->params().depth(); --depth) {
57 sgml::closeTag(os, environment_stack[depth]);
58 environment_stack[depth].erase();
61 // write opening SGML tags
62 switch (style->latextype) {
64 if (depth == pit->params().depth()
65 && !environment_stack[depth].empty()) {
66 sgml::closeTag(os, environment_stack[depth]);
67 environment_stack[depth].erase();
73 sgml::openTag(os, style->latexname());
79 error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
82 if (!environment_stack[depth].empty()) {
83 sgml::closeTag(os, environment_stack[depth]);
87 environment_stack[depth].erase();
88 sgml::openTag(os, style->latexname());
91 case LATEX_ENVIRONMENT:
92 case LATEX_ITEM_ENVIRONMENT:
93 case LATEX_BIB_ENVIRONMENT: {
94 string const & latexname = style->latexname();
96 if (depth == pit->params().depth()
97 && environment_stack[depth] != latexname) {
98 sgml::closeTag(os, environment_stack[depth]);
99 environment_stack[depth].erase();
101 if (depth < pit->params().depth()) {
102 depth = pit->params().depth();
103 environment_stack[depth].erase();
105 if (environment_stack[depth] != latexname) {
107 sgml::openTag(os, "p");
109 sgml::openTag(os, latexname);
111 if (environment_stack.size() == depth + 1)
112 environment_stack.push_back("!-- --");
113 environment_stack[depth] = latexname;
116 if (style->latexparam() == "CDATA")
119 if (style->latextype == LATEX_ENVIRONMENT) break;
121 if (style->labeltype == LABEL_MANUAL)
126 sgml::openTag(os, item_name);
131 sgml::openTag(os, style->latexname());
135 pit->simpleLinuxDocOnePar(buf, os,
136 outerFont(std::distance(paragraphs.begin(), pit), paragraphs),
140 // write closing SGML tags
141 switch (style->latextype) {
144 case LATEX_ENVIRONMENT:
145 case LATEX_ITEM_ENVIRONMENT:
146 case LATEX_BIB_ENVIRONMENT:
147 if (style->latexparam() == "CDATA")
151 sgml::closeTag(os, style->latexname());
157 for (int i = depth; i >= 0; --i)
158 sgml::closeTag(os, environment_stack[i]);