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_fwd.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());
78 //error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
81 if (!environment_stack[depth].empty()) {
82 sgml::closeTag(os, environment_stack[depth]);
86 environment_stack[depth].erase();
87 sgml::openTag(os, style->latexname());
90 case LATEX_ENVIRONMENT:
91 case LATEX_ITEM_ENVIRONMENT:
92 case LATEX_BIB_ENVIRONMENT: {
93 string const & latexname = style->latexname();
95 if (depth == pit->params().depth()
96 && environment_stack[depth] != latexname) {
97 sgml::closeTag(os, environment_stack[depth]);
98 environment_stack[depth].erase();
100 if (depth < pit->params().depth()) {
101 depth = pit->params().depth();
102 environment_stack[depth].erase();
104 if (environment_stack[depth] != latexname) {
106 sgml::openTag(os, "p");
108 sgml::openTag(os, latexname);
110 if (environment_stack.size() == depth + 1)
111 environment_stack.push_back("!-- --");
112 environment_stack[depth] = latexname;
115 if (style->latexparam() == "CDATA")
118 if (style->latextype == LATEX_ENVIRONMENT) break;
120 if (style->labeltype == LABEL_MANUAL)
125 sgml::openTag(os, item_name);
130 sgml::openTag(os, style->latexname());
134 pit->simpleLinuxDocOnePar(buf, os,
135 outerFont(pit - paragraphs.begin(), paragraphs),
139 // write closing SGML tags
140 switch (style->latextype) {
143 case LATEX_ENVIRONMENT:
144 case LATEX_ITEM_ENVIRONMENT:
145 case LATEX_BIB_ENVIRONMENT:
146 if (style->latexparam() == "CDATA")
150 sgml::closeTag(os, style->latexname());
156 for (int i = depth; i >= 0; --i)
157 sgml::closeTag(os, environment_stack[i]);