]> git.lyx.org Git - lyx.git/blob - src/output_linuxdoc.C
more IU
[lyx.git] / src / output_linuxdoc.C
1 /**
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.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author José Matos
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "output_linuxdoc.h"
15
16 #include "buffer.h"
17 #include "bufferparams.h"
18 #include "paragraph.h"
19 #include "paragraph_funcs.h"
20 #include "ParagraphParameters.h"
21 #include "sgml.h"
22
23 #include <stack>
24
25 #ifdef HAVE_LOCALE
26 #endif
27
28 using std::ostream;
29 using std::stack;
30 using std::vector;
31 using std::string;
32
33 void linuxdocParagraphs(Buffer const & buf,
34                         ParagraphList const & paragraphs,
35                         ostream & os,
36                         OutputParams const & runparams)
37 {
38         
39         Paragraph::depth_type depth = 0; // paragraph depth
40         string item_name;
41         vector<string> environment_stack(5);
42
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                         InsetBase * inset = pit->getInset(0);
50                         if (inset->lyxCode() == InsetOld::TOC_CODE) {
51                                 string const temp = "toc";
52                                 sgml::openTag(os, depth, false, temp);
53                                 continue;
54                         }
55                 }
56
57                 // environment tag closing
58                 for (; depth > pit->params().depth(); --depth) {
59                         sgml::closeTag(os, depth, false, environment_stack[depth]);
60                         environment_stack[depth].erase();
61                 }
62
63                 // write opening SGML tags
64                 switch (style->latextype) {
65                 case LATEX_PARAGRAPH:
66                         if (depth == pit->params().depth()
67                            && !environment_stack[depth].empty()) {
68                                 sgml::closeTag(os, depth, false, environment_stack[depth]);
69                                 environment_stack[depth].erase();
70                                 if (depth)
71                                         --depth;
72                                 else
73                                         os << "</p>";
74                         }
75                         sgml::openTag(os, depth, false, style->latexname());
76                         break;
77
78                 case LATEX_COMMAND:
79                         if (depth != 0)
80                                 //error(ErrorItem(_("Error:"), _("Wrong depth for LatexType Command.\n"), pit->id(), 0, pit->size()));
81                                 ;
82
83                         if (!environment_stack[depth].empty()) {
84                                 sgml::closeTag(os, depth, false, environment_stack[depth]);
85                                 os << "</p>";
86                         }
87
88                         environment_stack[depth].erase();
89                         sgml::openTag(os, depth, false, style->latexname());
90                         break;
91
92                 case LATEX_ENVIRONMENT:
93                 case LATEX_ITEM_ENVIRONMENT:
94                 case LATEX_BIB_ENVIRONMENT: {
95                         string const & latexname = style->latexname();
96
97                         if (depth == pit->params().depth()
98                             && environment_stack[depth] != latexname) {
99                                 sgml::closeTag(os, depth, false,
100                                              environment_stack[depth]);
101                                 environment_stack[depth].erase();
102                         }
103                         if (depth < pit->params().depth()) {
104                                depth = pit->params().depth();
105                                environment_stack[depth].erase();
106                         }
107                         if (environment_stack[depth] != latexname) {
108                                 if (depth == 0) {
109                                         sgml::openTag(os, depth, false, "p");
110                                 }
111                                 sgml::openTag(os, depth, false, latexname);
112
113                                 if (environment_stack.size() == depth + 1)
114                                         environment_stack.push_back("!-- --");
115                                 environment_stack[depth] = latexname;
116                         }
117
118                         if (style->latexparam() == "CDATA")
119                                 os << "<![CDATA[";
120
121                         if (style->latextype == LATEX_ENVIRONMENT) break;
122
123                         if (style->labeltype == LABEL_MANUAL)
124                                 item_name = "tag";
125                         else
126                                 item_name = "item";
127
128                         sgml::openTag(os, depth + 1, false, item_name);
129                 }
130                 break;
131
132                 default:
133                         sgml::openTag(os, depth, false, style->latexname());
134                         break;
135                 }
136
137                 pit->simpleLinuxDocOnePar(buf, os, outerFont(pit, paragraphs),
138                                           runparams, depth);
139
140                 os << "\n";
141                 // write closing SGML tags
142                 switch (style->latextype) {
143                 case LATEX_COMMAND:
144                         break;
145                 case LATEX_ENVIRONMENT:
146                 case LATEX_ITEM_ENVIRONMENT:
147                 case LATEX_BIB_ENVIRONMENT:
148                         if (style->latexparam() == "CDATA")
149                                 os << "]]>";
150                         break;
151                 default:
152                         sgml::closeTag(os, depth, false, style->latexname());
153                         break;
154                 }
155         }
156
157         // Close open tags
158         for (int i = depth; i >= 0; --i)
159                 sgml::closeTag(os, depth, false, environment_stack[i]);
160 }
161
162